12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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');
- });
- });
- });
|