Skip to content

Commit fa1dfbd

Browse files
Aniket-Enggnventuro
authored andcommitted
Fix #1358 Test helper to send funds (#1367)
* signing prefix added * Minor improvement * Tests changed * Successfully tested * Minor improvements * Minor improvements * Revert "Dangling commas are now required. (#1359)" This reverts commit a688977. * fixes #1358 * linting done * suggested changes
1 parent a688977 commit fa1dfbd

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

test/BreakInvariantBounty.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { ethGetBalance, ethSendTransaction } = require('./helpers/web3');
2+
const { sendEther } = require('./helpers/sendTransaction');
23
const expectEvent = require('./helpers/expectEvent');
34
const { assertRevert } = require('./helpers/assertRevert');
45

@@ -17,13 +18,13 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
1718
});
1819

1920
it('can set reward', async function () {
20-
await ethSendTransaction({ from: owner, to: this.bounty.address, value: reward });
21+
await sendEther(owner, this.bounty.address, reward);
2122
(await ethGetBalance(this.bounty.address)).should.be.bignumber.equal(reward);
2223
});
2324

2425
context('with reward', function () {
2526
beforeEach(async function () {
26-
await ethSendTransaction({ from: owner, to: this.bounty.address, value: reward });
27+
await sendEther(owner, this.bounty.address, reward);
2728
});
2829

2930
describe('destroy', function () {

test/helpers/sendTransaction.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ function sendTransaction (target, name, argsTypes, argsValues, opts) {
1515
return target.sendTransaction(Object.assign({ data: encodedData }, opts));
1616
}
1717

18+
function sendEther (from, to, value) {
19+
web3.eth.sendTransaction({
20+
from: from,
21+
to: to,
22+
value: value,
23+
gasPrice: 0,
24+
});
25+
}
1826
module.exports = {
1927
findMethod,
2028
sendTransaction,
29+
sendEther,
2130
};

test/payment/SplitPayment.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { ethGetBalance, ethSendTransaction } = require('../helpers/web3');
1+
const { ethGetBalance } = require('../helpers/web3');
2+
const { sendEther } = require('./../helpers/sendTransaction');
23

34
const BigNumber = web3.BigNumber;
45

@@ -58,7 +59,7 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1,
5859
});
5960

6061
it('should accept payments', async function () {
61-
await ethSendTransaction({ from: owner, to: this.contract.address, value: amount });
62+
await sendEther(owner, this.contract.address, amount);
6263

6364
(await ethGetBalance(this.contract.address)).should.be.bignumber.equal(amount);
6465
});
@@ -76,12 +77,12 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1,
7677
});
7778

7879
it('should throw if non-payee want to claim', async function () {
79-
await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount });
80+
await sendEther(payer1, this.contract.address, amount);
8081
await expectThrow(this.contract.release(nonpayee1), EVMRevert);
8182
});
8283

8384
it('should distribute funds to payees', async function () {
84-
await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount });
85+
await sendEther(payer1, this.contract.address, amount);
8586

8687
// receive funds
8788
const initBalance = await ethGetBalance(this.contract.address);

0 commit comments

Comments
 (0)