DelayedClaimable contract with test added
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
pragma solidity ^0.4.0;
|
||||
pragma solidity ^0.4.4;
|
||||
import './Ownable.sol';
|
||||
|
||||
/*
|
||||
|
||||
25
contracts/DelayedClaimable.sol
Normal file
25
contracts/DelayedClaimable.sol
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
58
test/DelayedClaimble.js
Normal file
58
test/DelayedClaimble.js
Normal file
@ -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)
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user