How to test AccessControl in forge

Hey All,

I have a very simple question.

I wanna assert that deployer is DEFAULT_ADMIN_ROLE

However, I'm not sure how to read it right.

  address Deployer = makeAddr("deployer");
 assertEq(myContract.hasRole(ludex.DEFAULT_ADMIN_ROLE, Deployer));

How can I read who has role ?

The DEFAULT_ADMIN_ROLE is a public constant in the contract. Thus, you can get its value with myContract.DEFAULT_ADMIN_ROLE().

In the case of our tests suite, we have a constant defined for it. Alternatively, you can use ethers.ZeroHash or a similar constant depending on the library you're using.

How can I read who has role ?

In case you need it on-chain, you may need AccessControlEnumerable.

1 Like