Migrate AccessManager tests to ethers (#4710)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -1,68 +1,81 @@
|
||||
require('@openzeppelin/test-helpers');
|
||||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
const { ethers } = require('hardhat');
|
||||
|
||||
const AuthorityUtils = artifacts.require('$AuthorityUtils');
|
||||
const NotAuthorityMock = artifacts.require('NotAuthorityMock');
|
||||
const AuthorityNoDelayMock = artifacts.require('AuthorityNoDelayMock');
|
||||
const AuthorityDelayMock = artifacts.require('AuthorityDelayMock');
|
||||
const AuthorityNoResponse = artifacts.require('AuthorityNoResponse');
|
||||
async function fixture() {
|
||||
const [user, other] = await ethers.getSigners();
|
||||
|
||||
contract('AuthorityUtils', function (accounts) {
|
||||
const [user, other] = accounts;
|
||||
const mock = await ethers.deployContract('$AuthorityUtils');
|
||||
const notAuthorityMock = await ethers.deployContract('NotAuthorityMock');
|
||||
const authorityNoDelayMock = await ethers.deployContract('AuthorityNoDelayMock');
|
||||
const authorityDelayMock = await ethers.deployContract('AuthorityDelayMock');
|
||||
const authorityNoResponse = await ethers.deployContract('AuthorityNoResponse');
|
||||
|
||||
return {
|
||||
user,
|
||||
other,
|
||||
mock,
|
||||
notAuthorityMock,
|
||||
authorityNoDelayMock,
|
||||
authorityDelayMock,
|
||||
authorityNoResponse,
|
||||
};
|
||||
}
|
||||
|
||||
describe('AuthorityUtils', function () {
|
||||
beforeEach(async function () {
|
||||
this.mock = await AuthorityUtils.new();
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
describe('canCallWithDelay', function () {
|
||||
describe('when authority does not have a canCall function', function () {
|
||||
beforeEach(async function () {
|
||||
this.authority = await NotAuthorityMock.new();
|
||||
this.authority = this.notAuthorityMock;
|
||||
});
|
||||
|
||||
it('returns (immediate = 0, delay = 0)', async function () {
|
||||
const { immediate, delay } = await this.mock.$canCallWithDelay(
|
||||
this.authority.address,
|
||||
user,
|
||||
other,
|
||||
this.authority,
|
||||
this.user,
|
||||
this.other,
|
||||
'0x12345678',
|
||||
);
|
||||
expect(immediate).to.equal(false);
|
||||
expect(delay).to.be.bignumber.equal('0');
|
||||
expect(delay).to.be.equal(0n);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when authority has no delay', function () {
|
||||
beforeEach(async function () {
|
||||
this.authority = await AuthorityNoDelayMock.new();
|
||||
this.authority = this.authorityNoDelayMock;
|
||||
this.immediate = true;
|
||||
await this.authority._setImmediate(this.immediate);
|
||||
});
|
||||
|
||||
it('returns (immediate, delay = 0)', async function () {
|
||||
const { immediate, delay } = await this.mock.$canCallWithDelay(
|
||||
this.authority.address,
|
||||
user,
|
||||
other,
|
||||
this.authority,
|
||||
this.user,
|
||||
this.other,
|
||||
'0x12345678',
|
||||
);
|
||||
expect(immediate).to.equal(this.immediate);
|
||||
expect(delay).to.be.bignumber.equal('0');
|
||||
expect(delay).to.be.equal(0n);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when authority replies with a delay', function () {
|
||||
beforeEach(async function () {
|
||||
this.authority = await AuthorityDelayMock.new();
|
||||
this.authority = this.authorityDelayMock;
|
||||
});
|
||||
|
||||
for (const immediate of [true, false]) {
|
||||
for (const delay of ['0', '42']) {
|
||||
for (const delay of [0n, 42n]) {
|
||||
it(`returns (immediate=${immediate}, delay=${delay})`, async function () {
|
||||
await this.authority._setImmediate(immediate);
|
||||
await this.authority._setDelay(delay);
|
||||
const result = await this.mock.$canCallWithDelay(this.authority.address, user, other, '0x12345678');
|
||||
const result = await this.mock.$canCallWithDelay(this.authority, this.user, this.other, '0x12345678');
|
||||
expect(result.immediate).to.equal(immediate);
|
||||
expect(result.delay).to.be.bignumber.equal(delay);
|
||||
expect(result.delay).to.be.equal(delay);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -70,18 +83,18 @@ contract('AuthorityUtils', function (accounts) {
|
||||
|
||||
describe('when authority replies with empty data', function () {
|
||||
beforeEach(async function () {
|
||||
this.authority = await AuthorityNoResponse.new();
|
||||
this.authority = this.authorityNoResponse;
|
||||
});
|
||||
|
||||
it('returns (immediate = 0, delay = 0)', async function () {
|
||||
const { immediate, delay } = await this.mock.$canCallWithDelay(
|
||||
this.authority.address,
|
||||
user,
|
||||
other,
|
||||
this.authority,
|
||||
this.user,
|
||||
this.other,
|
||||
'0x12345678',
|
||||
);
|
||||
expect(immediate).to.equal(false);
|
||||
expect(delay).to.be.bignumber.equal('0');
|
||||
expect(delay).to.be.equal(0n);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user