From 0aa4d02044aa5f5b89305d3e1d2c64fa93cdc311 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Wed, 16 Nov 2016 19:49:57 -0300 Subject: [PATCH 1/9] DelayedClaimable contract with test added --- contracts/Claimable.sol | 2 +- contracts/DelayedClaimable.sol | 25 +++++++++++++++ test/DelayedClaimble.js | 58 ++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 contracts/DelayedClaimable.sol create mode 100644 test/DelayedClaimble.js diff --git a/contracts/Claimable.sol b/contracts/Claimable.sol index 40e38d49c..e1639eff4 100644 --- a/contracts/Claimable.sol +++ b/contracts/Claimable.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.0; +pragma solidity ^0.4.4; import './Ownable.sol'; /* diff --git a/contracts/DelayedClaimable.sol b/contracts/DelayedClaimable.sol new file mode 100644 index 000000000..08b3b94a5 --- /dev/null +++ b/contracts/DelayedClaimable.sol @@ -0,0 +1,25 @@ +pragma solidity ^0.4.4; +import './Ownable.sol'; +import './Claimable.sol'; + +/* + * DelayedClaimable + * Extension for the Claimable contract, where the ownership needs to be claimed before certain time + */ + +contract DelayedClaimable is Ownable, Claimable { + uint public claimBefore; + + function setDelay(uint _claimBefore) onlyOwner { + claimBefore = _claimBefore; + } + + function claimOwnership() onlyPendingOwner { + if (block.number > claimBefore) + throw; + owner = pendingOwner; + pendingOwner = 0x0; + claimBefore = 0; + } + +} diff --git a/test/DelayedClaimble.js b/test/DelayedClaimble.js new file mode 100644 index 000000000..61c4a5e77 --- /dev/null +++ b/test/DelayedClaimble.js @@ -0,0 +1,58 @@ +contract('DelayedClaimable', function(accounts) { + var delayedClaimable; + + beforeEach(function() { + return DelayedClaimable.new().then(function(deployed) { + delayedClaimable = deployed; + }); + }); + + it("changes pendingOwner after transfer succesful", function(done) { + var newOwner = accounts[2]; + return delayedClaimable.transfer(newOwner) + .then(function(){ + return delayedClaimable.setDelay(1000) + }) + .then(function(){ + return delayedClaimable.claimBefore(); + }) + .then(function(claimBefore) { + assert.isTrue(claimBefore == 1000); + return delayedClaimable.pendingOwner(); + }) + .then(function(pendingOwner) { + assert.isTrue(pendingOwner === newOwner); + delayedClaimable.claimOwnership({from: newOwner}); + return delayedClaimable.owner(); + }) + .then(function(owner) { + assert.isTrue(owner === newOwner); + }) + .then(done) + }); + + it("changes pendingOwner after transfer fails", function(done) { + var newOwner = accounts[1]; + return delayedClaimable.transfer(newOwner) + .then(function(){ + return delayedClaimable.setDelay(1) + }) + .then(function(){ + return delayedClaimable.claimBefore(); + }) + .then(function(claimBefore) { + assert.isTrue(claimBefore == 1); + return delayedClaimable.pendingOwner(); + }) + .then(function(pendingOwner) { + assert.isTrue(pendingOwner === newOwner); + // delayedClaimable.claimOwnership({from: newOwner}); Uncomment to break the test. + return delayedClaimable.owner(); + }) + .then(function(owner) { + assert.isTrue(owner != newOwner); + }) + .then(done) + }); + +}); From 85a4013f49779b812bcdd2ff5b95dea73d17e1f0 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Fri, 18 Nov 2016 20:32:22 -0300 Subject: [PATCH 2/9] Using modifier to check block on delayedClaimable, tests fixed --- contracts/DelayedClaimable.sol | 9 ++++++--- test/DelayedClaimble.js | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contracts/DelayedClaimable.sol b/contracts/DelayedClaimable.sol index 08b3b94a5..5e97e82cf 100644 --- a/contracts/DelayedClaimable.sol +++ b/contracts/DelayedClaimable.sol @@ -10,13 +10,16 @@ import './Claimable.sol'; contract DelayedClaimable is Ownable, Claimable { uint public claimBefore; + modifier onTime() { + if (block.number < claimBefore) + _; + } + function setDelay(uint _claimBefore) onlyOwner { claimBefore = _claimBefore; } - function claimOwnership() onlyPendingOwner { - if (block.number > claimBefore) - throw; + function claimOwnership() onlyPendingOwner onTime { owner = pendingOwner; pendingOwner = 0x0; claimBefore = 0; diff --git a/test/DelayedClaimble.js b/test/DelayedClaimble.js index 61c4a5e77..7c0a4c581 100644 --- a/test/DelayedClaimble.js +++ b/test/DelayedClaimble.js @@ -22,7 +22,9 @@ contract('DelayedClaimable', function(accounts) { }) .then(function(pendingOwner) { assert.isTrue(pendingOwner === newOwner); - delayedClaimable.claimOwnership({from: newOwner}); + return delayedClaimable.claimOwnership({from: newOwner}); + }) + .then(function() { return delayedClaimable.owner(); }) .then(function(owner) { @@ -46,7 +48,9 @@ contract('DelayedClaimable', function(accounts) { }) .then(function(pendingOwner) { assert.isTrue(pendingOwner === newOwner); - // delayedClaimable.claimOwnership({from: newOwner}); Uncomment to break the test. + return delayedClaimable.claimOwnership({from: newOwner}); + }) + .then(function() { return delayedClaimable.owner(); }) .then(function(owner) { From 475cb5dc1f5d061cda8fe1002034aef375d6e9a3 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Sat, 19 Nov 2016 10:51:34 -0300 Subject: [PATCH 3/9] Renamed DelayedClaimable function and modifier --- contracts/DelayedClaimable.sol | 16 ++++++++-------- test/DelayedClaimble.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/contracts/DelayedClaimable.sol b/contracts/DelayedClaimable.sol index 5e97e82cf..8739f3307 100644 --- a/contracts/DelayedClaimable.sol +++ b/contracts/DelayedClaimable.sol @@ -4,25 +4,25 @@ import './Claimable.sol'; /* * DelayedClaimable - * Extension for the Claimable contract, where the ownership needs to be claimed before certain time + * Extension for the Claimable contract, where the ownership needs to be claimed before certain block number */ contract DelayedClaimable is Ownable, Claimable { - uint public claimBefore; + uint public claimBeforeBlock; - modifier onTime() { - if (block.number < claimBefore) + modifier claimBefore() { + if (block.number < claimBeforeBlock) _; } - function setDelay(uint _claimBefore) onlyOwner { - claimBefore = _claimBefore; + function setClaimBefore(uint _claimBeforeBlock) onlyOwner { + claimBeforeBlock = _claimBeforeBlock; } - function claimOwnership() onlyPendingOwner onTime { + function claimOwnership() onlyPendingOwner claimBefore { owner = pendingOwner; pendingOwner = 0x0; - claimBefore = 0; + claimBeforeBlock = 0; } } diff --git a/test/DelayedClaimble.js b/test/DelayedClaimble.js index 7c0a4c581..f2b7d0b71 100644 --- a/test/DelayedClaimble.js +++ b/test/DelayedClaimble.js @@ -11,13 +11,13 @@ contract('DelayedClaimable', function(accounts) { var newOwner = accounts[2]; return delayedClaimable.transfer(newOwner) .then(function(){ - return delayedClaimable.setDelay(1000) + return delayedClaimable.setClaimBefore(1000) }) .then(function(){ - return delayedClaimable.claimBefore(); + return delayedClaimable.claimBeforeBlock(); }) - .then(function(claimBefore) { - assert.isTrue(claimBefore == 1000); + .then(function(claimBeforeBlock) { + assert.isTrue(claimBeforeBlock == 1000); return delayedClaimable.pendingOwner(); }) .then(function(pendingOwner) { @@ -37,13 +37,13 @@ contract('DelayedClaimable', function(accounts) { var newOwner = accounts[1]; return delayedClaimable.transfer(newOwner) .then(function(){ - return delayedClaimable.setDelay(1) + return delayedClaimable.setClaimBefore(1) }) .then(function(){ - return delayedClaimable.claimBefore(); + return delayedClaimable.claimBeforeBlock(); }) - .then(function(claimBefore) { - assert.isTrue(claimBefore == 1); + .then(function(claimBeforeBlock) { + assert.isTrue(claimBeforeBlock == 1); return delayedClaimable.pendingOwner(); }) .then(function(pendingOwner) { From c7eb6736ee986e5d6751290ec36473485d024b10 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Wed, 16 Nov 2016 19:49:57 -0300 Subject: [PATCH 4/9] DelayedClaimable contract with test added Renamed DelayedClaimable function and modifier --- contracts/Claimable.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contracts/Claimable.sol b/contracts/Claimable.sol index 279e3480a..c8bc0c6be 100644 --- a/contracts/Claimable.sol +++ b/contracts/Claimable.sol @@ -1,6 +1,10 @@ +<<<<<<< HEAD pragma solidity ^0.4.0; +======= +pragma solidity ^0.4.4; +>>>>>>> 0aa4d02... DelayedClaimable contract with test added import './Ownable.sol'; From 423cec41e366db504f18a3c050108d92cc68bbdb Mon Sep 17 00:00:00 2001 From: AugustoL Date: Wed, 7 Dec 2016 18:32:42 -0300 Subject: [PATCH 5/9] claimBefore modifier removed on DelayedClaimable contract --- contracts/DelayedClaimable.sol | 8 ++------ test/DelayedClaimble.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/contracts/DelayedClaimable.sol b/contracts/DelayedClaimable.sol index 8739f3307..51a4a58af 100644 --- a/contracts/DelayedClaimable.sol +++ b/contracts/DelayedClaimable.sol @@ -10,16 +10,12 @@ import './Claimable.sol'; contract DelayedClaimable is Ownable, Claimable { uint public claimBeforeBlock; - modifier claimBefore() { - if (block.number < claimBeforeBlock) - _; - } - function setClaimBefore(uint _claimBeforeBlock) onlyOwner { claimBeforeBlock = _claimBeforeBlock; } - function claimOwnership() onlyPendingOwner claimBefore { + function claimOwnership() onlyPendingOwner { + if (block.number > claimBeforeBlock) throw; owner = pendingOwner; pendingOwner = 0x0; claimBeforeBlock = 0; diff --git a/test/DelayedClaimble.js b/test/DelayedClaimble.js index f2b7d0b71..b97e097f2 100644 --- a/test/DelayedClaimble.js +++ b/test/DelayedClaimble.js @@ -8,8 +8,7 @@ contract('DelayedClaimable', function(accounts) { }); it("changes pendingOwner after transfer succesful", function(done) { - var newOwner = accounts[2]; - return delayedClaimable.transfer(newOwner) + return delayedClaimable.transfer(accounts[2]) .then(function(){ return delayedClaimable.setClaimBefore(1000) }) @@ -21,21 +20,20 @@ contract('DelayedClaimable', function(accounts) { return delayedClaimable.pendingOwner(); }) .then(function(pendingOwner) { - assert.isTrue(pendingOwner === newOwner); - return delayedClaimable.claimOwnership({from: newOwner}); + assert.isTrue(pendingOwner === accounts[2]); + return delayedClaimable.claimOwnership({from: accounts[2]}); }) .then(function() { return delayedClaimable.owner(); }) .then(function(owner) { - assert.isTrue(owner === newOwner); + assert.isTrue(owner === accounts[2]); }) .then(done) }); it("changes pendingOwner after transfer fails", function(done) { - var newOwner = accounts[1]; - return delayedClaimable.transfer(newOwner) + return delayedClaimable.transfer(accounts[1]) .then(function(){ return delayedClaimable.setClaimBefore(1) }) @@ -47,14 +45,17 @@ contract('DelayedClaimable', function(accounts) { return delayedClaimable.pendingOwner(); }) .then(function(pendingOwner) { - assert.isTrue(pendingOwner === newOwner); - return delayedClaimable.claimOwnership({from: newOwner}); + assert.isTrue(pendingOwner === accounts[1]); + return delayedClaimable.claimOwnership({from: accounts[1]}); + }) + .catch(function(error) { + if (error.message.search('invalid JUMP') == -1) throw error }) .then(function() { return delayedClaimable.owner(); }) .then(function(owner) { - assert.isTrue(owner != newOwner); + assert.isTrue(owner != accounts[1]); }) .then(done) }); From 02f7f4c49d26e6fafeddf76534d118c2e8d608a1 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Thu, 15 Dec 2016 21:21:54 -0300 Subject: [PATCH 6/9] Fix invalid character on Claimable --- contracts/Claimable.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contracts/Claimable.sol b/contracts/Claimable.sol index c8bc0c6be..279e3480a 100644 --- a/contracts/Claimable.sol +++ b/contracts/Claimable.sol @@ -1,10 +1,6 @@ -<<<<<<< HEAD pragma solidity ^0.4.0; -======= -pragma solidity ^0.4.4; ->>>>>>> 0aa4d02... DelayedClaimable contract with test added import './Ownable.sol'; From f29264354351ffe2f66ce9212a2ad24f9756bee8 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Mon, 19 Dec 2016 19:15:22 -0300 Subject: [PATCH 8/9] DelayedClaimable tests changed to work with rename of transfer() to transferOwnership() --- test/DelayedClaimble.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/DelayedClaimble.js b/test/DelayedClaimble.js index b97e097f2..006485f12 100644 --- a/test/DelayedClaimble.js +++ b/test/DelayedClaimble.js @@ -8,7 +8,7 @@ contract('DelayedClaimable', function(accounts) { }); it("changes pendingOwner after transfer succesful", function(done) { - return delayedClaimable.transfer(accounts[2]) + return delayedClaimable.transferOwnership(accounts[2]) .then(function(){ return delayedClaimable.setClaimBefore(1000) }) @@ -33,7 +33,7 @@ contract('DelayedClaimable', function(accounts) { }); it("changes pendingOwner after transfer fails", function(done) { - return delayedClaimable.transfer(accounts[1]) + return delayedClaimable.transferOwnership(accounts[1]) .then(function(){ return delayedClaimable.setClaimBefore(1) }) From d97492404516af266763339e0abc1fdac993760a Mon Sep 17 00:00:00 2001 From: AugustoL Date: Thu, 29 Dec 2016 16:12:32 -0300 Subject: [PATCH 9/9] 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); }); });