From 85a4013f49779b812bcdd2ff5b95dea73d17e1f0 Mon Sep 17 00:00:00 2001 From: AugustoL Date: Fri, 18 Nov 2016 20:32:22 -0300 Subject: [PATCH] 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) {