123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131 |
- const { web3 } = require('hardhat');
- const { expectEvent, time } = require('@openzeppelin/test-helpers');
- const { expectRevertCustomError } = require('../../helpers/customError');
- const { selector } = require('../../helpers/methods');
- const { clockFromReceipt } = require('../../helpers/time');
- const AccessManager = artifacts.require('$AccessManager');
- const AccessManagedTarget = artifacts.require('$AccessManagedTarget');
- const Ownable = artifacts.require('$Ownable');
- const MAX_UINT64 = web3.utils.toBN((2n ** 64n - 1n).toString());
- const GROUPS = {
- ADMIN: web3.utils.toBN(0),
- SOME_ADMIN: web3.utils.toBN(17),
- SOME: web3.utils.toBN(42),
- PUBLIC: MAX_UINT64,
- };
- Object.assign(GROUPS, Object.fromEntries(Object.entries(GROUPS).map(([key, value]) => [value, key])));
- const executeDelay = web3.utils.toBN(10);
- const grantDelay = web3.utils.toBN(10);
- const MINSETBACK = time.duration.days(5);
- const formatAccess = access => [access[0], access[1].toString()];
- contract('AccessManager', function (accounts) {
- const [admin, manager, member, user, other] = accounts;
- beforeEach(async function () {
- this.manager = await AccessManager.new(admin);
- // add member to group
- await this.manager.$_setGroupAdmin(GROUPS.SOME, GROUPS.SOME_ADMIN);
- await this.manager.$_setGroupGuardian(GROUPS.SOME, GROUPS.SOME_ADMIN);
- await this.manager.$_grantGroup(GROUPS.SOME_ADMIN, manager, 0, 0);
- await this.manager.$_grantGroup(GROUPS.SOME, member, 0, 0);
- });
- it('default minsetback is 1 day', async function () {
- expect(await this.manager.minSetback()).to.be.bignumber.equal(MINSETBACK);
- });
- it('groups are correctly initialized', async function () {
- // group admin
- expect(await this.manager.getGroupAdmin(GROUPS.ADMIN)).to.be.bignumber.equal(GROUPS.ADMIN);
- expect(await this.manager.getGroupAdmin(GROUPS.SOME_ADMIN)).to.be.bignumber.equal(GROUPS.ADMIN);
- expect(await this.manager.getGroupAdmin(GROUPS.SOME)).to.be.bignumber.equal(GROUPS.SOME_ADMIN);
- expect(await this.manager.getGroupAdmin(GROUPS.PUBLIC)).to.be.bignumber.equal(GROUPS.ADMIN);
- // group guardian
- expect(await this.manager.getGroupGuardian(GROUPS.ADMIN)).to.be.bignumber.equal(GROUPS.ADMIN);
- expect(await this.manager.getGroupGuardian(GROUPS.SOME_ADMIN)).to.be.bignumber.equal(GROUPS.ADMIN);
- expect(await this.manager.getGroupGuardian(GROUPS.SOME)).to.be.bignumber.equal(GROUPS.SOME_ADMIN);
- expect(await this.manager.getGroupGuardian(GROUPS.PUBLIC)).to.be.bignumber.equal(GROUPS.ADMIN);
- // group members
- expect(await this.manager.hasGroup(GROUPS.ADMIN, admin).then(formatAccess)).to.be.deep.equal([true, '0']);
- expect(await this.manager.hasGroup(GROUPS.ADMIN, manager).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.ADMIN, member).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.ADMIN, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME_ADMIN, admin).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME_ADMIN, manager).then(formatAccess)).to.be.deep.equal([true, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME_ADMIN, member).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME_ADMIN, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME, admin).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME, manager).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME, member).then(formatAccess)).to.be.deep.equal([true, '0']);
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- expect(await this.manager.hasGroup(GROUPS.PUBLIC, admin).then(formatAccess)).to.be.deep.equal([true, '0']);
- expect(await this.manager.hasGroup(GROUPS.PUBLIC, manager).then(formatAccess)).to.be.deep.equal([true, '0']);
- expect(await this.manager.hasGroup(GROUPS.PUBLIC, member).then(formatAccess)).to.be.deep.equal([true, '0']);
- expect(await this.manager.hasGroup(GROUPS.PUBLIC, user).then(formatAccess)).to.be.deep.equal([true, '0']);
- });
- describe('Groups management', function () {
- describe('label group', function () {
- it('admin can emit a label event', async function () {
- expectEvent(await this.manager.labelGroup(GROUPS.SOME, 'Some label', { from: admin }), 'GroupLabel', {
- groupId: GROUPS.SOME,
- label: 'Some label',
- });
- });
- it('admin can re-emit a label event', async function () {
- await this.manager.labelGroup(GROUPS.SOME, 'Some label', { from: admin });
- expectEvent(await this.manager.labelGroup(GROUPS.SOME, 'Updated label', { from: admin }), 'GroupLabel', {
- groupId: GROUPS.SOME,
- label: 'Updated label',
- });
- });
- it('emitting a label is restricted', async function () {
- await expectRevertCustomError(
- this.manager.labelGroup(GROUPS.SOME, 'Invalid label', { from: other }),
- 'AccessManagerUnauthorizedAccount',
- [other, GROUPS.ADMIN],
- );
- });
- });
- describe('grant group', function () {
- describe('without a grant delay', function () {
- it('without an execute delay', async function () {
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- const { receipt } = await this.manager.grantGroup(GROUPS.SOME, user, 0, { from: manager });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'GroupGranted', {
- groupId: GROUPS.SOME,
- account: user,
- since: timestamp,
- delay: '0',
- newMember: true,
- });
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([true, '0']);
- const access = await this.manager.getAccess(GROUPS.SOME, user);
- expect(access[0]).to.be.bignumber.equal(timestamp); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- it('with an execute delay', async function () {
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- const { receipt } = await this.manager.grantGroup(GROUPS.SOME, user, executeDelay, { from: manager });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'GroupGranted', {
- groupId: GROUPS.SOME,
- account: user,
- since: timestamp,
- delay: executeDelay,
- newMember: true,
- });
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([
- true,
- executeDelay.toString(),
- ]);
- const access = await this.manager.getAccess(GROUPS.SOME, user);
- expect(access[0]).to.be.bignumber.equal(timestamp); // inGroupSince
- expect(access[1]).to.be.bignumber.equal(executeDelay); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- it('to a user that is already in the group', async function () {
- expect(await this.manager.hasGroup(GROUPS.SOME, member).then(formatAccess)).to.be.deep.equal([true, '0']);
- await this.manager.grantGroup(GROUPS.SOME, member, 0, { from: manager });
- expect(await this.manager.hasGroup(GROUPS.SOME, member).then(formatAccess)).to.be.deep.equal([true, '0']);
- });
- it('to a user that is scheduled for joining the group', async function () {
- await this.manager.$_grantGroup(GROUPS.SOME, user, 10, 0); // grant delay 10
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- await this.manager.grantGroup(GROUPS.SOME, user, 0, { from: manager });
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- });
- it('grant group is restricted', async function () {
- await expectRevertCustomError(
- this.manager.grantGroup(GROUPS.SOME, user, 0, { from: other }),
- 'AccessManagerUnauthorizedAccount',
- [other, GROUPS.SOME_ADMIN],
- );
- });
- });
- describe('with a grant delay', function () {
- beforeEach(async function () {
- await this.manager.$_setGrantDelay(GROUPS.SOME, grantDelay);
- await time.increase(MINSETBACK);
- });
- it('granted group is not active immediately', async function () {
- const { receipt } = await this.manager.grantGroup(GROUPS.SOME, user, 0, { from: manager });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'GroupGranted', {
- groupId: GROUPS.SOME,
- account: user,
- since: timestamp.add(grantDelay),
- delay: '0',
- newMember: true,
- });
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- const access = await this.manager.getAccess(GROUPS.SOME, user);
- expect(access[0]).to.be.bignumber.equal(timestamp.add(grantDelay)); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- it('granted group is active after the delay', async function () {
- const { receipt } = await this.manager.grantGroup(GROUPS.SOME, user, 0, { from: manager });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'GroupGranted', {
- groupId: GROUPS.SOME,
- account: user,
- since: timestamp.add(grantDelay),
- delay: '0',
- newMember: true,
- });
- await time.increase(grantDelay);
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([true, '0']);
- const access = await this.manager.getAccess(GROUPS.SOME, user);
- expect(access[0]).to.be.bignumber.equal(timestamp.add(grantDelay)); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- });
- it('cannot grant public group', async function () {
- await expectRevertCustomError(
- this.manager.$_grantGroup(GROUPS.PUBLIC, other, 0, executeDelay, { from: manager }),
- 'AccessManagerLockedGroup',
- [GROUPS.PUBLIC],
- );
- });
- });
- describe('revoke group', function () {
- it('from a user that is already in the group', async function () {
- expect(await this.manager.hasGroup(GROUPS.SOME, member).then(formatAccess)).to.be.deep.equal([true, '0']);
- const { receipt } = await this.manager.revokeGroup(GROUPS.SOME, member, { from: manager });
- expectEvent(receipt, 'GroupRevoked', { groupId: GROUPS.SOME, account: member });
- expect(await this.manager.hasGroup(GROUPS.SOME, member).then(formatAccess)).to.be.deep.equal([false, '0']);
- const access = await this.manager.getAccess(GROUPS.SOME, user);
- expect(access[0]).to.be.bignumber.equal('0'); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- it('from a user that is scheduled for joining the group', async function () {
- await this.manager.$_grantGroup(GROUPS.SOME, user, 10, 0); // grant delay 10
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- const { receipt } = await this.manager.revokeGroup(GROUPS.SOME, user, { from: manager });
- expectEvent(receipt, 'GroupRevoked', { groupId: GROUPS.SOME, account: user });
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- const access = await this.manager.getAccess(GROUPS.SOME, user);
- expect(access[0]).to.be.bignumber.equal('0'); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- it('from a user that is not in the group', async function () {
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- await this.manager.revokeGroup(GROUPS.SOME, user, { from: manager });
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- });
- it('revoke group is restricted', async function () {
- await expectRevertCustomError(
- this.manager.revokeGroup(GROUPS.SOME, member, { from: other }),
- 'AccessManagerUnauthorizedAccount',
- [other, GROUPS.SOME_ADMIN],
- );
- });
- });
- describe('renounce group', function () {
- it('for a user that is already in the group', async function () {
- expect(await this.manager.hasGroup(GROUPS.SOME, member).then(formatAccess)).to.be.deep.equal([true, '0']);
- const { receipt } = await this.manager.renounceGroup(GROUPS.SOME, member, { from: member });
- expectEvent(receipt, 'GroupRevoked', { groupId: GROUPS.SOME, account: member });
- expect(await this.manager.hasGroup(GROUPS.SOME, member).then(formatAccess)).to.be.deep.equal([false, '0']);
- const access = await this.manager.getAccess(GROUPS.SOME, member);
- expect(access[0]).to.be.bignumber.equal('0'); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- it('for a user that is schedule for joining the group', async function () {
- await this.manager.$_grantGroup(GROUPS.SOME, user, 10, 0); // grant delay 10
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- const { receipt } = await this.manager.renounceGroup(GROUPS.SOME, user, { from: user });
- expectEvent(receipt, 'GroupRevoked', { groupId: GROUPS.SOME, account: user });
- expect(await this.manager.hasGroup(GROUPS.SOME, user).then(formatAccess)).to.be.deep.equal([false, '0']);
- const access = await this.manager.getAccess(GROUPS.SOME, user);
- expect(access[0]).to.be.bignumber.equal('0'); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- });
- it('for a user that is not in the group', async function () {
- await this.manager.renounceGroup(GROUPS.SOME, user, { from: user });
- });
- it('bad user confirmation', async function () {
- await expectRevertCustomError(
- this.manager.renounceGroup(GROUPS.SOME, member, { from: user }),
- 'AccessManagerBadConfirmation',
- [],
- );
- });
- });
- describe('change group admin', function () {
- it("admin can set any group's admin", async function () {
- expect(await this.manager.getGroupAdmin(GROUPS.SOME)).to.be.bignumber.equal(GROUPS.SOME_ADMIN);
- const { receipt } = await this.manager.setGroupAdmin(GROUPS.SOME, GROUPS.ADMIN, { from: admin });
- expectEvent(receipt, 'GroupAdminChanged', { groupId: GROUPS.SOME, admin: GROUPS.ADMIN });
- expect(await this.manager.getGroupAdmin(GROUPS.SOME)).to.be.bignumber.equal(GROUPS.ADMIN);
- });
- it("setting a group's admin is restricted", async function () {
- await expectRevertCustomError(
- this.manager.setGroupAdmin(GROUPS.SOME, GROUPS.SOME, { from: manager }),
- 'AccessManagerUnauthorizedAccount',
- [manager, GROUPS.ADMIN],
- );
- });
- });
- describe('change group guardian', function () {
- it("admin can set any group's admin", async function () {
- expect(await this.manager.getGroupGuardian(GROUPS.SOME)).to.be.bignumber.equal(GROUPS.SOME_ADMIN);
- const { receipt } = await this.manager.setGroupGuardian(GROUPS.SOME, GROUPS.ADMIN, { from: admin });
- expectEvent(receipt, 'GroupGuardianChanged', { groupId: GROUPS.SOME, guardian: GROUPS.ADMIN });
- expect(await this.manager.getGroupGuardian(GROUPS.SOME)).to.be.bignumber.equal(GROUPS.ADMIN);
- });
- it("setting a group's admin is restricted", async function () {
- await expectRevertCustomError(
- this.manager.setGroupGuardian(GROUPS.SOME, GROUPS.SOME, { from: other }),
- 'AccessManagerUnauthorizedAccount',
- [other, GROUPS.ADMIN],
- );
- });
- });
- describe('change execution delay', function () {
- it('increasing the delay has immediate effect', async function () {
- const oldDelay = web3.utils.toBN(10);
- const newDelay = web3.utils.toBN(100);
- // group is already granted (with no delay) in the initial setup. this update takes time.
- await this.manager.$_grantGroup(GROUPS.SOME, member, 0, oldDelay);
- const accessBefore = await this.manager.getAccess(GROUPS.SOME, member);
- expect(accessBefore[1]).to.be.bignumber.equal(oldDelay); // currentDelay
- expect(accessBefore[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(accessBefore[3]).to.be.bignumber.equal('0'); // effect
- const { receipt } = await this.manager.grantGroup(GROUPS.SOME, member, newDelay, {
- from: manager,
- });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'GroupGranted', {
- groupId: GROUPS.SOME,
- account: member,
- since: timestamp,
- delay: newDelay,
- newMember: false,
- });
- // immediate effect
- const accessAfter = await this.manager.getAccess(GROUPS.SOME, member);
- expect(accessAfter[1]).to.be.bignumber.equal(newDelay); // currentDelay
- expect(accessAfter[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(accessAfter[3]).to.be.bignumber.equal('0'); // effect
- });
- it('decreasing the delay takes time', async function () {
- const oldDelay = web3.utils.toBN(100);
- const newDelay = web3.utils.toBN(10);
- // group is already granted (with no delay) in the initial setup. this update takes time.
- await this.manager.$_grantGroup(GROUPS.SOME, member, 0, oldDelay);
- const accessBefore = await this.manager.getAccess(GROUPS.SOME, member);
- expect(accessBefore[1]).to.be.bignumber.equal(oldDelay); // currentDelay
- expect(accessBefore[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(accessBefore[3]).to.be.bignumber.equal('0'); // effect
- const { receipt } = await this.manager.grantGroup(GROUPS.SOME, member, newDelay, {
- from: manager,
- });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- const setback = oldDelay.sub(newDelay);
- expectEvent(receipt, 'GroupGranted', {
- groupId: GROUPS.SOME,
- account: member,
- since: timestamp.add(setback),
- delay: newDelay,
- newMember: false,
- });
- // no immediate effect
- const accessAfter = await this.manager.getAccess(GROUPS.SOME, member);
- expect(accessAfter[1]).to.be.bignumber.equal(oldDelay); // currentDelay
- expect(accessAfter[2]).to.be.bignumber.equal(newDelay); // pendingDelay
- expect(accessAfter[3]).to.be.bignumber.equal(timestamp.add(setback)); // effect
- // delayed effect
- await time.increase(setback);
- const accessAfterSetback = await this.manager.getAccess(GROUPS.SOME, member);
- expect(accessAfterSetback[1]).to.be.bignumber.equal(newDelay); // currentDelay
- expect(accessAfterSetback[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(accessAfterSetback[3]).to.be.bignumber.equal('0'); // effect
- });
- it('can set a user execution delay during the grant delay', async function () {
- await this.manager.$_grantGroup(GROUPS.SOME, other, 10, 0);
- // here: "other" is pending to get the group, but doesn't yet have it.
- const { receipt } = await this.manager.grantGroup(GROUPS.SOME, other, executeDelay, { from: manager });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- // increasing the execution delay from 0 to executeDelay is immediate
- expectEvent(receipt, 'GroupGranted', {
- groupId: GROUPS.SOME,
- account: other,
- since: timestamp,
- delay: executeDelay,
- newMember: false,
- });
- });
- });
- describe('change grant delay', function () {
- it('increasing the delay has immediate effect', async function () {
- const oldDelay = web3.utils.toBN(10);
- const newDelay = web3.utils.toBN(100);
- await this.manager.$_setGrantDelay(GROUPS.SOME, oldDelay);
- await time.increase(MINSETBACK);
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(oldDelay);
- const { receipt } = await this.manager.setGrantDelay(GROUPS.SOME, newDelay, { from: admin });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- const setback = web3.utils.BN.max(MINSETBACK, oldDelay.sub(newDelay));
- expect(setback).to.be.bignumber.equal(MINSETBACK);
- expectEvent(receipt, 'GroupGrantDelayChanged', {
- groupId: GROUPS.SOME,
- delay: newDelay,
- since: timestamp.add(setback),
- });
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(oldDelay);
- await time.increase(setback);
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(newDelay);
- });
- it('increasing the delay has delay effect #1', async function () {
- const oldDelay = web3.utils.toBN(100);
- const newDelay = web3.utils.toBN(10);
- await this.manager.$_setGrantDelay(GROUPS.SOME, oldDelay);
- await time.increase(MINSETBACK);
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(oldDelay);
- const { receipt } = await this.manager.setGrantDelay(GROUPS.SOME, newDelay, { from: admin });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- const setback = web3.utils.BN.max(MINSETBACK, oldDelay.sub(newDelay));
- expect(setback).to.be.bignumber.equal(MINSETBACK);
- expectEvent(receipt, 'GroupGrantDelayChanged', {
- groupId: GROUPS.SOME,
- delay: newDelay,
- since: timestamp.add(setback),
- });
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(oldDelay);
- await time.increase(setback);
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(newDelay);
- });
- it('increasing the delay has delay effect #2', async function () {
- const oldDelay = time.duration.days(30); // more than the minsetback
- const newDelay = web3.utils.toBN(10);
- await this.manager.$_setGrantDelay(GROUPS.SOME, oldDelay);
- await time.increase(MINSETBACK);
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(oldDelay);
- const { receipt } = await this.manager.setGrantDelay(GROUPS.SOME, newDelay, { from: admin });
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- const setback = web3.utils.BN.max(MINSETBACK, oldDelay.sub(newDelay));
- expect(setback).to.be.bignumber.gt(MINSETBACK);
- expectEvent(receipt, 'GroupGrantDelayChanged', {
- groupId: GROUPS.SOME,
- delay: newDelay,
- since: timestamp.add(setback),
- });
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(oldDelay);
- await time.increase(setback);
- expect(await this.manager.getGroupGrantDelay(GROUPS.SOME)).to.be.bignumber.equal(newDelay);
- });
- it('changing the grant delay is restricted', async function () {
- await expectRevertCustomError(
- this.manager.setGrantDelay(GROUPS.SOME, grantDelay, { from: other }),
- 'AccessManagerUnauthorizedAccount',
- [GROUPS.ADMIN, other],
- );
- });
- });
- });
- describe('with AccessManaged target contract', function () {
- beforeEach('deploy target contract', async function () {
- this.target = await AccessManagedTarget.new(this.manager.address);
- // helpers for indirect calls
- this.callData = selector('fnRestricted()');
- this.call = [this.target.address, this.callData];
- this.opId = web3.utils.keccak256(
- web3.eth.abi.encodeParameters(['address', 'address', 'bytes'], [user, ...this.call]),
- );
- this.direct = (opts = {}) => this.target.fnRestricted({ from: user, ...opts });
- this.schedule = (opts = {}) => this.manager.schedule(...this.call, 0, { from: user, ...opts });
- this.relay = (opts = {}) => this.manager.relay(...this.call, { from: user, ...opts });
- this.cancel = (opts = {}) => this.manager.cancel(user, ...this.call, { from: user, ...opts });
- });
- describe('Change function permissions', function () {
- const sigs = ['someFunction()', 'someOtherFunction(uint256)', 'oneMoreFunction(address,uint8)'].map(selector);
- it('admin can set function group', async function () {
- for (const sig of sigs) {
- expect(await this.manager.getTargetFunctionGroup(this.target.address, sig)).to.be.bignumber.equal(
- GROUPS.ADMIN,
- );
- }
- const { receipt: receipt1 } = await this.manager.setTargetFunctionGroup(
- this.target.address,
- sigs,
- GROUPS.SOME,
- {
- from: admin,
- },
- );
- for (const sig of sigs) {
- expectEvent(receipt1, 'TargetFunctionGroupUpdated', {
- target: this.target.address,
- selector: sig,
- groupId: GROUPS.SOME,
- });
- expect(await this.manager.getTargetFunctionGroup(this.target.address, sig)).to.be.bignumber.equal(
- GROUPS.SOME,
- );
- }
- const { receipt: receipt2 } = await this.manager.setTargetFunctionGroup(
- this.target.address,
- [sigs[1]],
- GROUPS.SOME_ADMIN,
- {
- from: admin,
- },
- );
- expectEvent(receipt2, 'TargetFunctionGroupUpdated', {
- target: this.target.address,
- selector: sigs[1],
- groupId: GROUPS.SOME_ADMIN,
- });
- for (const sig of sigs) {
- expect(await this.manager.getTargetFunctionGroup(this.target.address, sig)).to.be.bignumber.equal(
- sig == sigs[1] ? GROUPS.SOME_ADMIN : GROUPS.SOME,
- );
- }
- });
- it('non-admin cannot set function group', async function () {
- await expectRevertCustomError(
- this.manager.setTargetFunctionGroup(this.target.address, sigs, GROUPS.SOME, { from: other }),
- 'AccessManagerUnauthorizedAccount',
- [other, GROUPS.ADMIN],
- );
- });
- });
- // WIP
- describe('Calling restricted & unrestricted functions', function () {
- const product = (...arrays) => arrays.reduce((a, b) => a.flatMap(ai => b.map(bi => [...ai, bi])), [[]]);
- for (const [callerGroups, fnGroup, closed, delay] of product(
- [[], [GROUPS.SOME]],
- [undefined, GROUPS.ADMIN, GROUPS.SOME, GROUPS.PUBLIC],
- [false, true],
- [null, executeDelay],
- )) {
- // can we call with a delay ?
- const indirectSuccess = (fnGroup == GROUPS.PUBLIC || callerGroups.includes(fnGroup)) && !closed;
- // can we call without a delay ?
- const directSuccess = (fnGroup == GROUPS.PUBLIC || (callerGroups.includes(fnGroup) && !delay)) && !closed;
- const description = [
- 'Caller in groups',
- '[' + (callerGroups ?? []).map(groupId => GROUPS[groupId]).join(', ') + ']',
- delay ? 'with a delay' : 'without a delay',
- '+',
- 'functions open to groups',
- '[' + (GROUPS[fnGroup] ?? '') + ']',
- closed ? `(closed)` : '',
- ].join(' ');
- describe(description, function () {
- beforeEach(async function () {
- // setup
- await Promise.all([
- this.manager.$_setTargetClosed(this.target.address, closed),
- fnGroup &&
- this.manager.$_setTargetFunctionGroup(this.target.address, selector('fnRestricted()'), fnGroup),
- fnGroup &&
- this.manager.$_setTargetFunctionGroup(this.target.address, selector('fnUnrestricted()'), fnGroup),
- ...callerGroups
- .filter(groupId => groupId != GROUPS.PUBLIC)
- .map(groupId => this.manager.$_grantGroup(groupId, user, 0, delay ?? 0)),
- ]);
- // post setup checks
- expect(await this.manager.isTargetClosed(this.target.address)).to.be.equal(closed);
- if (fnGroup) {
- expect(
- await this.manager.getTargetFunctionGroup(this.target.address, selector('fnRestricted()')),
- ).to.be.bignumber.equal(fnGroup);
- expect(
- await this.manager.getTargetFunctionGroup(this.target.address, selector('fnUnrestricted()')),
- ).to.be.bignumber.equal(fnGroup);
- }
- for (const groupId of callerGroups) {
- const access = await this.manager.getAccess(groupId, user);
- if (groupId == GROUPS.PUBLIC) {
- expect(access[0]).to.be.bignumber.equal('0'); // inGroupSince
- expect(access[1]).to.be.bignumber.equal('0'); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- } else {
- expect(access[0]).to.be.bignumber.gt('0'); // inGroupSince
- expect(access[1]).to.be.bignumber.eq(String(delay ?? 0)); // currentDelay
- expect(access[2]).to.be.bignumber.equal('0'); // pendingDelay
- expect(access[3]).to.be.bignumber.equal('0'); // effect
- }
- }
- });
- it('canCall', async function () {
- const result = await this.manager.canCall(user, this.target.address, selector('fnRestricted()'));
- expect(result[0]).to.be.equal(directSuccess);
- expect(result[1]).to.be.bignumber.equal(!directSuccess && indirectSuccess ? delay ?? '0' : '0');
- });
- it('Calling a non restricted function never revert', async function () {
- expectEvent(await this.target.fnUnrestricted({ from: user }), 'CalledUnrestricted', {
- caller: user,
- });
- });
- it(`Calling a restricted function directly should ${
- directSuccess ? 'succeed' : 'revert'
- }`, async function () {
- const promise = this.direct();
- if (directSuccess) {
- expectEvent(await promise, 'CalledRestricted', { caller: user });
- } else if (indirectSuccess) {
- await expectRevertCustomError(promise, 'AccessManagerNotScheduled', [this.opId]);
- } else {
- await expectRevertCustomError(promise, 'AccessManagedUnauthorized', [user]);
- }
- });
- it('Calling indirectly: only relay', async function () {
- // relay without schedule
- if (directSuccess) {
- const { receipt, tx } = await this.relay();
- expectEvent.notEmitted(receipt, 'OperationExecuted', { operationId: this.opId });
- await expectEvent.inTransaction(tx, this.target, 'CalledRestricted', { caller: this.manager.address });
- } else if (indirectSuccess) {
- await expectRevertCustomError(this.relay(), 'AccessManagerNotScheduled', [this.opId]);
- } else {
- await expectRevertCustomError(this.relay(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- });
- it('Calling indirectly: schedule and relay', async function () {
- if (directSuccess || indirectSuccess) {
- const { receipt } = await this.schedule();
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'OperationScheduled', {
- operationId: this.opId,
- caller: user,
- target: this.call[0],
- data: this.call[1],
- });
- // if can call directly, delay should be 0. Otherwise, the delay should be applied
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal(
- timestamp.add(directSuccess ? web3.utils.toBN(0) : delay),
- );
- // execute without wait
- if (directSuccess) {
- const { receipt, tx } = await this.relay();
- await expectEvent.inTransaction(tx, this.target, 'CalledRestricted', { caller: this.manager.address });
- if (delay && fnGroup !== GROUPS.PUBLIC) {
- expectEvent(receipt, 'OperationExecuted', { operationId: this.opId });
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal('0');
- }
- } else if (indirectSuccess) {
- await expectRevertCustomError(this.relay(), 'AccessManagerNotReady', [this.opId]);
- } else {
- await expectRevertCustomError(this.relay(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- } else {
- await expectRevertCustomError(this.schedule(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- });
- it('Calling indirectly: schedule wait and relay', async function () {
- if (directSuccess || indirectSuccess) {
- const { receipt } = await this.schedule();
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'OperationScheduled', {
- operationId: this.opId,
- caller: user,
- target: this.call[0],
- data: this.call[1],
- });
- // if can call directly, delay should be 0. Otherwise, the delay should be applied
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal(
- timestamp.add(directSuccess ? web3.utils.toBN(0) : delay),
- );
- // wait
- await time.increase(delay ?? 0);
- // execute without wait
- if (directSuccess || indirectSuccess) {
- const { receipt, tx } = await this.relay();
- await expectEvent.inTransaction(tx, this.target, 'CalledRestricted', { caller: this.manager.address });
- if (delay && fnGroup !== GROUPS.PUBLIC) {
- expectEvent(receipt, 'OperationExecuted', { operationId: this.opId });
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal('0');
- }
- } else {
- await expectRevertCustomError(this.relay(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- } else {
- await expectRevertCustomError(this.schedule(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- });
- it('Calling directly: schedule and call', async function () {
- if (directSuccess || indirectSuccess) {
- const { receipt } = await this.schedule();
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'OperationScheduled', {
- operationId: this.opId,
- caller: user,
- target: this.call[0],
- data: this.call[1],
- });
- // if can call directly, delay should be 0. Otherwise, the delay should be applied
- const schedule = timestamp.add(directSuccess ? web3.utils.toBN(0) : delay);
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal(schedule);
- // execute without wait
- const promise = this.direct();
- if (directSuccess) {
- expectEvent(await promise, 'CalledRestricted', { caller: user });
- // schedule is not reset
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal(schedule);
- } else if (indirectSuccess) {
- await expectRevertCustomError(promise, 'AccessManagerNotReady', [this.opId]);
- } else {
- await expectRevertCustomError(promise, 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- } else {
- await expectRevertCustomError(this.schedule(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- });
- it('Calling directly: schedule wait and call', async function () {
- if (directSuccess || indirectSuccess) {
- const { receipt } = await this.schedule();
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expectEvent(receipt, 'OperationScheduled', {
- operationId: this.opId,
- caller: user,
- target: this.call[0],
- data: this.call[1],
- });
- // if can call directly, delay should be 0. Otherwise, the delay should be applied
- const schedule = timestamp.add(directSuccess ? web3.utils.toBN(0) : delay);
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal(schedule);
- // wait
- await time.increase(delay ?? 0);
- // execute without wait
- const promise = await this.direct();
- if (directSuccess) {
- expectEvent(await promise, 'CalledRestricted', { caller: user });
- // schedule is not reset
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal(schedule);
- } else if (indirectSuccess) {
- const receipt = await promise;
- expectEvent(receipt, 'CalledRestricted', { caller: user });
- await expectEvent.inTransaction(receipt.tx, this.manager, 'OperationExecuted', {
- operationId: this.opId,
- });
- // schedule is reset
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal('0');
- } else {
- await expectRevertCustomError(this.direct(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- } else {
- await expectRevertCustomError(this.schedule(), 'AccessManagerUnauthorizedCall', [user, ...this.call]);
- }
- });
- it('Scheduling for later than needed'); // TODO
- });
- }
- });
- describe('Indirect execution corner-cases', async function () {
- beforeEach(async function () {
- await this.manager.$_setTargetFunctionGroup(this.target.address, this.callData, GROUPS.SOME);
- await this.manager.$_grantGroup(GROUPS.SOME, user, 0, executeDelay);
- });
- it('Checking canCall when caller is the manager depend on the _relayIdentifier', async function () {
- const result = await this.manager.canCall(this.manager.address, this.target.address, '0x00000000');
- expect(result[0]).to.be.false;
- expect(result[1]).to.be.bignumber.equal('0');
- });
- it('Cannot execute earlier', async function () {
- const { receipt } = await this.schedule();
- const timestamp = await clockFromReceipt.timestamp(receipt).then(web3.utils.toBN);
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal(timestamp.add(executeDelay));
- // we need to set the clock 2 seconds before the value, because the increaseTo "consumes" the timestamp
- // and the next transaction will be one after that (see check below)
- await time.increaseTo(timestamp.add(executeDelay).subn(2));
- // too early
- await expectRevertCustomError(this.relay(), 'AccessManagerNotReady', [this.opId]);
- // the revert happened one second before the execution delay expired
- expect(await time.latest()).to.be.bignumber.equal(timestamp.add(executeDelay).subn(1));
- // ok
- await this.relay();
- // the success happened when the delay was reached (earliest possible)
- expect(await time.latest()).to.be.bignumber.equal(timestamp.add(executeDelay));
- });
- it('Cannot schedule an already scheduled operation', async function () {
- const { receipt } = await this.schedule();
- expectEvent(receipt, 'OperationScheduled', {
- operationId: this.opId,
- caller: user,
- target: this.call[0],
- data: this.call[1],
- });
- await expectRevertCustomError(this.schedule(), 'AccessManagerAlreadyScheduled', [this.opId]);
- });
- it('Cannot cancel an operation that is not scheduled', async function () {
- await expectRevertCustomError(this.cancel(), 'AccessManagerNotScheduled', [this.opId]);
- });
- it('Cannot cancel an operation that is not already relayed', async function () {
- await this.schedule();
- await time.increase(executeDelay);
- await this.relay();
- await expectRevertCustomError(this.cancel(), 'AccessManagerNotScheduled', [this.opId]);
- });
- it('Scheduler can cancel', async function () {
- await this.schedule();
- expect(await this.manager.getSchedule(this.opId)).to.not.be.bignumber.equal('0');
- expectEvent(await this.cancel({ from: manager }), 'OperationCanceled', { operationId: this.opId });
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal('0');
- });
- it('Guardian can cancel', async function () {
- await this.schedule();
- expect(await this.manager.getSchedule(this.opId)).to.not.be.bignumber.equal('0');
- expectEvent(await this.cancel({ from: manager }), 'OperationCanceled', { operationId: this.opId });
- expect(await this.manager.getSchedule(this.opId)).to.be.bignumber.equal('0');
- });
- it('Cancel is restricted', async function () {
- await this.schedule();
- expect(await this.manager.getSchedule(this.opId)).to.not.be.bignumber.equal('0');
- await expectRevertCustomError(this.cancel({ from: other }), 'AccessManagerCannotCancel', [
- other,
- user,
- ...this.call,
- ]);
- expect(await this.manager.getSchedule(this.opId)).to.not.be.bignumber.equal('0');
- });
- it('Can re-schedule after execution', async function () {
- await this.schedule();
- await time.increase(executeDelay);
- await this.relay();
- // reschedule
- const { receipt } = await this.schedule();
- expectEvent(receipt, 'OperationScheduled', {
- operationId: this.opId,
- caller: user,
- target: this.call[0],
- data: this.call[1],
- });
- });
- it('Can re-schedule after cancel', async function () {
- await this.schedule();
- await this.cancel();
- // reschedule
- const { receipt } = await this.schedule();
- expectEvent(receipt, 'OperationScheduled', {
- operationId: this.opId,
- caller: user,
- target: this.call[0],
- data: this.call[1],
- });
- });
- });
- });
- describe('with Ownable target contract', function () {
- const groupId = web3.utils.toBN(1);
- beforeEach(async function () {
- this.ownable = await Ownable.new(this.manager.address);
- // add user to group
- await this.manager.$_grantGroup(groupId, user, 0, 0);
- });
- it('initial state', async function () {
- expect(await this.ownable.owner()).to.be.equal(this.manager.address);
- });
- describe('Contract is closed', function () {
- beforeEach(async function () {
- await this.manager.$_setTargetClosed(this.ownable.address, true);
- });
- it('directly call: reverts', async function () {
- await expectRevertCustomError(this.ownable.$_checkOwner({ from: user }), 'OwnableUnauthorizedAccount', [user]);
- });
- it('relayed call (with group): reverts', async function () {
- await expectRevertCustomError(
- this.manager.relay(this.ownable.address, selector('$_checkOwner()'), { from: user }),
- 'AccessManagerUnauthorizedCall',
- [user, this.ownable.address, selector('$_checkOwner()')],
- );
- });
- it('relayed call (without group): reverts', async function () {
- await expectRevertCustomError(
- this.manager.relay(this.ownable.address, selector('$_checkOwner()'), { from: other }),
- 'AccessManagerUnauthorizedCall',
- [other, this.ownable.address, selector('$_checkOwner()')],
- );
- });
- });
- describe('Contract is managed', function () {
- describe('function is open to specific group', function () {
- beforeEach(async function () {
- await this.manager.$_setTargetFunctionGroup(this.ownable.address, selector('$_checkOwner()'), groupId);
- });
- it('directly call: reverts', async function () {
- await expectRevertCustomError(this.ownable.$_checkOwner({ from: user }), 'OwnableUnauthorizedAccount', [
- user,
- ]);
- });
- it('relayed call (with group): success', async function () {
- await this.manager.relay(this.ownable.address, selector('$_checkOwner()'), { from: user });
- });
- it('relayed call (without group): reverts', async function () {
- await expectRevertCustomError(
- this.manager.relay(this.ownable.address, selector('$_checkOwner()'), { from: other }),
- 'AccessManagerUnauthorizedCall',
- [other, this.ownable.address, selector('$_checkOwner()')],
- );
- });
- });
- describe('function is open to public group', function () {
- beforeEach(async function () {
- await this.manager.$_setTargetFunctionGroup(this.ownable.address, selector('$_checkOwner()'), GROUPS.PUBLIC);
- });
- it('directly call: reverts', async function () {
- await expectRevertCustomError(this.ownable.$_checkOwner({ from: user }), 'OwnableUnauthorizedAccount', [
- user,
- ]);
- });
- it('relayed call (with group): success', async function () {
- await this.manager.relay(this.ownable.address, selector('$_checkOwner()'), { from: user });
- });
- it('relayed call (without group): success', async function () {
- await this.manager.relay(this.ownable.address, selector('$_checkOwner()'), { from: other });
- });
- });
- });
- });
- describe('authority update', function () {
- beforeEach(async function () {
- this.newManager = await AccessManager.new(admin);
- this.target = await AccessManagedTarget.new(this.manager.address);
- });
- it('admin can change authority', async function () {
- expect(await this.target.authority()).to.be.equal(this.manager.address);
- const { tx } = await this.manager.updateAuthority(this.target.address, this.newManager.address, { from: admin });
- await expectEvent.inTransaction(tx, this.target, 'AuthorityUpdated', { authority: this.newManager.address });
- expect(await this.target.authority()).to.be.equal(this.newManager.address);
- });
- it('cannot set an address without code as the authority', async function () {
- await expectRevertCustomError(
- this.manager.updateAuthority(this.target.address, user, { from: admin }),
- 'AccessManagedInvalidAuthority',
- [user],
- );
- });
- it('updateAuthority is restricted on manager', async function () {
- await expectRevertCustomError(
- this.manager.updateAuthority(this.target.address, this.newManager.address, { from: other }),
- 'AccessManagerUnauthorizedAccount',
- [other, GROUPS.ADMIN],
- );
- });
- it('setAuthority is restricted on AccessManaged', async function () {
- await expectRevertCustomError(
- this.target.setAuthority(this.newManager.address, { from: admin }),
- 'AccessManagedUnauthorized',
- [admin],
- );
- });
- });
- // TODO:
- // - check opening/closing a contract
- // - check updating the contract delay
- // - check the delay applies to admin function
- describe.skip('contract modes', function () {});
- });
|