Access Manager (#4416)
Co-authored-by: Ernesto García <ernestognw@gmail.com> Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
@ -1,55 +0,0 @@
|
||||
const {
|
||||
expectEvent,
|
||||
expectRevert,
|
||||
constants: { ZERO_ADDRESS },
|
||||
} = require('@openzeppelin/test-helpers');
|
||||
|
||||
const AccessManaged = artifacts.require('$AccessManagedMock');
|
||||
const SimpleAuthority = artifacts.require('SimpleAuthority');
|
||||
|
||||
contract('AccessManaged', function (accounts) {
|
||||
const [authority, other, user] = accounts;
|
||||
it('construction', async function () {
|
||||
const managed = await AccessManaged.new(authority);
|
||||
expectEvent.inConstruction(managed, 'AuthorityUpdated', {
|
||||
oldAuthority: ZERO_ADDRESS,
|
||||
newAuthority: authority,
|
||||
});
|
||||
expect(await managed.authority()).to.equal(authority);
|
||||
});
|
||||
|
||||
describe('setAuthority', function () {
|
||||
it(`current authority can change managed's authority`, async function () {
|
||||
const managed = await AccessManaged.new(authority);
|
||||
const set = await managed.setAuthority(other, { from: authority });
|
||||
expectEvent(set, 'AuthorityUpdated', {
|
||||
sender: authority,
|
||||
newAuthority: other,
|
||||
});
|
||||
expect(await managed.authority()).to.equal(other);
|
||||
});
|
||||
|
||||
it(`other account cannot change managed's authority`, async function () {
|
||||
const managed = await AccessManaged.new(authority);
|
||||
await expectRevert(managed.setAuthority(other, { from: other }), 'AccessManaged: not current authority');
|
||||
});
|
||||
});
|
||||
|
||||
describe('restricted', function () {
|
||||
const selector = web3.eth.abi.encodeFunctionSignature('restrictedFunction()');
|
||||
|
||||
it('allows if authority returns true', async function () {
|
||||
const authority = await SimpleAuthority.new();
|
||||
const managed = await AccessManaged.new(authority.address);
|
||||
await authority.setAllowed(user, managed.address, selector);
|
||||
const restricted = await managed.restrictedFunction({ from: user });
|
||||
expectEvent(restricted, 'RestrictedRan');
|
||||
});
|
||||
|
||||
it('reverts if authority returns false', async function () {
|
||||
const authority = await SimpleAuthority.new();
|
||||
const managed = await AccessManaged.new(authority.address);
|
||||
await expectRevert(managed.restrictedFunction({ from: user }), 'AccessManaged: authority rejected');
|
||||
});
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,5 @@ module.exports = {
|
||||
ProposalState: Enum('Pending', 'Active', 'Canceled', 'Defeated', 'Succeeded', 'Queued', 'Expired', 'Executed'),
|
||||
VoteType: Enum('Against', 'For', 'Abstain'),
|
||||
Rounding: Enum('Floor', 'Ceil', 'Trunc', 'Expand'),
|
||||
AccessMode: Enum('Custom', 'Closed', 'Open'),
|
||||
OperationState: Enum('Unset', 'Waiting', 'Ready', 'Done'),
|
||||
};
|
||||
|
||||
5
test/helpers/methods.js
Normal file
5
test/helpers/methods.js
Normal file
@ -0,0 +1,5 @@
|
||||
const { soliditySha3 } = require('web3-utils');
|
||||
|
||||
module.exports = {
|
||||
selector: signature => soliditySha3(signature).substring(0, 10),
|
||||
};
|
||||
Reference in New Issue
Block a user