Files
openzeppelin-contracts/test/ownership/Secondary.test.js
ckshei 19c705d928 Fix/rename anyone account #1357 (#1718)
* replacing all instances of from: anyone with from: other

* replacing all instances of from: anyone with from: other

* replacing all instances of from: anyone with from: other

* changing anyone to other

* changing anyone to other
2019-04-11 12:34:10 -03:00

55 lines
2.1 KiB
JavaScript

const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const SecondaryMock = artifacts.require('SecondaryMock');
contract('Secondary', function ([_, primary, newPrimary, other]) {
beforeEach(async function () {
this.secondary = await SecondaryMock.new({ from: primary });
});
it('stores the primary\'s address', async function () {
(await this.secondary.primary()).should.equal(primary);
});
describe('onlyPrimary', function () {
it('allows the primary account to call onlyPrimary functions', async function () {
await this.secondary.onlyPrimaryMock({ from: primary });
});
it('reverts when anyone calls onlyPrimary functions', async function () {
await shouldFail.reverting(this.secondary.onlyPrimaryMock({ from: other }));
});
});
describe('transferPrimary', function () {
it('makes the recipient the new primary', async function () {
const { logs } = await this.secondary.transferPrimary(newPrimary, { from: primary });
expectEvent.inLogs(logs, 'PrimaryTransferred', { recipient: newPrimary });
(await this.secondary.primary()).should.equal(newPrimary);
});
it('reverts when transferring to the null address', async function () {
await shouldFail.reverting(this.secondary.transferPrimary(ZERO_ADDRESS, { from: primary }));
});
it('reverts when called by anyone', async function () {
await shouldFail.reverting(this.secondary.transferPrimary(newPrimary, { from: other }));
});
context('with new primary', function () {
beforeEach(async function () {
await this.secondary.transferPrimary(newPrimary, { from: primary });
});
it('allows the new primary account to call onlyPrimary functions', async function () {
await this.secondary.onlyPrimaryMock({ from: newPrimary });
});
it('reverts when the old primary account calls onlyPrimary functions', async function () {
await shouldFail.reverting(this.secondary.onlyPrimaryMock({ from: primary }));
});
});
});
});