From d97492404516af266763339e0abc1fdac993760a Mon Sep 17 00:00:00 2001 From: AugustoL Date: Thu, 29 Dec 2016 16:12:32 -0300 Subject: [PATCH] Added claimAfterBlock variable and tests changes to support changes --- contracts/DelayedClaimable.sol | 12 +++++++++--- test/DelayedClaimble.js | 35 ++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/contracts/DelayedClaimable.sol b/contracts/DelayedClaimable.sol index 51a4a58af..c5c68844e 100644 --- a/contracts/DelayedClaimable.sol +++ b/contracts/DelayedClaimable.sol @@ -4,18 +4,24 @@ import './Claimable.sol'; /* * DelayedClaimable - * Extension for the Claimable contract, where the ownership needs to be claimed before certain block number + * Extension for the Claimable contract, where the ownership needs to be claimed before/after certain block number */ contract DelayedClaimable is Ownable, Claimable { + uint public claimBeforeBlock; + uint public claimAfterBlock; - function setClaimBefore(uint _claimBeforeBlock) onlyOwner { + function setClaimBlocks(uint _claimBeforeBlock, uint _claimAfterBlock) onlyOwner { + if (_claimAfterBlock > claimBeforeBlock) + throw; claimBeforeBlock = _claimBeforeBlock; + claimAfterBlock = _claimAfterBlock; } function claimOwnership() onlyPendingOwner { - if (block.number > claimBeforeBlock) throw; + if ((block.number > claimBeforeBlock) || (block.number < claimAfterBlock)) + throw; owner = pendingOwner; pendingOwner = 0x0; claimBeforeBlock = 0; diff --git a/test/DelayedClaimble.js b/test/DelayedClaimble.js index 006485f12..d7ef10c4e 100644 --- a/test/DelayedClaimble.js +++ b/test/DelayedClaimble.js @@ -7,16 +7,20 @@ contract('DelayedClaimable', function(accounts) { }); }); - it("changes pendingOwner after transfer succesful", function(done) { + it("Changes pendingOwner after transfer succesfull", function(done) { return delayedClaimable.transferOwnership(accounts[2]) .then(function(){ - return delayedClaimable.setClaimBefore(1000) + return delayedClaimable.setClaimBlocks(1000,0); }) .then(function(){ return delayedClaimable.claimBeforeBlock(); }) .then(function(claimBeforeBlock) { assert.isTrue(claimBeforeBlock == 1000); + return delayedClaimable.claimAfterBlock(); + }) + .then(function(claimAfterBlock) { + assert.isTrue(claimAfterBlock == 0); return delayedClaimable.pendingOwner(); }) .then(function(pendingOwner) { @@ -29,19 +33,23 @@ contract('DelayedClaimable', function(accounts) { .then(function(owner) { assert.isTrue(owner === accounts[2]); }) - .then(done) + .then(done); }); - it("changes pendingOwner after transfer fails", function(done) { + it("Changes pendingOwner after transfer fails", function(done) { return delayedClaimable.transferOwnership(accounts[1]) .then(function(){ - return delayedClaimable.setClaimBefore(1) + return delayedClaimable.setClaimBlocks(11000,10000); }) .then(function(){ return delayedClaimable.claimBeforeBlock(); }) .then(function(claimBeforeBlock) { - assert.isTrue(claimBeforeBlock == 1); + assert.isTrue(claimBeforeBlock == 11000); + return delayedClaimable.claimAfterBlock(); + }) + .then(function(claimAfterBlock) { + assert.isTrue(claimAfterBlock == 10000); return delayedClaimable.pendingOwner(); }) .then(function(pendingOwner) { @@ -49,7 +57,7 @@ contract('DelayedClaimable', function(accounts) { return delayedClaimable.claimOwnership({from: accounts[1]}); }) .catch(function(error) { - if (error.message.search('invalid JUMP') == -1) throw error + if (error.message.search('invalid JUMP') == -1) throw error; }) .then(function() { return delayedClaimable.owner(); @@ -57,7 +65,18 @@ contract('DelayedClaimable', function(accounts) { .then(function(owner) { assert.isTrue(owner != accounts[1]); }) - .then(done) + .then(done); + }); + + it("Set claimBeforeBlock and claimAfterBlock invalid values fail", function(done) { + return delayedClaimable.transferOwnership(accounts[1]) + .then(function(){ + return delayedClaimable.setClaimBlocks(1000,10000); + }) + .catch(function(error) { + if (error.message.search('invalid JUMP') == -1) throw error; + }) + .then(done); }); });