Commit 7e44204d by Paweł Winnicki Committed by Francisco Giordano

added function to renounce ownership (#907)

parent 4a10f727
...@@ -10,6 +10,7 @@ contract Ownable { ...@@ -10,6 +10,7 @@ contract Ownable {
address public owner; address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
...@@ -39,4 +40,11 @@ contract Ownable { ...@@ -39,4 +40,11 @@ contract Ownable {
owner = newOwner; owner = newOwner;
} }
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import assertRevert from '../helpers/assertRevert'; import assertRevert from '../helpers/assertRevert';
var Ownable = artifacts.require('Ownable'); var Ownable = artifacts.require('Ownable');
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
contract('Ownable', function (accounts) { contract('Ownable', function (accounts) {
let ownable; let ownable;
...@@ -34,4 +35,18 @@ contract('Ownable', function (accounts) { ...@@ -34,4 +35,18 @@ contract('Ownable', function (accounts) {
let originalOwner = await ownable.owner(); let originalOwner = await ownable.owner();
await assertRevert(ownable.transferOwnership(null, { from: originalOwner })); 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 }));
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment