forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SafeOwnable.test.js
36 lines (29 loc) · 1.33 KB
/
SafeOwnable.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const SafeOwnable = artifacts.require('SafeOwnableMock');
contract('SafeOwnable', function (accounts) {
const [ owner, accountA, accountB ] = accounts;
beforeEach(async function () {
this.safeOwnable = await SafeOwnable.new({ from: owner });
});
describe('transfer ownership', function () {
it('starting a transfer does not change owner', async function () {
const receipt = await this.safeOwnable.transferOwnership(accountA, { from: owner });
expectEvent(receipt, 'OwnershipTransferStarted');
expect(await this.safeOwnable.owner()).to.equal(owner);
});
it('changes owner after transfer', async function () {
await this.safeOwnable.transferOwnership(accountA, { from: owner });
const receipt = await this.safeOwnable.acceptOwnership({ from: accountA });
expectEvent(receipt, 'OwnershipTransferred');
expect(await this.safeOwnable.owner()).to.equal(accountA);
});
it('guards transfer against invalid user', async function () {
await this.safeOwnable.transferOwnership(accountA, { from: owner });
await expectRevert(
this.safeOwnable.acceptOwnership({ from: accountB }),
'SafeOwnable: caller is not the new owner',
);
});
});
});