Use hardhat-exposed to reduce the need for mocks (#3666)

Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Hadrien Croubois
2023-01-03 15:38:13 +01:00
committed by GitHub
parent a81b0d0b21
commit c1d9da4052
190 changed files with 2297 additions and 4311 deletions

View File

@ -115,7 +115,7 @@ function shouldBehaveLikeAccessControl (errorPrefix, admin, authorized, other, o
describe('setting role admin', function () {
beforeEach(async function () {
const receipt = await this.accessControl.setRoleAdmin(ROLE, OTHER_ROLE);
const receipt = await this.accessControl.$_setRoleAdmin(ROLE, OTHER_ROLE);
expectEvent(receipt, 'RoleAdminChanged', {
role: ROLE,
previousAdminRole: DEFAULT_ADMIN_ROLE,
@ -161,19 +161,19 @@ function shouldBehaveLikeAccessControl (errorPrefix, admin, authorized, other, o
});
it('do not revert if sender has role', async function () {
await this.accessControl.senderProtected(ROLE, { from: authorized });
await this.accessControl.methods['$_checkRole(bytes32)'](ROLE, { from: authorized });
});
it('revert if sender doesn\'t have role #1', async function () {
await expectRevert(
this.accessControl.senderProtected(ROLE, { from: other }),
this.accessControl.methods['$_checkRole(bytes32)'](ROLE, { from: other }),
`${errorPrefix}: account ${other.toLowerCase()} is missing role ${ROLE}`,
);
});
it('revert if sender doesn\'t have role #2', async function () {
await expectRevert(
this.accessControl.senderProtected(OTHER_ROLE, { from: authorized }),
this.accessControl.methods['$_checkRole(bytes32)'](OTHER_ROLE, { from: authorized }),
`${errorPrefix}: account ${authorized.toLowerCase()} is missing role ${OTHER_ROLE}`,
);
});
@ -211,6 +211,7 @@ function shouldBehaveLikeAccessControlEnumerable (errorPrefix, admin, authorized
}
module.exports = {
DEFAULT_ADMIN_ROLE,
shouldBehaveLikeAccessControl,
shouldBehaveLikeAccessControlEnumerable,
};

View File

@ -1,12 +1,14 @@
const {
DEFAULT_ADMIN_ROLE,
shouldBehaveLikeAccessControl,
} = require('./AccessControl.behavior.js');
const AccessControlMock = artifacts.require('AccessControlMock');
const AccessControl = artifacts.require('$AccessControl');
contract('AccessControl', function (accounts) {
beforeEach(async function () {
this.accessControl = await AccessControlMock.new({ from: accounts[0] });
this.accessControl = await AccessControl.new({ from: accounts[0] });
await this.accessControl.$_grantRole(DEFAULT_ADMIN_ROLE, accounts[0]);
});
shouldBehaveLikeAccessControl('AccessControl', ...accounts);

View File

@ -2,6 +2,7 @@ const { expectRevert } = require('@openzeppelin/test-helpers');
const { BridgeHelper } = require('../helpers/crosschain');
const {
DEFAULT_ADMIN_ROLE,
shouldBehaveLikeAccessControl,
} = require('./AccessControl.behavior.js');
@ -10,7 +11,7 @@ const crossChainRoleAlias = (role) => web3.utils.leftPad(
64,
);
const AccessControlCrossChainMock = artifacts.require('AccessControlCrossChainMock');
const AccessControlCrossChainMock = artifacts.require('$AccessControlCrossChainMock');
const ROLE = web3.utils.soliditySha3('ROLE');
@ -21,6 +22,7 @@ contract('AccessControl', function (accounts) {
beforeEach(async function () {
this.accessControl = await AccessControlCrossChainMock.new({ from: accounts[0] });
await this.accessControl.$_grantRole(DEFAULT_ADMIN_ROLE, accounts[0]);
});
shouldBehaveLikeAccessControl('AccessControl', ...accounts);
@ -32,7 +34,7 @@ contract('AccessControl', function (accounts) {
});
it('check alliassing', async function () {
expect(await this.accessControl.crossChainRoleAlias(ROLE)).to.be.bignumber.equal(crossChainRoleAlias(ROLE));
expect(await this.accessControl.$_crossChainRoleAlias(ROLE)).to.be.bignumber.equal(crossChainRoleAlias(ROLE));
});
it('Crosschain calls not authorized to non-aliased addresses', async function () {
@ -40,7 +42,7 @@ contract('AccessControl', function (accounts) {
this.bridge.call(
accounts[0],
this.accessControl,
'senderProtected',
'$_checkRole(bytes32)',
[ ROLE ],
),
`AccessControl: account ${accounts[0].toLowerCase()} is missing role ${crossChainRoleAlias(ROLE)}`,
@ -51,7 +53,7 @@ contract('AccessControl', function (accounts) {
await this.bridge.call(
accounts[1],
this.accessControl,
'senderProtected',
'$_checkRole(bytes32)',
[ ROLE ],
);
});

View File

@ -1,13 +1,15 @@
const {
DEFAULT_ADMIN_ROLE,
shouldBehaveLikeAccessControl,
shouldBehaveLikeAccessControlEnumerable,
} = require('./AccessControl.behavior.js');
const AccessControlMock = artifacts.require('AccessControlEnumerableMock');
const AccessControlEnumerable = artifacts.require('$AccessControlEnumerable');
contract('AccessControl', function (accounts) {
beforeEach(async function () {
this.accessControl = await AccessControlMock.new({ from: accounts[0] });
this.accessControl = await AccessControlEnumerable.new({ from: accounts[0] });
await this.accessControl.$_grantRole(DEFAULT_ADMIN_ROLE, accounts[0]);
});
shouldBehaveLikeAccessControl('AccessControl', ...accounts);

View File

@ -3,7 +3,7 @@ const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const Ownable = artifacts.require('OwnableMock');
const Ownable = artifacts.require('$Ownable');
contract('Ownable', function (accounts) {
const [ owner, other ] = accounts;

View File

@ -2,7 +2,7 @@ const { constants, expectEvent, expectRevert } = require('@openzeppelin/test-hel
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const Ownable2Step = artifacts.require('Ownable2StepMock');
const Ownable2Step = artifacts.require('$Ownable2Step');
contract('Ownable2Step', function (accounts) {
const [owner, accountA, accountB] = accounts;