Skip to content

Commit af42c39

Browse files
Aniket-Enggnventuro
authored andcommitted
Improves Ownable events (#1397)
* signing prefix added * Minor improvement * Tests changed * Successfully tested * Minor improvements * Minor improvements * Revert "Dangling commas are now required. (#1359)" This reverts commit a688977. * updates * fixes #1392 * event tests added * constructor event added
1 parent 3acc2b4 commit af42c39

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

contracts/ownership/Ownable.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pragma solidity ^0.4.24;
88
contract Ownable {
99
address private _owner;
1010

11-
event OwnershipRenounced(address indexed previousOwner);
1211
event OwnershipTransferred(
1312
address indexed previousOwner,
1413
address indexed newOwner
@@ -20,6 +19,7 @@ contract Ownable {
2019
*/
2120
constructor() public {
2221
_owner = msg.sender;
22+
emit OwnershipTransferred(address(0), _owner);
2323
}
2424

2525
/**
@@ -51,7 +51,7 @@ contract Ownable {
5151
* modifier anymore.
5252
*/
5353
function renounceOwnership() public onlyOwner {
54-
emit OwnershipRenounced(_owner);
54+
emit OwnershipTransferred(_owner, address(0));
5555
_owner = address(0);
5656
}
5757

test/ownership/Ownable.behavior.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { expectThrow } = require('../helpers/expectThrow');
22
const { EVMRevert } = require('../helpers/EVMRevert');
3+
const expectEvent = require('../helpers/expectEvent');
34

45
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
56

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

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

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

3133
it('loses owner after renouncement', async function () {
32-
await this.ownable.renounceOwnership({ from: owner });
34+
const { logs } = await this.ownable.renounceOwnership({ from: owner });
35+
expectEvent.inLogs(logs, 'OwnershipTransferred');
36+
3337
(await this.ownable.owner()).should.equal(ZERO_ADDRESS);
3438
});
3539

0 commit comments

Comments
 (0)