added function to renounce ownership (#907)

This commit is contained in:
Paweł Winnicki
2018-05-03 18:25:18 +02:00
committed by Francisco Giordano
parent 4a10f727c4
commit 7e44204d9b
2 changed files with 23 additions and 0 deletions

View File

@ -10,6 +10,7 @@ contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
@ -39,4 +40,11 @@ contract Ownable {
owner = newOwner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
}

View File

@ -2,6 +2,7 @@
import assertRevert from '../helpers/assertRevert';
var Ownable = artifacts.require('Ownable');
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
contract('Ownable', function (accounts) {
let ownable;
@ -34,4 +35,18 @@ contract('Ownable', function (accounts) {
let originalOwner = await ownable.owner();
await assertRevert(ownable.transferOwnership(null, { from: originalOwner }));
});
it('loses owner after renouncement', async function () {
await ownable.renounceOwnership();
let owner = await ownable.owner();
assert.isTrue(owner === ZERO_ADDRESS);
});
it('should prevent non-owners from renouncement', async function () {
const other = accounts[2];
const owner = await ownable.owner.call();
assert.isTrue(owner !== other);
await assertRevert(ownable.renounceOwnership({ from: other }));
});
});