From 0f3a8051d69bb0fee10287c0760d9fe7cc65fca2 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Wed, 2 Nov 2016 14:20:52 -0300 Subject: [PATCH] Added Claimable contract as an extension of Ownable with the Claimable tests --- contracts/Claimable.sol | 26 ++++++++++++++ migrations/2_deploy_contracts.js | 1 + test/Claimable.js | 60 ++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 contracts/Claimable.sol create mode 100644 test/Claimable.js diff --git a/contracts/Claimable.sol b/contracts/Claimable.sol new file mode 100644 index 000000000..40e38d49c --- /dev/null +++ b/contracts/Claimable.sol @@ -0,0 +1,26 @@ +pragma solidity ^0.4.0; +import './Ownable.sol'; + +/* + * Claimable + * Extension for the Ownable contract, where the ownership needs to be claimed + */ + +contract Claimable is Ownable { + address public pendingOwner; + + modifier onlyPendingOwner() { + if (msg.sender == pendingOwner) + _; + } + + function transfer(address newOwner) onlyOwner { + pendingOwner = newOwner; + } + + function claimOwnership() onlyPendingOwner { + owner = pendingOwner; + pendingOwner = 0x0; + } + +} diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index 869c60623..dd29abdac 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -3,6 +3,7 @@ module.exports = function(deployer) { deployer.deploy(BadArrayUse); deployer.deploy(ProofOfExistence); deployer.deploy(Ownable); + deployer.deploy(Claimable); deployer.deploy(LimitFunds); if(deployer.network == 'test'){ deployer.deploy(SecureTargetMock); diff --git a/test/Claimable.js b/test/Claimable.js new file mode 100644 index 000000000..9d62663d6 --- /dev/null +++ b/test/Claimable.js @@ -0,0 +1,60 @@ +contract('Claimable', function(accounts) { + + it("should have an owner", function(done) { + var claimable = Claimable.deployed(); + return claimable.owner() + .then(function(owner) { + assert.isTrue(owner != 0); + }) + .then(done) + }); + + it("changes pendingOwner after transfer", function(done) { + var claimable = Claimable.deployed(); + return claimable.transfer(accounts[1]) + .then(function() { + return claimable.pendingOwner(); + }) + .then(function(pendingOwner) { + assert.isTrue(pendingOwner === accounts[1]); + }) + .then(done) + }); + + it("should prevent to claimOwnership from no pendingOwner", function(done) { + var claimable = Claimable.deployed(); + return claimable.claimOwnership({from: accounts[2]}) + .then(function() { + return claimable.owner(); + }) + .then(function(owner) { + assert.isTrue(owner != accounts[2]); + }) + .then(done) + }); + + it("changes allow pending owner to claim ownership", function(done) { + var claimable = Claimable.deployed(); + return claimable.claimOwnership({from: accounts[1]}) + .then(function() { + return claimable.owner(); + }) + .then(function(owner) { + assert.isTrue(owner === accounts[1]); + }) + .then(done) + }); + + it("should prevent non-owners from transfering" ,function(done) { + var claimable = Claimable.deployed(); + return claimable.transfer(accounts[2], {from: accounts[2]}) + .then(function() { + return claimable.pendingOwner(); + }) + .then(function(pendingOwner) { + assert.isFalse(pendingOwner === accounts[2]); + }) + .then(done) + }); + +});