Skip to content

Commit

Permalink
Events added to Secondary (#1425)
Browse files Browse the repository at this point in the history
* Update contracts/ownership/Secondary.sol

* Update Secondary.sol

* Update Secondary.test.js

* Update Secondary.test.js

* Update Secondary.sol
  • Loading branch information
Aniket-Engg authored and nventuro committed Oct 18, 2018
1 parent 0231fac commit cbe4148
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions contracts/ownership/Secondary.sol
Expand Up @@ -7,11 +7,16 @@ pragma solidity ^0.4.24;
contract Secondary {
address private _primary;

event PrimaryTransferred(
address recipient
);

/**
* @dev Sets the primary account to the one that is creating the Secondary contract.
*/
constructor() internal {
_primary = msg.sender;
emit PrimaryTransferred(_primary);
}

/**
Expand All @@ -22,13 +27,20 @@ contract Secondary {
_;
}

/**
* @return the address of the primary.
*/
function primary() public view returns (address) {
return _primary;
}


/**
* @dev Transfers contract to a new primary.
* @param recipient The address of new primary.
*/
function transferPrimary(address recipient) public onlyPrimary {
require(recipient != address(0));

_primary = recipient;
emit PrimaryTransferred(_primary);
}
}
4 changes: 3 additions & 1 deletion test/ownership/Secondary.test.js
@@ -1,4 +1,5 @@
const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../helpers/constants');

const SecondaryMock = artifacts.require('SecondaryMock');
Expand Down Expand Up @@ -27,7 +28,8 @@ contract('Secondary', function ([_, primary, newPrimary, anyone]) {

describe('transferPrimary', 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);
});

Expand Down

0 comments on commit cbe4148

Please sign in to comment.