From 721d8fbbf79ee578bc82c30e804e24e039680ecc Mon Sep 17 00:00:00 2001 From: Makoto Inoue Date: Wed, 26 Oct 2016 09:12:17 +0100 Subject: [PATCH] Pass factory address at contract creation phase --- contracts/bounties/SimpleTokenBounty.sol | 9 ++++++-- test/Bounty.js | 28 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/contracts/bounties/SimpleTokenBounty.sol b/contracts/bounties/SimpleTokenBounty.sol index 6721186a4..8fbb2f426 100644 --- a/contracts/bounties/SimpleTokenBounty.sol +++ b/contracts/bounties/SimpleTokenBounty.sol @@ -16,16 +16,21 @@ contract Target { function checkInvariant() returns(bool); } -contract Bounty is PullPayment { +contract SimpleTokenBounty is PullPayment { Target target; bool public claimed; + address public factoryAddress; mapping(address => address) public researchers; function() { if (claimed) throw; } - function createTarget(address factoryAddress) returns(Target) { + function SimpleTokenBounty(address _factoryAddress){ + factoryAddress = _factoryAddress; + } + + function createTarget() returns(Target) { target = Target(Factory(factoryAddress).deployContract()); researchers[target] = msg.sender; return target; diff --git a/test/Bounty.js b/test/Bounty.js index 68b567a8d..e66dbf7a9 100644 --- a/test/Bounty.js +++ b/test/Bounty.js @@ -1,11 +1,27 @@ contract('Bounty', function(accounts) { - it("can call checkInvariant for InsecureTargetMock", function(done){ - var bounty = Bounty.deployed(); + it("can create bounty contract with factory address", function(done){ var target = SecureTargetMock.deployed(); - bounty.createTarget(target.address). - then(function() { - return bounty.checkInvariant.call() + SimpleTokenBounty.new(target.address). + then(function(bounty){ + return bounty.factoryAddress.call() + }). + then(function(address){ + assert.equal(address, target.address) + }). + then(done); + }) + + it.only("can call checkInvariant for SecureTargetMock", function(done){ + var bounty; + var target = SecureTargetMock.deployed(); + SimpleTokenBounty.new(target.address). + then(function(_bounty) { + bounty = _bounty; + return bounty.createTarget.sendTransaction({gas:200000}); }). + // then(function() { + // return bounty.checkInvariant.call() + // }). then(function(result) { assert.isTrue(result); }). @@ -13,7 +29,7 @@ contract('Bounty', function(accounts) { }) it("can call checkInvariant for InsecureTargetMock", function(done){ - var bounty = Bounty.deployed(); + var bounty = SimpleTokenBounty.deployed(); var target = InsecureTargetMock.deployed(); bounty.createTarget(target.address). then(function() {