Skip to content

Commit

Permalink
Share roles in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmichalis committed Feb 8, 2025
1 parent a0c20e0 commit 5875b15
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 27 deletions.
3 changes: 1 addition & 2 deletions test/access/AccessControl.behavior.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { ethers } = require('hardhat');
const { expect } = require('chai');

const { DEFAULT_ADMIN_ROLE } = require('../helpers/roles');
const time = require('../helpers/time');

const { shouldSupportInterfaces } = require('../utils/introspection/SupportsInterface.behavior');

const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
const ROLE = ethers.id('ROLE');
const OTHER_ROLE = ethers.id('OTHER_ROLE');

Expand Down Expand Up @@ -867,7 +867,6 @@ function shouldBehaveLikeAccessControlDefaultAdminRules() {
}

module.exports = {
DEFAULT_ADMIN_ROLE,
shouldBehaveLikeAccessControl,
shouldBehaveLikeAccessControlEnumerable,
shouldBehaveLikeAccessControlDefaultAdminRules,
Expand Down
3 changes: 2 additions & 1 deletion test/access/AccessControl.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { ethers } = require('hardhat');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

const { DEFAULT_ADMIN_ROLE, shouldBehaveLikeAccessControl } = require('./AccessControl.behavior');
const { shouldBehaveLikeAccessControl } = require('./AccessControl.behavior');
const { DEFAULT_ADMIN_ROLE } = require('../helpers/roles');

async function fixture() {
const [defaultAdmin, ...accounts] = await ethers.getSigners();
Expand Down
7 changes: 2 additions & 5 deletions test/access/extensions/AccessControlEnumerable.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const { ethers } = require('hardhat');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

const {
DEFAULT_ADMIN_ROLE,
shouldBehaveLikeAccessControl,
shouldBehaveLikeAccessControlEnumerable,
} = require('../AccessControl.behavior');
const { shouldBehaveLikeAccessControl, shouldBehaveLikeAccessControlEnumerable } = require('../AccessControl.behavior');
const { DEFAULT_ADMIN_ROLE } = require('../../helpers/roles');

async function fixture() {
const [defaultAdmin, ...accounts] = await ethers.getSigners();
Expand Down
5 changes: 1 addition & 4 deletions test/governance/TimelockController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');

const { GovernorHelper } = require('../helpers/governance');
const { OperationState } = require('../helpers/enums');
const { DEFAULT_ADMIN_ROLE, PROPOSER_ROLE, EXECUTOR_ROLE, CANCELLER_ROLE } = require('../helpers/roles');
const time = require('../helpers/time');

const { shouldSupportInterfaces } = require('../utils/introspection/SupportsInterface.behavior');

const salt = '0x025e7b0be353a74631ad648c667493c0e1cd31caa4cc2d3520fdc171ea0cc726'; // a random value

const MINDELAY = time.duration.days(1);
const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
const PROPOSER_ROLE = ethers.id('PROPOSER_ROLE');
const EXECUTOR_ROLE = ethers.id('EXECUTOR_ROLE');
const CANCELLER_ROLE = ethers.id('CANCELLER_ROLE');

const getAddress = obj => obj.address ?? obj.target ?? obj;

Expand Down
6 changes: 1 addition & 5 deletions test/governance/extensions/GovernorStorage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');

const { GovernorHelper, timelockSalt } = require('../../helpers/governance');
const { VoteType } = require('../../helpers/enums');
const { DEFAULT_ADMIN_ROLE, PROPOSER_ROLE, EXECUTOR_ROLE, CANCELLER_ROLE } = require('../../helpers/roles');

const TOKENS = [
{ Token: '$ERC20Votes', mode: 'blocknumber' },
{ Token: '$ERC20VotesTimestampMock', mode: 'timestamp' },
];

const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
const PROPOSER_ROLE = ethers.id('PROPOSER_ROLE');
const EXECUTOR_ROLE = ethers.id('EXECUTOR_ROLE');
const CANCELLER_ROLE = ethers.id('CANCELLER_ROLE');

const name = 'OZ-Governor';
const version = '1';
const tokenName = 'MockToken';
Expand Down
6 changes: 1 addition & 5 deletions test/governance/extensions/GovernorSuperQuorum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

const { GovernorHelper } = require('../../helpers/governance');
const { ProposalState, VoteType } = require('../../helpers/enums');
const { DEFAULT_ADMIN_ROLE, PROPOSER_ROLE, EXECUTOR_ROLE, CANCELLER_ROLE } = require('../../helpers/roles');
const time = require('../../helpers/time');

const TOKENS = [
{ Token: '$ERC20Votes', mode: 'blocknumber' },
{ Token: '$ERC20VotesTimestampMock', mode: 'timestamp' },
];

const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
const PROPOSER_ROLE = ethers.id('PROPOSER_ROLE');
const EXECUTOR_ROLE = ethers.id('EXECUTOR_ROLE');
const CANCELLER_ROLE = ethers.id('CANCELLER_ROLE');

const name = 'OZ-Governor';
const version = '1';
const tokenName = 'MockToken';
Expand Down
6 changes: 1 addition & 5 deletions test/governance/extensions/GovernorTimelockControl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');

const { GovernorHelper, timelockSalt } = require('../../helpers/governance');
const { OperationState, ProposalState, VoteType } = require('../../helpers/enums');
const { DEFAULT_ADMIN_ROLE, PROPOSER_ROLE, EXECUTOR_ROLE, CANCELLER_ROLE } = require('../../helpers/roles');
const time = require('../../helpers/time');

const TOKENS = [
{ Token: '$ERC20Votes', mode: 'blocknumber' },
{ Token: '$ERC20VotesTimestampMock', mode: 'timestamp' },
];

const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
const PROPOSER_ROLE = ethers.id('PROPOSER_ROLE');
const EXECUTOR_ROLE = ethers.id('EXECUTOR_ROLE');
const CANCELLER_ROLE = ethers.id('CANCELLER_ROLE');

const name = 'OZ-Governor';
const version = '1';
const tokenName = 'MockToken';
Expand Down
13 changes: 13 additions & 0 deletions test/helpers/roles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { ethers } = require('hardhat');

const DEFAULT_ADMIN_ROLE = ethers.ZeroHash;
const PROPOSER_ROLE = ethers.id('PROPOSER_ROLE');
const EXECUTOR_ROLE = ethers.id('EXECUTOR_ROLE');
const CANCELLER_ROLE = ethers.id('CANCELLER_ROLE');

module.exports = {
DEFAULT_ADMIN_ROLE,
PROPOSER_ROLE,
EXECUTOR_ROLE,
CANCELLER_ROLE,
};

0 comments on commit 5875b15

Please sign in to comment.