diff --git a/contracts/bounties/SimpleTokenBounty.sol b/contracts/bounties/SimpleTokenBounty.sol index 7372289fe..9aeb6a7d9 100644 --- a/contracts/bounties/SimpleTokenBounty.sol +++ b/contracts/bounties/SimpleTokenBounty.sol @@ -9,9 +9,7 @@ import '../PullPayment.sol'; */ contract Target { - function checkInvarient() returns(bool){ - return true; - } + function checkInvarient() returns(bool); } contract Bounty is PullPayment { @@ -23,8 +21,8 @@ contract Bounty is PullPayment { if (claimed) throw; } - function createTarget() returns(Target) { - target = new Target(); + function createTarget(address targetAddress) returns(Target) { + target = Target(targetAddress); researchers[target] = msg.sender; return target; } @@ -37,7 +35,6 @@ contract Bounty is PullPayment { address researcher = researchers[target]; if (researcher == 0) throw; // Check Target contract invariants - // Customize this to the specifics of your contract if (!target.checkInvarient()) { throw; } diff --git a/contracts/test-helpers/InsecureTargetMock.sol b/contracts/test-helpers/InsecureTargetMock.sol new file mode 100644 index 000000000..101d371e9 --- /dev/null +++ b/contracts/test-helpers/InsecureTargetMock.sol @@ -0,0 +1,7 @@ +pragma solidity ^0.4.0; + +contract InsecureTargetMock { + function checkInvarient() returns(bool){ + return false; + } +} diff --git a/contracts/test-helpers/SecureTargetMock.sol b/contracts/test-helpers/SecureTargetMock.sol new file mode 100644 index 000000000..67e599018 --- /dev/null +++ b/contracts/test-helpers/SecureTargetMock.sol @@ -0,0 +1,7 @@ +pragma solidity ^0.4.0; + +contract SecureTargetMock { + function checkInvarient() returns(bool){ + return true; + } +} diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js index 8b400d5d1..51e052891 100644 --- a/migrations/2_deploy_contracts.js +++ b/migrations/2_deploy_contracts.js @@ -6,4 +6,6 @@ module.exports = function(deployer) { deployer.deploy(CrowdsaleTokenBounty); deployer.deploy(Ownable); deployer.deploy(LimitFunds); + deployer.deploy(SecureTargetMock); + deployer.deploy(InsecureTargetMock); }; diff --git a/test/Bounty.js b/test/Bounty.js index 4cb3e0325..e214b9683 100644 --- a/test/Bounty.js +++ b/test/Bounty.js @@ -1,8 +1,8 @@ contract('Bounty', function(accounts) { - it.only("create target", function(done){ + it.only("can call checkInvarient for InsecureTargetMock", function(done){ var bounty = Bounty.deployed(); - - bounty.createTarget(). + var target = SecureTargetMock.deployed(); + bounty.createTarget(target.address). then(function() { return bounty.checkInvarient.call() }). @@ -11,4 +11,17 @@ contract('Bounty', function(accounts) { }). 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); + }) });