Events added to Secondary (#1425)

* Update contracts/ownership/Secondary.sol

* Update Secondary.sol

* Update Secondary.test.js

* Update Secondary.test.js

* Update Secondary.sol
This commit is contained in:
Aniket
2018-10-18 19:30:33 +05:30
committed by Nicolás Venturo
parent 0231fac514
commit cbe414864f
2 changed files with 17 additions and 3 deletions

View File

@ -7,11 +7,16 @@ pragma solidity ^0.4.24;
contract Secondary { contract Secondary {
address private _primary; address private _primary;
event PrimaryTransferred(
address recipient
);
/** /**
* @dev Sets the primary account to the one that is creating the Secondary contract. * @dev Sets the primary account to the one that is creating the Secondary contract.
*/ */
constructor() internal { constructor() internal {
_primary = msg.sender; _primary = msg.sender;
emit PrimaryTransferred(_primary);
} }
/** /**
@ -22,13 +27,20 @@ contract Secondary {
_; _;
} }
/**
* @return the address of the primary.
*/
function primary() public view returns (address) { function primary() public view returns (address) {
return _primary; return _primary;
} }
/**
* @dev Transfers contract to a new primary.
* @param recipient The address of new primary.
*/
function transferPrimary(address recipient) public onlyPrimary { function transferPrimary(address recipient) public onlyPrimary {
require(recipient != address(0)); require(recipient != address(0));
_primary = recipient; _primary = recipient;
emit PrimaryTransferred(_primary);
} }
} }

View File

@ -1,4 +1,5 @@
const shouldFail = require('../helpers/shouldFail'); const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../helpers/constants'); const { ZERO_ADDRESS } = require('../helpers/constants');
const SecondaryMock = artifacts.require('SecondaryMock'); const SecondaryMock = artifacts.require('SecondaryMock');
@ -27,7 +28,8 @@ contract('Secondary', function ([_, primary, newPrimary, anyone]) {
describe('transferPrimary', function () { describe('transferPrimary', function () {
it('makes the recipient the new primary', async function () { it('makes the recipient the new primary', async function () {
await this.secondary.transferPrimary(newPrimary, { from: primary }); const { logs } = await this.secondary.transferPrimary(newPrimary, { from: primary });
expectEvent.inLogs(logs, 'PrimaryTransferred', { recipient: newPrimary });
(await this.secondary.primary()).should.equal(newPrimary); (await this.secondary.primary()).should.equal(newPrimary);
}); });