Files
openzeppelin-contracts/test/ownership/Secondary.test.js
Aniket 70fd243e3b Test setup helper added (#1482)
* signing prefix added

* Minor improvement

* Tests changed

* Successfully tested

* Minor improvements

* Minor improvements

* Revert "Dangling commas are now required. (#1359)"

This reverts commit a6889776f4.

* updates

* fixes #1404

* approve failing test

* suggested changes done

* ISafeERC20 removed

* conflict fixes

* fixes #1205

* minor change

* suggested changes

* reviewed changes

* final update
2018-12-07 13:32:48 -03:00

58 lines
2.1 KiB
JavaScript

const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../helpers/constants');
const SecondaryMock = artifacts.require('SecondaryMock');
require('../helpers/setup');
contract('Secondary', function ([_, primary, newPrimary, anyone]) {
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: anyone }));
});
});
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 transfering 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: anyone }));
});
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 }));
});
});
});
});