Skip to content

Commit

Permalink
remove done and return promise in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbe committed Jan 30, 2018
1 parent 816050e commit 38af7a6
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions test/test_splitter_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract('Splitter', function (accounts) {
}).catch(done);
});

it("funds sent by Alice to fallback should be claimable by Bob and Carol", function (done) {
it("funds sent by Alice to fallback should be claimable by Bob and Carol", function () {
// calculate expected amounts to be debited and credited
var amount = 1000000;
var halfAmount1 = Math.floor(amount / 2);
Expand All @@ -50,7 +50,7 @@ contract('Splitter', function (accounts) {
// send some amount to Splitter on behalf of Alice
var balancesBefore, txHash, tx, txCost;
var txBobInfo, txCostBob, txCarolInfo;
getBalances().then(_balancesBefore => {
return getBalances().then(_balancesBefore => {
balancesBefore = _balancesBefore;
return splitter.split.sendTransaction(bob, carol, { from: alice, to: splitter.address, value: amount });
}).then(_txHash => {
Expand Down Expand Up @@ -79,9 +79,7 @@ contract('Splitter', function (accounts) {
}).then(txCarol => {
var txCostCarol = txCarolInfo.receipt.gasUsed * txCarol.gasPrice;
return assertBalancesDiffEqual(balancesBefore, [0, -txCost - amount, halfAmount1 - txCostBob, halfAmount2 - txCostCarol, 0, 0]);
}).then(() => {
done();
}).catch(done);
});
});

function _assertRevert(error, tag) {
Expand All @@ -107,15 +105,15 @@ contract('Splitter', function (accounts) {
});
});

it("funds sent by Dave to split(emma, carol) should be claimable by Emma and Carol, events should fire", function (done) {
it("funds sent by Dave to split(emma, carol) should be claimable by Emma and Carol, events should fire", function () {
// calculate expected amounts to be debited and credited
var amount = 1000000;
var halfAmount1 = Math.floor(amount / 2);
var halfAmount2 = amount - halfAmount1;

// send some amount to Splitter on behalf of Dave
var balancesBefore, txDaveInfo, txDaveCost, txEmmaInfo, txEmmaCost, txCarolInfo;
getBalances().then(_balancesBefore => {
return getBalances().then(_balancesBefore => {
balancesBefore = _balancesBefore;
return splitter.split(emma, carol, { from: dave, value: amount });
}).then(_txDaveInfo => {
Expand Down Expand Up @@ -154,13 +152,12 @@ contract('Splitter', function (accounts) {
}).then(txCarol => {
var txCostCarol = txCarolInfo.receipt.gasUsed * txCarol.gasPrice;
assertBalancesDiffEqual(balancesBefore, [0, 0, 0, halfAmount2 - txCostCarol, -txDaveCost - amount, halfAmount1 - txEmmaCost]);
done();
}).catch(done);
});
});

it("kill should work", function (done) {
// connfirm the contract is not empty to begin with
web3.eth.getCodePromise(splitter.address).then(code => {
it("kill should work", function () {
// confirm the contract is not empty to begin with
return web3.eth.getCodePromise(splitter.address).then(code => {
// console.log("contract code before kill:", code); // DEBUG
assert.notEqual(parseInt(code + "0"), 0, 'Live contract code is empty');
// kill
Expand All @@ -174,7 +171,6 @@ contract('Splitter', function (accounts) {
}).then(code => {
// console.log("contract code after kill:", code); // DEBUG
assert.equal(parseInt(code + "0"), 0, 'Killed contract code is not empty');
done();
}).catch(done);
});
});
});

0 comments on commit 38af7a6

Please sign in to comment.