Swap target contract at test by using abstract interface
This commit is contained in:
@ -9,9 +9,7 @@ import '../PullPayment.sol';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
contract Target {
|
contract Target {
|
||||||
function checkInvarient() returns(bool){
|
function checkInvarient() returns(bool);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contract Bounty is PullPayment {
|
contract Bounty is PullPayment {
|
||||||
@ -23,8 +21,8 @@ contract Bounty is PullPayment {
|
|||||||
if (claimed) throw;
|
if (claimed) throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTarget() returns(Target) {
|
function createTarget(address targetAddress) returns(Target) {
|
||||||
target = new Target();
|
target = Target(targetAddress);
|
||||||
researchers[target] = msg.sender;
|
researchers[target] = msg.sender;
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@ -37,7 +35,6 @@ contract Bounty is PullPayment {
|
|||||||
address researcher = researchers[target];
|
address researcher = researchers[target];
|
||||||
if (researcher == 0) throw;
|
if (researcher == 0) throw;
|
||||||
// Check Target contract invariants
|
// Check Target contract invariants
|
||||||
// Customize this to the specifics of your contract
|
|
||||||
if (!target.checkInvarient()) {
|
if (!target.checkInvarient()) {
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
7
contracts/test-helpers/InsecureTargetMock.sol
Normal file
7
contracts/test-helpers/InsecureTargetMock.sol
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
pragma solidity ^0.4.0;
|
||||||
|
|
||||||
|
contract InsecureTargetMock {
|
||||||
|
function checkInvarient() returns(bool){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
contracts/test-helpers/SecureTargetMock.sol
Normal file
7
contracts/test-helpers/SecureTargetMock.sol
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
pragma solidity ^0.4.0;
|
||||||
|
|
||||||
|
contract SecureTargetMock {
|
||||||
|
function checkInvarient() returns(bool){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,4 +6,6 @@ module.exports = function(deployer) {
|
|||||||
deployer.deploy(CrowdsaleTokenBounty);
|
deployer.deploy(CrowdsaleTokenBounty);
|
||||||
deployer.deploy(Ownable);
|
deployer.deploy(Ownable);
|
||||||
deployer.deploy(LimitFunds);
|
deployer.deploy(LimitFunds);
|
||||||
|
deployer.deploy(SecureTargetMock);
|
||||||
|
deployer.deploy(InsecureTargetMock);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
contract('Bounty', function(accounts) {
|
contract('Bounty', function(accounts) {
|
||||||
it.only("create target", function(done){
|
it.only("can call checkInvarient for InsecureTargetMock", function(done){
|
||||||
var bounty = Bounty.deployed();
|
var bounty = Bounty.deployed();
|
||||||
|
var target = SecureTargetMock.deployed();
|
||||||
bounty.createTarget().
|
bounty.createTarget(target.address).
|
||||||
then(function() {
|
then(function() {
|
||||||
return bounty.checkInvarient.call()
|
return bounty.checkInvarient.call()
|
||||||
}).
|
}).
|
||||||
@ -11,4 +11,17 @@ contract('Bounty', function(accounts) {
|
|||||||
}).
|
}).
|
||||||
then(done);
|
then(done);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can call checkInvarient for InsecureTargetMock", function(done){
|
||||||
|
var bounty = Bounty.deployed();
|
||||||
|
var target = InsecureTargetMock.deployed();
|
||||||
|
bounty.createTarget(target.address).
|
||||||
|
then(function() {
|
||||||
|
return bounty.checkInvarient.call()
|
||||||
|
}).
|
||||||
|
then(function(result) {
|
||||||
|
assert.isFalse(result);
|
||||||
|
}).
|
||||||
|
then(done);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user