|
|
@ -1,11 +1,15 @@ |
|
|
|
contract('Bounty', function(accounts) { |
|
|
|
var sendReward = function(sender, receiver, value){ |
|
|
|
before(function(){ |
|
|
|
web3.eth.sendTransaction({ |
|
|
|
owner = accounts[0]; |
|
|
|
from:sender, |
|
|
|
researcher = accounts[1]; |
|
|
|
to:receiver, |
|
|
|
|
|
|
|
value: value |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract('Bounty', function(accounts) { |
|
|
|
it("can create bounty contract with factory address", function(done){ |
|
|
|
it("can create bounty contract with factory address", function(done){ |
|
|
|
var target = SecureTargetMock.deployed(); |
|
|
|
var target = SecureTargetMock.deployed(); |
|
|
|
|
|
|
|
|
|
|
|
SimpleTokenBounty.new(target.address). |
|
|
|
SimpleTokenBounty.new(target.address). |
|
|
|
then(function(bounty){ |
|
|
|
then(function(bounty){ |
|
|
|
return bounty.factoryAddress.call() |
|
|
|
return bounty.factoryAddress.call() |
|
|
@ -18,26 +22,21 @@ contract('Bounty', function(accounts) { |
|
|
|
|
|
|
|
|
|
|
|
it("sets reward", function(done){ |
|
|
|
it("sets reward", function(done){ |
|
|
|
var target = SecureTargetMock.deployed(); |
|
|
|
var target = SecureTargetMock.deployed(); |
|
|
|
|
|
|
|
var owner = accounts[0]; |
|
|
|
var reward = web3.toWei(1, "ether"); |
|
|
|
var reward = web3.toWei(1, "ether"); |
|
|
|
var bounty; |
|
|
|
|
|
|
|
SimpleTokenBounty.new(target.address). |
|
|
|
SimpleTokenBounty.new(target.address). |
|
|
|
then(function(bounty){ |
|
|
|
then(function(bounty){ |
|
|
|
web3.eth.sendTransaction({ |
|
|
|
sendReward(owner, bounty.address, reward); |
|
|
|
from:owner, |
|
|
|
|
|
|
|
to:bounty.address, |
|
|
|
|
|
|
|
value: reward |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber()) |
|
|
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber()) |
|
|
|
}). |
|
|
|
}). |
|
|
|
then(done); |
|
|
|
then(done); |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe("SecureTargetMock", function(){ |
|
|
|
describe("SecureTargetMock", function(){ |
|
|
|
before(function(){ |
|
|
|
|
|
|
|
targetFactory = SecureTargetFactory.deployed(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("checkInvariant returns true", function(done){ |
|
|
|
it("checkInvariant returns true", function(done){ |
|
|
|
|
|
|
|
var targetFactory = SecureTargetFactory.deployed(); |
|
|
|
|
|
|
|
var bounty; |
|
|
|
SimpleTokenBounty.new(targetFactory.address). |
|
|
|
SimpleTokenBounty.new(targetFactory.address). |
|
|
|
then(function(_bounty) { |
|
|
|
then(function(_bounty) { |
|
|
|
bounty = _bounty; |
|
|
|
bounty = _bounty; |
|
|
@ -51,14 +50,46 @@ contract('Bounty', function(accounts) { |
|
|
|
}). |
|
|
|
}). |
|
|
|
then(done); |
|
|
|
then(done); |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe("InsecureTargetMock", function(){ |
|
|
|
it("cannot calim reward", function(done){ |
|
|
|
before(function(){ |
|
|
|
var targetFactory = SecureTargetFactory.deployed(); |
|
|
|
targetFactory = InsecureTargetFactory.deployed(); |
|
|
|
var owner = accounts[0]; |
|
|
|
|
|
|
|
var researcher = accounts[1]; |
|
|
|
|
|
|
|
var reward = web3.toWei(1, "ether"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SimpleTokenBounty.new(targetFactory.address). |
|
|
|
|
|
|
|
then(function(bounty) { |
|
|
|
|
|
|
|
var event = bounty.TargetCreated({}); |
|
|
|
|
|
|
|
event.watch(function(err, result) { |
|
|
|
|
|
|
|
event.stopWatching(); |
|
|
|
|
|
|
|
if (err) { throw err } |
|
|
|
|
|
|
|
var targetAddress = result.args.createdAddress; |
|
|
|
|
|
|
|
sendReward(owner, bounty.address, reward); |
|
|
|
|
|
|
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber()) |
|
|
|
|
|
|
|
bounty.claim(targetAddress, {from:researcher}). |
|
|
|
|
|
|
|
then(function(){ throw("should not come here")}). |
|
|
|
|
|
|
|
catch(function() { |
|
|
|
|
|
|
|
return bounty.claimed.call(); |
|
|
|
|
|
|
|
}). |
|
|
|
|
|
|
|
then(function(result) { |
|
|
|
|
|
|
|
assert.isFalse(result); |
|
|
|
|
|
|
|
bounty.withdrawPayments({from:researcher}). |
|
|
|
|
|
|
|
then(function(){ throw("should not come here")}). |
|
|
|
|
|
|
|
catch(function() { |
|
|
|
|
|
|
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber()) |
|
|
|
|
|
|
|
done(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
bounty.createTarget({from:researcher}); |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe("InsecureTargetMock", function(){ |
|
|
|
it("checkInvariant returns false", function(done){ |
|
|
|
it("checkInvariant returns false", function(done){ |
|
|
|
|
|
|
|
var targetFactory = InsecureTargetFactory.deployed(); |
|
|
|
|
|
|
|
var bounty; |
|
|
|
SimpleTokenBounty.new(targetFactory.address). |
|
|
|
SimpleTokenBounty.new(targetFactory.address). |
|
|
|
then(function(_bounty) { |
|
|
|
then(function(_bounty) { |
|
|
|
bounty = _bounty; |
|
|
|
bounty = _bounty; |
|
|
@ -72,5 +103,36 @@ contract('Bounty', function(accounts) { |
|
|
|
}). |
|
|
|
}). |
|
|
|
then(done); |
|
|
|
then(done); |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("calims reward", function(done){ |
|
|
|
|
|
|
|
var targetFactory = InsecureTargetFactory.deployed(); |
|
|
|
|
|
|
|
var owner = accounts[0]; |
|
|
|
|
|
|
|
var researcher = accounts[1]; |
|
|
|
|
|
|
|
var reward = web3.toWei(1, "ether"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SimpleTokenBounty.new(targetFactory.address). |
|
|
|
|
|
|
|
then(function(bounty) { |
|
|
|
|
|
|
|
var event = bounty.TargetCreated({}); |
|
|
|
|
|
|
|
event.watch(function(err, result) { |
|
|
|
|
|
|
|
event.stopWatching(); |
|
|
|
|
|
|
|
if (err) { throw err } |
|
|
|
|
|
|
|
var targetAddress = result.args.createdAddress; |
|
|
|
|
|
|
|
sendReward(owner, bounty.address, reward); |
|
|
|
|
|
|
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber()) |
|
|
|
|
|
|
|
bounty.claim(targetAddress, {from:researcher}). |
|
|
|
|
|
|
|
then(function() { |
|
|
|
|
|
|
|
return bounty.claimed.call(); |
|
|
|
|
|
|
|
}). |
|
|
|
|
|
|
|
then(function(result) { |
|
|
|
|
|
|
|
assert.isTrue(result); |
|
|
|
|
|
|
|
return bounty.withdrawPayments({from:researcher}) |
|
|
|
|
|
|
|
}). |
|
|
|
|
|
|
|
then(function() { |
|
|
|
|
|
|
|
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber()) |
|
|
|
|
|
|
|
}).then(done); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
bounty.createTarget({from:researcher}); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}); |
|
|
|
}); |
|
|
|