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 a6889776f4.
* updates
* fixes #1392
* event tests added
* constructor event added
This commit is contained in:
@ -8,7 +8,6 @@ pragma solidity ^0.4.24;
|
|||||||
contract Ownable {
|
contract Ownable {
|
||||||
address private _owner;
|
address private _owner;
|
||||||
|
|
||||||
event OwnershipRenounced(address indexed previousOwner);
|
|
||||||
event OwnershipTransferred(
|
event OwnershipTransferred(
|
||||||
address indexed previousOwner,
|
address indexed previousOwner,
|
||||||
address indexed newOwner
|
address indexed newOwner
|
||||||
@ -20,6 +19,7 @@ contract Ownable {
|
|||||||
*/
|
*/
|
||||||
constructor() public {
|
constructor() public {
|
||||||
_owner = msg.sender;
|
_owner = msg.sender;
|
||||||
|
emit OwnershipTransferred(address(0), _owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +51,7 @@ contract Ownable {
|
|||||||
* modifier anymore.
|
* modifier anymore.
|
||||||
*/
|
*/
|
||||||
function renounceOwnership() public onlyOwner {
|
function renounceOwnership() public onlyOwner {
|
||||||
emit OwnershipRenounced(_owner);
|
emit OwnershipTransferred(_owner, address(0));
|
||||||
_owner = address(0);
|
_owner = address(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
const { expectThrow } = require('../helpers/expectThrow');
|
const { expectThrow } = require('../helpers/expectThrow');
|
||||||
const { EVMRevert } = require('../helpers/EVMRevert');
|
const { EVMRevert } = require('../helpers/EVMRevert');
|
||||||
|
const expectEvent = require('../helpers/expectEvent');
|
||||||
|
|
||||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||||
|
|
||||||
@ -14,7 +15,8 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {
|
|||||||
|
|
||||||
it('changes owner after transfer', async function () {
|
it('changes owner after transfer', async function () {
|
||||||
(await this.ownable.isOwner({ from: anyone })).should.be.equal(false);
|
(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.owner()).should.equal(anyone);
|
||||||
(await this.ownable.isOwner({ from: anyone })).should.be.equal(true);
|
(await this.ownable.isOwner({ from: anyone })).should.be.equal(true);
|
||||||
@ -29,7 +31,9 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('loses owner after renouncement', async function () {
|
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);
|
(await this.ownable.owner()).should.equal(ZERO_ADDRESS);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user