From c126e3e81a317e2a3c9dcf99279cb862e2500115 Mon Sep 17 00:00:00 2001 From: Aniket <30843294+Aniket-Engg@users.noreply.github.com> Date: Thu, 18 Oct 2018 19:30:33 +0530 Subject: [PATCH] Events added to Secondary (#1425) * Update contracts/ownership/Secondary.sol * Update Secondary.sol * Update Secondary.test.js * Update Secondary.test.js * Update Secondary.sol (cherry picked from commit cbe414864fc74290ae1c08175a4b1f7b59941bbc) --- contracts/ownership/Secondary.sol | 16 ++++++++++++++-- test/ownership/Secondary.test.js | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/contracts/ownership/Secondary.sol b/contracts/ownership/Secondary.sol index 02d2982a3..67d2250d5 100644 --- a/contracts/ownership/Secondary.sol +++ b/contracts/ownership/Secondary.sol @@ -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); } /** @@ -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); } } diff --git a/test/ownership/Secondary.test.js b/test/ownership/Secondary.test.js index 55283963b..c8772db1f 100644 --- a/test/ownership/Secondary.test.js +++ b/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'); @@ -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); });