Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco Giordano <fg@frang.io> Co-authored-by: Joseph Delong <joseph@delong.me> Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> Co-authored-by: Renan Souza <renan.rodrigues.souza1@gmail.com> Co-authored-by: Ernesto García <ernestognw@gmail.com> Co-authored-by: Voronor <129545215+voronor@users.noreply.github.com> Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Co-authored-by: Michalis Kargakis <kargakis@protonmail.com> Co-authored-by: Bilog WEB3 <155262265+Bilogweb3@users.noreply.github.com> Co-authored-by: Fallengirl <155266340+Fallengirl@users.noreply.github.com> Co-authored-by: XxAlex74xX <30472093+XxAlex74xX@users.noreply.github.com> Co-authored-by: PixelPilot <161360836+PixelPil0t1@users.noreply.github.com> Co-authored-by: kilavvy <140459108+kilavvy@users.noreply.github.com> Co-authored-by: Devkuni <155117116+detrina@users.noreply.github.com> Co-authored-by: Danbo <140512416+dannbbb1@users.noreply.github.com> Co-authored-by: Ann Wagner <chant_77_swirly@icloud.com> Co-authored-by: comfsrt <155266597+comfsrt@users.noreply.github.com> Co-authored-by: Bob <158583129+bouchmann@users.noreply.github.com> Co-authored-by: JohnBonny <158583902+JohnBonny@users.noreply.github.com> Co-authored-by: moonman <155266991+moooonman@users.noreply.github.com> Co-authored-by: kazak <alright-epsilon8h@icloud.com> Co-authored-by: Wei <ybxerlvqtx@rambler.ru> Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com> Co-authored-by: Vitalyr <158586577+Vitaliyr888@users.noreply.github.com> Co-authored-by: pendrue <158588659+pendrue@users.noreply.github.com> Co-authored-by: Tronica <wudmytrotest404@gmail.com> Co-authored-by: emmmm <155267286+eeemmmmmm@users.noreply.github.com> Co-authored-by: bigbear <155267841+aso20455@users.noreply.github.com> Co-authored-by: Tomás Andróil <tomasandroil@gmail.com> Co-authored-by: GooseMatrix <155266802+GooseMatrix@users.noreply.github.com> Co-authored-by: jasmy <3776356370@qq.com> Co-authored-by: SITADRITA1 <mrlime2018@gmail.com> Co-authored-by: Ocenka <testoviydiman1@gmail.com>
113 lines
3.7 KiB
JavaScript
113 lines
3.7 KiB
JavaScript
const { ethers } = require('hardhat');
|
|
const { expect } = require('chai');
|
|
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
|
|
|
const { MAX_UINT32, MAX_UINT64 } = require('../../helpers/constants');
|
|
|
|
async function fixture() {
|
|
const [user, other] = await ethers.getSigners();
|
|
|
|
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 () {
|
|
Object.assign(this, await loadFixture(fixture));
|
|
});
|
|
|
|
describe('canCallWithDelay', function () {
|
|
describe('when authority does not have a canCall function', function () {
|
|
beforeEach(async function () {
|
|
this.authority = this.notAuthorityMock;
|
|
});
|
|
|
|
it('returns (immediate = 0, delay = 0)', async function () {
|
|
const { immediate, delay } = await this.mock.$canCallWithDelay(
|
|
this.authority,
|
|
this.user,
|
|
this.other,
|
|
'0x12345678',
|
|
);
|
|
expect(immediate).to.be.false;
|
|
expect(delay).to.equal(0n);
|
|
});
|
|
});
|
|
|
|
describe('when authority has no delay', function () {
|
|
beforeEach(async function () {
|
|
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,
|
|
this.user,
|
|
this.other,
|
|
'0x12345678',
|
|
);
|
|
expect(immediate).to.equal(this.immediate);
|
|
expect(delay).to.equal(0n);
|
|
});
|
|
});
|
|
|
|
describe('when authority replies with a delay', function () {
|
|
beforeEach(async function () {
|
|
this.authority = this.authorityDelayMock;
|
|
});
|
|
|
|
for (const immediate of [true, false]) {
|
|
for (const delay of [0n, 42n, MAX_UINT32]) {
|
|
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, this.user, this.other, '0x12345678');
|
|
expect(result.immediate).to.equal(immediate);
|
|
expect(result.delay).to.equal(delay);
|
|
});
|
|
}
|
|
}
|
|
|
|
it('out of bound delay', async function () {
|
|
await this.authority._setImmediate(false);
|
|
await this.authority._setDelay(MAX_UINT64); // bigger than the expected uint32
|
|
const result = await this.mock.$canCallWithDelay(this.authority, this.user, this.other, '0x12345678');
|
|
expect(result.immediate).to.equal(false);
|
|
expect(result.delay).to.equal(0n);
|
|
});
|
|
});
|
|
|
|
describe('when authority replies with empty data', function () {
|
|
beforeEach(async function () {
|
|
this.authority = this.authorityNoResponse;
|
|
});
|
|
|
|
it('returns (immediate = 0, delay = 0)', async function () {
|
|
const { immediate, delay } = await this.mock.$canCallWithDelay(
|
|
this.authority,
|
|
this.user,
|
|
this.other,
|
|
'0x12345678',
|
|
);
|
|
expect(immediate).to.be.false;
|
|
expect(delay).to.equal(0n);
|
|
});
|
|
});
|
|
});
|
|
});
|