Skip to content

Commit

Permalink
Improves Ownable events (OpenZeppelin#1397)
Browse files Browse the repository at this point in the history
* signing prefix added

* Minor improvement

* Tests changed

* Successfully tested

* Minor improvements

* Minor improvements

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

This reverts commit a688977.

* updates

* fixes OpenZeppelin#1392

* event tests added

* constructor event added

(cherry picked from commit af42c39)
  • Loading branch information
Aniket-Engg authored and nventuro committed Oct 18, 2018
1 parent 9c76d28 commit a811a0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions contracts/ownership/Ownable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ pragma solidity ^0.4.24;
contract Ownable {
address private _owner;


event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
Expand All @@ -23,6 +21,7 @@ contract Ownable {
*/
constructor() public {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}

/**
Expand Down Expand Up @@ -54,7 +53,7 @@ contract Ownable {
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(_owner);
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}

Expand Down
8 changes: 6 additions & 2 deletions test/ownership/Ownable.behavior.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const expectEvent = require('../helpers/expectEvent');

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

Expand All @@ -14,7 +15,8 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {

it('changes owner after transfer', async function () {
(await this.ownable.isOwner({ from: anyone })).should.be.equal(false);
await this.ownable.transferOwnership(anyone, { from: owner });
const { logs } = await this.ownable.transferOwnership(anyone, { from: owner });
expectEvent.inLogs(logs, 'OwnershipTransferred');

(await this.ownable.owner()).should.equal(anyone);
(await this.ownable.isOwner({ from: anyone })).should.be.equal(true);
Expand All @@ -29,7 +31,9 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {
});

it('loses owner after renouncement', async function () {
await this.ownable.renounceOwnership({ from: owner });
const { logs } = await this.ownable.renounceOwnership({ from: owner });
expectEvent.inLogs(logs, 'OwnershipTransferred');

(await this.ownable.owner()).should.equal(ZERO_ADDRESS);
});

Expand Down

0 comments on commit a811a0b

Please sign in to comment.