Skip to content

Commit

Permalink
large test case is split in two
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbe committed Jan 30, 2018
1 parent b67fab8 commit 343d2cb
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions test/test_splitter_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Promise.promisifyAll(web3.eth, { suffix: "Promise" });

web3.eth.getTransactionReceiptMined = require("./getTransactionReceiptMined.js");

const TEST_AMOUNT = 1000000;

var Splitter = artifacts.require("./Splitter.sol");

contract('Splitter', function (accounts) {
Expand Down Expand Up @@ -41,15 +43,11 @@ contract('Splitter', function (accounts) {
}).catch(done);
});

it("funds sent by Alice to fallback should be claimable by Bob and Carol", function () {
it("Alice should be able to split", function () {
// calculate expected amounts to be debited and credited
var amount = 1000000;
var halfAmount1 = Math.floor(amount / 2);
var halfAmount2 = amount - halfAmount1;
var amount = TEST_AMOUNT;

// send some amount to Splitter on behalf of Alice
var balancesBefore, txHash, tx, txCost;
var txBobInfo, txCostBob, txCarolInfo;
return getBalances().then(_balancesBefore => {
balancesBefore = _balancesBefore;
return splitter.split.sendTransaction(bob, carol, { from: alice, to: splitter.address, value: amount });
Expand All @@ -63,7 +61,17 @@ contract('Splitter', function (accounts) {
// got receipt for the transaction - make sure funds are with splitter

This comment has been minimized.

Copy link
@xavierlepretre

xavierlepretre Jan 30, 2018

You could make another test that checks the event was correct.

This comment has been minimized.

Copy link
@abbbe

abbbe Jan 31, 2018

Author Owner

#38

txCost = txReceipt.gasUsed * tx.gasPrice;
return assertBalancesDiffEqual(balancesBefore, [amount, -txCost - amount, 0, 0, 0, 0]);
}).then(() => {
});
});

it("funds split by Alice should be claimable by Bob and Carol", function () {
var halfAmount1 = Math.floor(TEST_AMOUNT / 2);
var halfAmount2 = TEST_AMOUNT - halfAmount1;

var balancesBefore, txBobInfo, txCostBob, txCarolInfo;

return getBalances().then(_balancesBefore => {
balancesBefore = _balancesBefore;
// claim as bob
return splitter.withdraw({ from: bob });
}).then(_txBobInfo => {
Expand All @@ -78,7 +86,7 @@ contract('Splitter', function (accounts) {
return web3.eth.getTransactionPromise(txCarolInfo.tx);
}).then(txCarol => {
var txCostCarol = txCarolInfo.receipt.gasUsed * txCarol.gasPrice;
return assertBalancesDiffEqual(balancesBefore, [0, -txCost - amount, halfAmount1 - txCostBob, halfAmount2 - txCostCarol, 0, 0]);
return assertBalancesDiffEqual(balancesBefore, [-TEST_AMOUNT, 0, halfAmount1 - txCostBob, halfAmount2 - txCostCarol, 0, 0]);
});
});

Expand All @@ -89,7 +97,7 @@ contract('Splitter', function (accounts) {
};

it("transfers to fallback should fail, even from Alice", function (done) {
var amount = 1000000;
var amount = TEST_AMOUNT;

// send some amount to Splitter on behalf of Alice
web3.eth.sendTransactionPromise({ from: alice, to: splitter.address, value: amount })
Expand All @@ -107,7 +115,7 @@ contract('Splitter', function (accounts) {

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 amount = TEST_AMOUNT;
var halfAmount1 = Math.floor(amount / 2);
var halfAmount2 = amount - halfAmount1;

Expand Down

0 comments on commit 343d2cb

Please sign in to comment.