refactor tests for truffle 3
This commit is contained in:
@ -9,22 +9,22 @@ import './Claimable.sol';
|
|||||||
|
|
||||||
contract DelayedClaimable is Ownable, Claimable {
|
contract DelayedClaimable is Ownable, Claimable {
|
||||||
|
|
||||||
uint public claimBeforeBlock;
|
uint public end;
|
||||||
uint public claimAfterBlock;
|
uint public start;
|
||||||
|
|
||||||
function setClaimBlocks(uint _claimBeforeBlock, uint _claimAfterBlock) onlyOwner {
|
function setLimits(uint _start, uint _end) onlyOwner {
|
||||||
if (_claimAfterBlock > claimBeforeBlock)
|
if (_start > _end)
|
||||||
throw;
|
throw;
|
||||||
claimBeforeBlock = _claimBeforeBlock;
|
end = _end;
|
||||||
claimAfterBlock = _claimAfterBlock;
|
start = _start;
|
||||||
}
|
}
|
||||||
|
|
||||||
function claimOwnership() onlyPendingOwner {
|
function claimOwnership() onlyPendingOwner {
|
||||||
if ((block.number > claimBeforeBlock) || (block.number < claimAfterBlock))
|
if ((block.number > end) || (block.number < start))
|
||||||
throw;
|
throw;
|
||||||
owner = pendingOwner;
|
owner = pendingOwner;
|
||||||
pendingOwner = 0x0;
|
pendingOwner = 0x0;
|
||||||
claimBeforeBlock = 0;
|
end = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,5 @@
|
|||||||
var Ownable = artifacts.require("ownership/Ownable.sol");
|
//var Ownable = artifacts.require("ownership/Ownable.sol");
|
||||||
var Claimable = artifacts.require("ownership/Claimable.sol");
|
|
||||||
var LimitBalance = artifacts.require("LimitBalance.sol");
|
|
||||||
var SecureTargetBounty = artifacts.require("test-helpers/SecureTargetBounty.sol");
|
|
||||||
var InsecureTargetBounty = artifacts.require("test-helpers/InsecureTargetBounty.sol");
|
|
||||||
|
|
||||||
module.exports = function(deployer) {
|
module.exports = function(deployer) {
|
||||||
deployer.deploy(Ownable);
|
//deployer.deploy(Ownable);
|
||||||
deployer.deploy(Claimable);
|
|
||||||
deployer.deploy(LimitBalance);
|
|
||||||
if(deployer.network == 'test'){
|
|
||||||
deployer.deploy(SecureTargetBounty);
|
|
||||||
deployer.deploy(InsecureTargetBounty);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
testrpc &
|
output=$(nc -z localhost 8545; echo $?)
|
||||||
|
[ $output -eq "0" ] && trpc_running=true
|
||||||
|
if [ ! $trpc_running ]; then
|
||||||
|
echo "Starting our own testrpc node instance"
|
||||||
|
testrpc > /dev/null &
|
||||||
trpc_pid=$!
|
trpc_pid=$!
|
||||||
|
fi
|
||||||
truffle test
|
truffle test
|
||||||
|
if [ ! $trpc_running ]; then
|
||||||
kill -9 $trpc_pid
|
kill -9 $trpc_pid
|
||||||
|
fi
|
||||||
|
|||||||
@ -1,25 +1,39 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
let sendReward = function(sender, receiver, value){
|
let sendReward = function(sender, receiver, value){
|
||||||
web3.eth.sendTransaction({
|
web3.eth.sendTransaction({
|
||||||
from:sender,
|
from:sender,
|
||||||
to:receiver,
|
to:receiver,
|
||||||
value: value
|
value: value
|
||||||
})
|
});
|
||||||
|
};
|
||||||
|
var SecureTargetBounty = artifacts.require('helpers/SecureTargetBounty.sol');
|
||||||
|
var InsecureTargetBounty = artifacts.require('helpers/InsecureTargetBounty.sol');
|
||||||
|
|
||||||
|
function awaitEvent(event, handler) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
function wrappedHandler(...args) {
|
||||||
|
Promise.resolve(handler(...args)).then(resolve).catch(reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.watch(wrappedHandler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
contract('Bounty', function(accounts) {
|
contract('Bounty', function(accounts) {
|
||||||
|
|
||||||
it("sets reward", async function(){
|
it('sets reward', async function() {
|
||||||
let owner = accounts[0];
|
let owner = accounts[0];
|
||||||
let reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, 'ether');
|
||||||
let bounty = await SecureTargetBounty.new();
|
let bounty = await SecureTargetBounty.new();
|
||||||
sendReward(owner, bounty.address, reward);
|
sendReward(owner, bounty.address, reward);
|
||||||
|
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber());
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber());
|
||||||
})
|
});
|
||||||
|
|
||||||
it("empties itself when killed", async function(){
|
it('empties itself when killed', async function(){
|
||||||
let owner = accounts[0];
|
let owner = accounts[0];
|
||||||
let reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, 'ether');
|
||||||
let bounty = await SecureTargetBounty.new();
|
let bounty = await SecureTargetBounty.new();
|
||||||
sendReward(owner, bounty.address, reward);
|
sendReward(owner, bounty.address, reward);
|
||||||
|
|
||||||
@ -27,89 +41,74 @@ contract('Bounty', function(accounts) {
|
|||||||
|
|
||||||
await bounty.kill();
|
await bounty.kill();
|
||||||
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber());
|
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber());
|
||||||
})
|
});
|
||||||
|
|
||||||
describe("Against secure contract", function(){
|
describe('Against secure contract', function(){
|
||||||
|
|
||||||
it("checkInvariant returns true", async function(){
|
it('cannot claim reward', async function(){
|
||||||
let bounty = await SecureTargetBounty.new();
|
|
||||||
let target = await bounty.createTarget();
|
|
||||||
let check = await bounty.checkInvariant.call();
|
|
||||||
|
|
||||||
assert.isTrue(check);
|
|
||||||
})
|
|
||||||
|
|
||||||
it("cannot claim reward", async function(done){
|
|
||||||
let owner = accounts[0];
|
let owner = accounts[0];
|
||||||
let researcher = accounts[1];
|
let researcher = accounts[1];
|
||||||
let reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, 'ether');
|
||||||
let bounty = await SecureTargetBounty.new();
|
let bounty = await SecureTargetBounty.new();
|
||||||
let event = bounty.TargetCreated({});
|
let event = bounty.TargetCreated({});
|
||||||
|
|
||||||
event.watch(async function(err, result) {
|
event.watch(async function(err, result) {
|
||||||
event.stopWatching();
|
event.stopWatching();
|
||||||
if (err) { throw err }
|
if (err) { throw err; }
|
||||||
|
|
||||||
var targetAddress = result.args.createdAddress;
|
var targetAddress = result.args.createdAddress;
|
||||||
sendReward(owner, bounty.address, reward);
|
sendReward(owner, bounty.address, reward);
|
||||||
|
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber())
|
assert.equal(reward,
|
||||||
|
web3.eth.getBalance(bounty.address).toNumber());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let tmpClain = await bounty.claim(targetAddress, {from:researcher});
|
await bounty.claim(targetAddress, {from:researcher});
|
||||||
done("should not come here");
|
assert.isTrue(false); // should never reach here
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
let reClaimedBounty = await bounty.claimed.call();
|
let reClaimedBounty = await bounty.claimed.call();
|
||||||
assert.isFalse(reClaimedBounty);
|
assert.isFalse(reClaimedBounty);
|
||||||
|
|
||||||
try {
|
|
||||||
let withdraw = await bounty.withdrawPayments({from:researcher});
|
|
||||||
done("should not come here")
|
|
||||||
} catch (err) {
|
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber());
|
|
||||||
done();
|
|
||||||
}
|
}
|
||||||
}//end of first try catch
|
try {
|
||||||
|
await bounty.withdrawPayments({from:researcher});
|
||||||
|
assert.isTrue(false); // should never reach here
|
||||||
|
} catch (err) {
|
||||||
|
assert.equal(reward,
|
||||||
|
web3.eth.getBalance(bounty.address).toNumber());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
bounty.createTarget({from:researcher});
|
bounty.createTarget({from:researcher});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe("Against broken contract", function(){
|
describe('Against broken contract', function(){
|
||||||
it("checkInvariant returns false", async function(){
|
it('claims reward', async function() {
|
||||||
let bounty = await InsecureTargetBounty.new();
|
|
||||||
let target = await bounty.createTarget();
|
|
||||||
let invariantCall = await bounty.checkInvariant.call();
|
|
||||||
|
|
||||||
assert.isFalse(invariantCall);
|
|
||||||
})
|
|
||||||
|
|
||||||
it("claims reward", async function(done){
|
|
||||||
let owner = accounts[0];
|
let owner = accounts[0];
|
||||||
let researcher = accounts[1];
|
let researcher = accounts[1];
|
||||||
let reward = web3.toWei(1, "ether");
|
let reward = web3.toWei(1, 'ether');
|
||||||
let bounty = await InsecureTargetBounty.new();
|
let bounty = await InsecureTargetBounty.new();
|
||||||
let event = bounty.TargetCreated({});
|
let event = bounty.TargetCreated({});
|
||||||
|
|
||||||
event.watch(async function(err, result) {
|
let watcher = async function(err, result) {
|
||||||
event.stopWatching();
|
event.stopWatching();
|
||||||
if (err) { throw err }
|
if (err) { throw err; }
|
||||||
let targetAddress = result.args.createdAddress;
|
let targetAddress = result.args.createdAddress;
|
||||||
sendReward(owner, bounty.address, reward);
|
sendReward(owner, bounty.address, reward);
|
||||||
|
|
||||||
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber());
|
assert.equal(reward, web3.eth.getBalance(bounty.address).toNumber());
|
||||||
|
|
||||||
let bountyClaim = await bounty.claim(targetAddress, {from:researcher});
|
await bounty.claim(targetAddress, {from:researcher});
|
||||||
let claim = await bounty.claimed.call();
|
let claim = await bounty.claimed.call();
|
||||||
|
|
||||||
assert.isTrue(claim);
|
assert.isTrue(claim);
|
||||||
|
|
||||||
let payment = await bounty.withdrawPayments({from:researcher});
|
await bounty.withdrawPayments({from:researcher});
|
||||||
|
|
||||||
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber());
|
assert.equal(0, web3.eth.getBalance(bounty.address).toNumber());
|
||||||
done();
|
};
|
||||||
})
|
|
||||||
bounty.createTarget({from:researcher});
|
bounty.createTarget({from:researcher});
|
||||||
})
|
await awaitEvent(event, watcher);
|
||||||
})
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Claimable = artifacts.require('../contracts/ownership/Claimable.sol');
|
||||||
|
|
||||||
contract('Claimable', function(accounts) {
|
contract('Claimable', function(accounts) {
|
||||||
let claimable;
|
let claimable;
|
||||||
|
|
||||||
@ -5,34 +9,34 @@ contract('Claimable', function(accounts) {
|
|||||||
claimable = await Claimable.new();
|
claimable = await Claimable.new();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should have an owner", async function() {
|
it('should have an owner', async function() {
|
||||||
let owner = await claimable.owner();
|
let owner = await claimable.owner();
|
||||||
assert.isTrue(owner != 0);
|
assert.isTrue(owner !== 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes pendingOwner after transfer", async function() {
|
it('changes pendingOwner after transfer', async function() {
|
||||||
let newOwner = accounts[1];
|
let newOwner = accounts[1];
|
||||||
let transfer = await claimable.transferOwnership(newOwner);
|
await claimable.transferOwnership(newOwner);
|
||||||
let pendingOwner = await claimable.pendingOwner();
|
let pendingOwner = await claimable.pendingOwner();
|
||||||
|
|
||||||
assert.isTrue(pendingOwner === newOwner);
|
assert.isTrue(pendingOwner === newOwner);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should prevent to claimOwnership from no pendingOwner", async function() {
|
it('should prevent to claimOwnership from no pendingOwner', async function() {
|
||||||
let claimedOwner = await claimable.claimOwnership({from: accounts[2]});
|
claimable.claimOwnership({from: accounts[2]});
|
||||||
let owner = await claimable.owner();
|
let owner = await claimable.owner();
|
||||||
|
|
||||||
assert.isTrue(owner != accounts[2]);
|
assert.isTrue(owner !== accounts[2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should prevent non-owners from transfering", async function() {
|
it('should prevent non-owners from transfering', async function() {
|
||||||
let transfer = await claimable.transferOwnership(accounts[2], {from: accounts[2]});
|
await claimable.transferOwnership(accounts[2], {from: accounts[2]});
|
||||||
let pendingOwner = await claimable.pendingOwner();
|
let pendingOwner = await claimable.pendingOwner();
|
||||||
|
|
||||||
assert.isFalse(pendingOwner === accounts[2]);
|
assert.isFalse(pendingOwner === accounts[2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("after initiating a transfer", function () {
|
describe('after initiating a transfer', function () {
|
||||||
let newOwner;
|
let newOwner;
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
@ -40,8 +44,8 @@ contract('Claimable', function(accounts) {
|
|||||||
await claimable.transferOwnership(newOwner);
|
await claimable.transferOwnership(newOwner);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes allow pending owner to claim ownership", async function() {
|
it('changes allow pending owner to claim ownership', async function() {
|
||||||
let claimedOwner = await claimable.claimOwnership({from: newOwner})
|
await claimable.claimOwnership({from: newOwner});
|
||||||
let owner = await claimable.owner();
|
let owner = await claimable.owner();
|
||||||
|
|
||||||
assert.isTrue(owner === newOwner);
|
assert.isTrue(owner === newOwner);
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var DayLimitMock = artifacts.require('helpers/DayLimitMock.sol');
|
||||||
|
|
||||||
contract('DayLimit', function(accounts) {
|
contract('DayLimit', function(accounts) {
|
||||||
|
|
||||||
it('should construct with the passed daily limit', async function() {
|
it('should construct with the passed daily limit', async function() {
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var DelayedClaimable = artifacts.require('../contracts/ownership/DelayedClaimable.sol');
|
||||||
|
|
||||||
contract('DelayedClaimable', function(accounts) {
|
contract('DelayedClaimable', function(accounts) {
|
||||||
var delayedClaimable;
|
var delayedClaimable;
|
||||||
|
|
||||||
@ -7,76 +11,58 @@ contract('DelayedClaimable', function(accounts) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Changes pendingOwner after transfer succesfull", function(done) {
|
it('can set claim blocks', async function() {
|
||||||
return delayedClaimable.transferOwnership(accounts[2])
|
await delayedClaimable.transferOwnership(accounts[2]);
|
||||||
.then(function(){
|
await delayedClaimable.setLimits(0, 1000);
|
||||||
return delayedClaimable.setClaimBlocks(1000,0);
|
let end = await delayedClaimable.end();
|
||||||
})
|
assert.equal(end, 1000);
|
||||||
.then(function(){
|
let start = await delayedClaimable.start();
|
||||||
return delayedClaimable.claimBeforeBlock();
|
assert.equal(start, 0);
|
||||||
})
|
|
||||||
.then(function(claimBeforeBlock) {
|
|
||||||
assert.isTrue(claimBeforeBlock == 1000);
|
|
||||||
return delayedClaimable.claimAfterBlock();
|
|
||||||
})
|
|
||||||
.then(function(claimAfterBlock) {
|
|
||||||
assert.isTrue(claimAfterBlock == 0);
|
|
||||||
return delayedClaimable.pendingOwner();
|
|
||||||
})
|
|
||||||
.then(function(pendingOwner) {
|
|
||||||
assert.isTrue(pendingOwner === accounts[2]);
|
|
||||||
return delayedClaimable.claimOwnership({from: accounts[2]});
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return delayedClaimable.owner();
|
|
||||||
})
|
|
||||||
.then(function(owner) {
|
|
||||||
assert.isTrue(owner === accounts[2]);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Changes pendingOwner after transfer fails", function(done) {
|
it('changes pendingOwner after transfer successful', async function() {
|
||||||
return delayedClaimable.transferOwnership(accounts[1])
|
await delayedClaimable.transferOwnership(accounts[2]);
|
||||||
.then(function(){
|
await delayedClaimable.setLimits(0, 1000);
|
||||||
return delayedClaimable.setClaimBlocks(11000,10000);
|
let end = await delayedClaimable.end();
|
||||||
})
|
assert.equal(end, 1000);
|
||||||
.then(function(){
|
let start = await delayedClaimable.start();
|
||||||
return delayedClaimable.claimBeforeBlock();
|
assert.equal(start, 0);
|
||||||
})
|
let pendingOwner = await delayedClaimable.pendingOwner();
|
||||||
.then(function(claimBeforeBlock) {
|
assert.equal(pendingOwner, accounts[2]);
|
||||||
assert.isTrue(claimBeforeBlock == 11000);
|
await delayedClaimable.claimOwnership({from: accounts[2]});
|
||||||
return delayedClaimable.claimAfterBlock();
|
let owner = await delayedClaimable.owner();
|
||||||
})
|
assert.equal(owner, accounts[2]);
|
||||||
.then(function(claimAfterBlock) {
|
|
||||||
assert.isTrue(claimAfterBlock == 10000);
|
|
||||||
return delayedClaimable.pendingOwner();
|
|
||||||
})
|
|
||||||
.then(function(pendingOwner) {
|
|
||||||
assert.isTrue(pendingOwner === accounts[1]);
|
|
||||||
return delayedClaimable.claimOwnership({from: accounts[1]});
|
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error;
|
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
return delayedClaimable.owner();
|
|
||||||
})
|
|
||||||
.then(function(owner) {
|
|
||||||
assert.isTrue(owner != accounts[1]);
|
|
||||||
})
|
|
||||||
.then(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Set claimBeforeBlock and claimAfterBlock invalid values fail", function(done) {
|
it('changes pendingOwner after transfer fails', async function() {
|
||||||
return delayedClaimable.transferOwnership(accounts[1])
|
await delayedClaimable.transferOwnership(accounts[1]);
|
||||||
.then(function(){
|
await delayedClaimable.setLimits(100, 110);
|
||||||
return delayedClaimable.setClaimBlocks(1000,10000);
|
let end = await delayedClaimable.end();
|
||||||
})
|
assert.equal(end, 110);
|
||||||
.catch(function(error) {
|
let start = await delayedClaimable.start();
|
||||||
if (error.message.search('invalid JUMP') == -1) throw error;
|
assert.equal(start, 100);
|
||||||
})
|
let pendingOwner = await delayedClaimable.pendingOwner();
|
||||||
.then(done);
|
assert.equal(pendingOwner, accounts[1]);
|
||||||
|
var err = null;
|
||||||
|
try {
|
||||||
|
await delayedClaimable.claimOwnership({from: accounts[1]});
|
||||||
|
} catch (error) {
|
||||||
|
err = error;
|
||||||
|
}
|
||||||
|
assert.isFalse(err.message.search('invalid JUMP') === -1);
|
||||||
|
let owner = await delayedClaimable.owner();
|
||||||
|
assert.isTrue(owner !== accounts[1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('set end and start invalid values fail', async function() {
|
||||||
|
await delayedClaimable.transferOwnership(accounts[1]);
|
||||||
|
var err = null;
|
||||||
|
try {
|
||||||
|
await delayedClaimable.setLimits(1001, 1000);
|
||||||
|
} catch (error) {
|
||||||
|
err = error;
|
||||||
|
}
|
||||||
|
assert.isFalse(err.message.search('invalid JUMP') === -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,51 +1,16 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Killable = artifacts.require('../contracts/lifecycle/Killable.sol');
|
||||||
|
require('./helpers/transactionMined.js');
|
||||||
|
|
||||||
contract('Killable', function(accounts) {
|
contract('Killable', function(accounts) {
|
||||||
//from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
|
|
||||||
web3.eth.getTransactionReceiptMined = function (txnHash, interval) {
|
|
||||||
var transactionReceiptAsync;
|
|
||||||
interval = interval ? interval : 500;
|
|
||||||
transactionReceiptAsync = function(txnHash, resolve, reject) {
|
|
||||||
try {
|
|
||||||
var receipt = web3.eth.getTransactionReceipt(txnHash);
|
|
||||||
if (receipt === null) {
|
|
||||||
setTimeout(function () {
|
|
||||||
transactionReceiptAsync(txnHash, resolve, reject);
|
|
||||||
}, interval);
|
|
||||||
} else {
|
|
||||||
resolve(receipt);
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (Array.isArray(txnHash)) {
|
it('should send balance to owner after death', async function() {
|
||||||
var promises = [];
|
let killable = await Killable.new({from: accounts[0], value: web3.toWei('10','ether')});
|
||||||
txnHash.forEach(function (oneTxHash) {
|
let owner = await killable.owner();
|
||||||
promises.push(web3.eth.getTransactionReceiptMined(oneTxHash, interval));
|
let initBalance = web3.eth.getBalance(owner);
|
||||||
});
|
await killable.kill({from: owner});
|
||||||
return Promise.all(promises);
|
let newBalance = web3.eth.getBalance(owner);
|
||||||
} else {
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
transactionReceiptAsync(txnHash, resolve, reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
it("should send balance to owner after death", async function() {
|
|
||||||
let initBalance, newBalance, owner, address, killable, kBalance, txnHash, receiptMined;
|
|
||||||
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('50','ether')}, function(err, result) {
|
|
||||||
if(err)
|
|
||||||
console.log("ERROR:" + err);
|
|
||||||
});
|
|
||||||
|
|
||||||
killable = await Killable.new({from: accounts[0], value: web3.toWei('10','ether')});
|
|
||||||
owner = await killable.owner();
|
|
||||||
initBalance = web3.eth.getBalance(owner);
|
|
||||||
kBalance = web3.eth.getBalance(killable.address);
|
|
||||||
txnHash = await killable.kill({from: owner});
|
|
||||||
receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
newBalance = web3.eth.getBalance(owner);
|
|
||||||
|
|
||||||
assert.isTrue(newBalance > initBalance);
|
assert.isTrue(newBalance > initBalance);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var LimitBalanceMock = artifacts.require('helpers/LimitBalanceMock.sol');
|
||||||
const assertJump = require('./helpers/assertJump');
|
const assertJump = require('./helpers/assertJump');
|
||||||
|
|
||||||
contract('LimitBalance', function(accounts) {
|
contract('LimitBalance', function(accounts) {
|
||||||
@ -9,46 +12,46 @@ contract('LimitBalance', function(accounts) {
|
|||||||
|
|
||||||
let LIMIT = 1000;
|
let LIMIT = 1000;
|
||||||
|
|
||||||
it("should expose limit", async function() {
|
it('should expose limit', async function() {
|
||||||
let limit = await lb.limit();
|
let limit = await lb.limit();
|
||||||
assert.equal(limit, LIMIT);
|
assert.equal(limit, LIMIT);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow sending below limit", async function() {
|
it('should allow sending below limit', async function() {
|
||||||
let amount = 1;
|
let amount = 1;
|
||||||
let limDeposit = await lb.limitedDeposit({value: amount});
|
await lb.limitedDeposit({value: amount});
|
||||||
|
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount);
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouldnt allow sending above limit", async function() {
|
it('shouldnt allow sending above limit', async function() {
|
||||||
let amount = 1110;
|
let amount = 1110;
|
||||||
try {
|
try {
|
||||||
let limDeposit = await lb.limitedDeposit({value: amount});
|
await lb.limitedDeposit({value: amount});
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
return assertJump(error);
|
return assertJump(error);
|
||||||
}
|
}
|
||||||
assert.fail('should have thrown before');
|
assert.fail('should have thrown before');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow multiple sends below limit", async function() {
|
it('should allow multiple sends below limit', async function() {
|
||||||
let amount = 500;
|
let amount = 500;
|
||||||
let limDeposit = await lb.limitedDeposit({value: amount});
|
await lb.limitedDeposit({value: amount});
|
||||||
|
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount);
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||||||
|
|
||||||
let limDeposit2 = await lb.limitedDeposit({value: amount});
|
await lb.limitedDeposit({value: amount});
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount*2);
|
assert.equal(web3.eth.getBalance(lb.address), amount*2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouldnt allow multiple sends above limit", async function() {
|
it('shouldnt allow multiple sends above limit', async function() {
|
||||||
let amount = 500;
|
let amount = 500;
|
||||||
let limDeposit = await lb.limitedDeposit({value: amount});
|
await lb.limitedDeposit({value: amount});
|
||||||
|
|
||||||
assert.equal(web3.eth.getBalance(lb.address), amount);
|
assert.equal(web3.eth.getBalance(lb.address), amount);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await lb.limitedDeposit({value: amount+1})
|
await lb.limitedDeposit({value: amount+1});
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
return assertJump(error);
|
return assertJump(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,43 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var MultisigWalletMock = artifacts.require('./helpers/MultisigWalletMock.sol');
|
||||||
|
require('./helpers/transactionMined.js');
|
||||||
|
|
||||||
contract('MultisigWallet', function(accounts) {
|
contract('MultisigWallet', function(accounts) {
|
||||||
//from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
|
let shouldntFail = function(err) {
|
||||||
web3.eth.getTransactionReceiptMined = function (txnHash, interval) {
|
assert.isFalse(!!err);
|
||||||
var transactionReceiptAsync;
|
|
||||||
interval = interval ? interval : 500;
|
|
||||||
transactionReceiptAsync = function(txnHash, resolve, reject) {
|
|
||||||
try {
|
|
||||||
var receipt = web3.eth.getTransactionReceipt(txnHash);
|
|
||||||
if (receipt == null) {
|
|
||||||
setTimeout(function () {
|
|
||||||
transactionReceiptAsync(txnHash, resolve, reject);
|
|
||||||
}, interval);
|
|
||||||
} else {
|
|
||||||
resolve(receipt);
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Array.isArray(txnHash)) {
|
|
||||||
var promises = [];
|
|
||||||
txnHash.forEach(function (oneTxHash) {
|
|
||||||
promises.push(web3.eth.getTransactionReceiptMined(oneTxHash, interval));
|
|
||||||
});
|
|
||||||
return Promise.all(promises);
|
|
||||||
} else {
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
transactionReceiptAsync(txnHash, resolve, reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
it('should send balance to passed address upon death', async function() {
|
it('should send balance to passed address upon death', async function() {
|
||||||
//Give account[0] 20 ether
|
//Give account[0] 20 ether
|
||||||
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, function(err, result) {
|
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
|
||||||
if(err)
|
|
||||||
console.log("ERROR:" + err);
|
|
||||||
});
|
|
||||||
|
|
||||||
let dailyLimit = 10;
|
let dailyLimit = 10;
|
||||||
let ownersRequired = 2;
|
let ownersRequired = 2;
|
||||||
@ -54,8 +26,6 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
await wallet.kill(accounts[0], {data: hash});
|
await wallet.kill(accounts[0], {data: hash});
|
||||||
let txnHash = await wallet.kill(accounts[0], {from: accounts[1], data: hash});
|
let txnHash = await wallet.kill(accounts[0], {from: accounts[1], data: hash});
|
||||||
|
|
||||||
let receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
|
|
||||||
//Get balances of owner and wallet after kill function is complete, compare with previous values
|
//Get balances of owner and wallet after kill function is complete, compare with previous values
|
||||||
let newOwnerBalance = web3.eth.getBalance(accounts[0]);
|
let newOwnerBalance = web3.eth.getBalance(accounts[0]);
|
||||||
let newWalletBalance = web3.eth.getBalance(wallet.address);
|
let newWalletBalance = web3.eth.getBalance(wallet.address);
|
||||||
@ -66,10 +36,7 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
it('should execute transaction if below daily limit', async function() {
|
it('should execute transaction if below daily limit', async function() {
|
||||||
//Give account[0] 20 ether
|
//Give account[0] 20 ether
|
||||||
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, function(err, result) {
|
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
|
||||||
if(err)
|
|
||||||
console.log("ERROR:" + err);
|
|
||||||
});
|
|
||||||
|
|
||||||
let dailyLimit = 10;
|
let dailyLimit = 10;
|
||||||
let ownersRequired = 2;
|
let ownersRequired = 2;
|
||||||
@ -82,7 +49,6 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
//Owner account0 commands wallet to send 9 wei to account2
|
//Owner account0 commands wallet to send 9 wei to account2
|
||||||
let txnHash = await wallet.execute(accounts[2], 9, hash);
|
let txnHash = await wallet.execute(accounts[2], 9, hash);
|
||||||
let receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
|
|
||||||
//Balance of account2 should have increased
|
//Balance of account2 should have increased
|
||||||
let newAccountBalance = web3.eth.getBalance(accounts[2]);
|
let newAccountBalance = web3.eth.getBalance(accounts[2]);
|
||||||
@ -91,10 +57,7 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
it('should prevent execution of transaction if above daily limit', async function() {
|
it('should prevent execution of transaction if above daily limit', async function() {
|
||||||
//Give account[0] 20 ether
|
//Give account[0] 20 ether
|
||||||
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, function(err, result) {
|
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
|
||||||
if(err)
|
|
||||||
console.log("ERROR:" + err);
|
|
||||||
});
|
|
||||||
|
|
||||||
let dailyLimit = 10;
|
let dailyLimit = 10;
|
||||||
let ownersRequired = 2;
|
let ownersRequired = 2;
|
||||||
@ -107,7 +70,6 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
//Owner account0 commands wallet to send 9 wei to account2
|
//Owner account0 commands wallet to send 9 wei to account2
|
||||||
let txnHash = await wallet.execute(accounts[2], 9, hash);
|
let txnHash = await wallet.execute(accounts[2], 9, hash);
|
||||||
let receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
|
|
||||||
//Balance of account2 should have increased
|
//Balance of account2 should have increased
|
||||||
let newAccountBalance = web3.eth.getBalance(accounts[2]);
|
let newAccountBalance = web3.eth.getBalance(accounts[2]);
|
||||||
@ -118,7 +80,6 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
//Owner account0 commands wallet to send 2 more wei to account2, going over the daily limit of 10
|
//Owner account0 commands wallet to send 2 more wei to account2, going over the daily limit of 10
|
||||||
txnHash = await wallet.execute(accounts[2], 2, hash);
|
txnHash = await wallet.execute(accounts[2], 2, hash);
|
||||||
receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
|
|
||||||
//Balance of account2 should not change
|
//Balance of account2 should not change
|
||||||
newAccountBalance = web3.eth.getBalance(accounts[2]);
|
newAccountBalance = web3.eth.getBalance(accounts[2]);
|
||||||
@ -127,10 +88,7 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
it('should execute transaction if above daily limit and enough owners approve', async function() {
|
it('should execute transaction if above daily limit and enough owners approve', async function() {
|
||||||
//Give account[0] 20 ether
|
//Give account[0] 20 ether
|
||||||
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, function(err, result) {
|
web3.eth.sendTransaction({from: web3.eth.coinbase, to: accounts[0], value: web3.toWei('20','ether')}, shouldntFail);
|
||||||
if(err)
|
|
||||||
console.log("ERROR:" + err);
|
|
||||||
});
|
|
||||||
|
|
||||||
let dailyLimit = 10;
|
let dailyLimit = 10;
|
||||||
let ownersRequired = 2;
|
let ownersRequired = 2;
|
||||||
@ -143,7 +101,6 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
//Owner account0 commands wallet to send 11 wei to account2
|
//Owner account0 commands wallet to send 11 wei to account2
|
||||||
let txnHash = await wallet.execute(accounts[2], 11, hash);
|
let txnHash = await wallet.execute(accounts[2], 11, hash);
|
||||||
let receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
|
|
||||||
//Balance of account2 should not change
|
//Balance of account2 should not change
|
||||||
let newAccountBalance = web3.eth.getBalance(accounts[2]);
|
let newAccountBalance = web3.eth.getBalance(accounts[2]);
|
||||||
@ -153,7 +110,6 @@ contract('MultisigWallet', function(accounts) {
|
|||||||
|
|
||||||
//Owner account1 commands wallet to send 11 wei to account2
|
//Owner account1 commands wallet to send 11 wei to account2
|
||||||
txnHash = await wallet.execute(accounts[2], 2, hash);
|
txnHash = await wallet.execute(accounts[2], 2, hash);
|
||||||
receiptMined = await web3.eth.getTransactionReceiptMined(txnHash);
|
|
||||||
|
|
||||||
//Balance of account2 should change
|
//Balance of account2 should change
|
||||||
newAccountBalance = web3.eth.getBalance(accounts[2]);
|
newAccountBalance = web3.eth.getBalance(accounts[2]);
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Ownable = artifacts.require('../contracts/ownership/Ownable.sol');
|
||||||
|
|
||||||
contract('Ownable', function(accounts) {
|
contract('Ownable', function(accounts) {
|
||||||
let ownable;
|
let ownable;
|
||||||
|
|
||||||
@ -5,31 +9,30 @@ contract('Ownable', function(accounts) {
|
|||||||
ownable = await Ownable.new();
|
ownable = await Ownable.new();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should have an owner", async function() {
|
it('should have an owner', async function() {
|
||||||
let owner = await ownable.owner();
|
let owner = await ownable.owner();
|
||||||
assert.isTrue(owner != 0);
|
assert.isTrue(owner !== 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes owner after transfer", async function() {
|
it('changes owner after transfer', async function() {
|
||||||
let other = accounts[1];
|
let other = accounts[1];
|
||||||
let transfer = await ownable.transferOwnership(other);
|
await ownable.transferOwnership(other);
|
||||||
let owner = await ownable.owner();
|
let owner = await ownable.owner();
|
||||||
|
|
||||||
assert.isTrue(owner === other);
|
assert.isTrue(owner === other);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should prevent non-owners from transfering", async function() {
|
it('should prevent non-owners from transfering', async function() {
|
||||||
let other = accounts[2];
|
let other = accounts[2];
|
||||||
let transfer = await ownable.transferOwnership(other, {from: accounts[2]});
|
await ownable.transferOwnership(other, {from: accounts[2]});
|
||||||
let owner = await ownable.owner();
|
let owner = await ownable.owner();
|
||||||
|
|
||||||
assert.isFalse(owner === other);
|
assert.isFalse(owner === other);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should guard ownership against stuck state", async function() {
|
it('should guard ownership against stuck state', async function() {
|
||||||
let ownable = Ownable.deployed();
|
|
||||||
let originalOwner = await ownable.owner();
|
let originalOwner = await ownable.owner();
|
||||||
let transfer = await ownable.transferOwnership(null, {from: originalOwner});
|
await ownable.transferOwnership(null, {from: originalOwner});
|
||||||
let newOwner = await ownable.owner();
|
let newOwner = await ownable.owner();
|
||||||
|
|
||||||
assert.equal(originalOwner, newOwner);
|
assert.equal(originalOwner, newOwner);
|
||||||
|
|||||||
@ -1,49 +1,53 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var PausableMock = artifacts.require('helpers/PausableMock.sol');
|
||||||
|
|
||||||
contract('Pausable', function(accounts) {
|
contract('Pausable', function(accounts) {
|
||||||
|
|
||||||
it("can perform normal process in non-emergency", async function() {
|
it('can perform normal process in non-emergency', async function() {
|
||||||
let Pausable = await PausableMock.new();
|
let Pausable = await PausableMock.new();
|
||||||
let count0 = await Pausable.count();
|
let count0 = await Pausable.count();
|
||||||
assert.equal(count0, 0);
|
assert.equal(count0, 0);
|
||||||
|
|
||||||
let normalProcess = await Pausable.normalProcess();
|
await Pausable.normalProcess();
|
||||||
let count1 = await Pausable.count();
|
let count1 = await Pausable.count();
|
||||||
assert.equal(count1, 1);
|
assert.equal(count1, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can not perform normal process in emergency", async function() {
|
it('can not perform normal process in emergency', async function() {
|
||||||
let Pausable = await PausableMock.new();
|
let Pausable = await PausableMock.new();
|
||||||
let emergencyStop = await Pausable.emergencyStop();
|
await Pausable.emergencyStop();
|
||||||
let count0 = await Pausable.count();
|
let count0 = await Pausable.count();
|
||||||
assert.equal(count0, 0);
|
assert.equal(count0, 0);
|
||||||
|
|
||||||
let normalProcess = await Pausable.normalProcess();
|
await Pausable.normalProcess();
|
||||||
let count1 = await Pausable.count();
|
let count1 = await Pausable.count();
|
||||||
assert.equal(count1, 0);
|
assert.equal(count1, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("can not take drastic measure in non-emergency", async function() {
|
it('can not take drastic measure in non-emergency', async function() {
|
||||||
let Pausable = await PausableMock.new();
|
let Pausable = await PausableMock.new();
|
||||||
let drasticMeasure = await Pausable.drasticMeasure();
|
await Pausable.drasticMeasure();
|
||||||
let drasticMeasureTaken = await Pausable.drasticMeasureTaken();
|
let drasticMeasureTaken = await Pausable.drasticMeasureTaken();
|
||||||
|
|
||||||
assert.isFalse(drasticMeasureTaken);
|
assert.isFalse(drasticMeasureTaken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can take a drastic measure in an emergency", async function() {
|
it('can take a drastic measure in an emergency', async function() {
|
||||||
let Pausable = await PausableMock.new();
|
let Pausable = await PausableMock.new();
|
||||||
let emergencyStop = await Pausable.emergencyStop();
|
await Pausable.emergencyStop();
|
||||||
let drasticMeasure = await Pausable.drasticMeasure();
|
await Pausable.drasticMeasure();
|
||||||
let drasticMeasureTaken = await Pausable.drasticMeasureTaken();
|
let drasticMeasureTaken = await Pausable.drasticMeasureTaken();
|
||||||
|
|
||||||
assert.isTrue(drasticMeasureTaken);
|
assert.isTrue(drasticMeasureTaken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should resume allowing normal process after emergency is over", async function() {
|
it('should resume allowing normal process after emergency is over', async function() {
|
||||||
let Pausable = await PausableMock.new();
|
let Pausable = await PausableMock.new();
|
||||||
let emergencyStop = await Pausable.emergencyStop();
|
await Pausable.emergencyStop();
|
||||||
let release = await Pausable.release();
|
await Pausable.release();
|
||||||
let normalProcess = await Pausable.normalProcess();
|
await Pausable.normalProcess();
|
||||||
let count0 = await Pausable.count();
|
let count0 = await Pausable.count();
|
||||||
|
|
||||||
assert.equal(count0, 1);
|
assert.equal(count0, 1);
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
var PullPaymentMock = artifacts.require("./helpers/PullPaymentMock.sol");
|
||||||
|
|
||||||
contract('PullPayment', function(accounts) {
|
contract('PullPayment', function(accounts) {
|
||||||
|
|
||||||
it("can't call asyncSend externally", async function() {
|
it("can't call asyncSend externally", async function() {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const assertJump = require('./helpers/assertJump');
|
const assertJump = require('./helpers/assertJump');
|
||||||
|
var SafeMathMock = artifacts.require("./helpers/SafeMathMock.sol");
|
||||||
|
|
||||||
contract('SafeMath', function(accounts) {
|
contract('SafeMath', function(accounts) {
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
var ShareableMock = artifacts.require("./helpers/ShareableMock.sol");
|
||||||
|
|
||||||
contract('Shareable', function(accounts) {
|
contract('Shareable', function(accounts) {
|
||||||
|
|
||||||
it('should construct with correct owners and number of sigs required', async function() {
|
it('should construct with correct owners and number of sigs required', async function() {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const assertJump = require('./helpers/assertJump');
|
const assertJump = require('./helpers/assertJump');
|
||||||
|
var StandardTokenMock = artifacts.require("./helpers/StandardTokenMock.sol");
|
||||||
|
|
||||||
contract('StandardToken', function(accounts) {
|
contract('StandardToken', function(accounts) {
|
||||||
|
|
||||||
|
|||||||
34
test/helpers/transactionMined.js
Normal file
34
test/helpers/transactionMined.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
//from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
|
||||||
|
module.export = web3.eth.transactionMined = function (txnHash, interval) {
|
||||||
|
var transactionReceiptAsync;
|
||||||
|
interval = interval ? interval : 500;
|
||||||
|
transactionReceiptAsync = function(txnHash, resolve, reject) {
|
||||||
|
try {
|
||||||
|
var receipt = web3.eth.getTransactionReceipt(txnHash);
|
||||||
|
if (receipt === null) {
|
||||||
|
setTimeout(function () {
|
||||||
|
transactionReceiptAsync(txnHash, resolve, reject);
|
||||||
|
}, interval);
|
||||||
|
} else {
|
||||||
|
resolve(receipt);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (Array.isArray(txnHash)) {
|
||||||
|
var promises = [];
|
||||||
|
txnHash.forEach(function (oneTxHash) {
|
||||||
|
promises.push(
|
||||||
|
web3.eth.getTransactionReceiptMined(oneTxHash, interval));
|
||||||
|
});
|
||||||
|
return Promise.all(promises);
|
||||||
|
} else {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
transactionReceiptAsync(txnHash, resolve, reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user