How to test for roles in AccessControl?

Hi @abcoathup - I’m using ERC20PresetMinterPauserUpgradeable and having a hard time testing roles. This works:

    const [deployer] = await ethers.getSigners();
    const isAdmin = await godToken.hasRole(DEFAULT_ADMIN_ROLE, deployer.address);

but this doesn’t:

    const [deployer] = await ethers.getSigners();
    const isMinter = await godToken.hasRole(

From the look of AccessControl.sol, MINTER_ROLE is assigned when ERC20PresetMinterPauserUpgradeable is initialized, so I’m at a loss. Any ideas?

1 Like

Nevermind - got it! For anyone looking in the future:

1 Like

Hi @gigamesh,

Welcome to the community :wave:

Glad you were able to resolve and thanks for sharing your solution. I have marked it as the solution.

Another way to get the value is to read it from the contract myContract.MINTER_ROLE().