Promisify web3 sync requests in tests (#1009)

This commit is contained in:
Arun Kumar
2018-07-10 16:01:51 -05:00
committed by Matt Condon
parent 4575a240f7
commit 40b5594f52
26 changed files with 137 additions and 104 deletions

View File

@ -1,5 +1,6 @@
import expectThrow from './helpers/expectThrow';
import { ethGetBalance, ethSendTransaction } from './helpers/web3';
const SimpleSavingsWallet = artifacts.require('SimpleSavingsWallet');
@ -15,19 +16,21 @@ contract('SimpleSavingsWallet', function (accounts) {
});
it('should receive funds', async function () {
await web3.eth.sendTransaction({ from: owner, to: savingsWallet.address, value: paymentAmount });
assert.isTrue((new web3.BigNumber(paymentAmount)).equals(web3.eth.getBalance(savingsWallet.address)));
await ethSendTransaction({ from: owner, to: savingsWallet.address, value: paymentAmount });
const balance = await ethGetBalance(savingsWallet.address);
assert.isTrue((new web3.BigNumber(paymentAmount)).equals(balance));
});
it('owner can send funds', async function () {
// Receive payment so we have some money to spend.
await web3.eth.sendTransaction({ from: accounts[9], to: savingsWallet.address, value: 1000000 });
await ethSendTransaction({ from: accounts[9], to: savingsWallet.address, value: 1000000 });
await expectThrow(savingsWallet.sendTo(0, paymentAmount, { from: owner }));
await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, { from: owner }));
await expectThrow(savingsWallet.sendTo(accounts[1], 0, { from: owner }));
const balance = web3.eth.getBalance(accounts[1]);
const balance = await ethGetBalance(accounts[1]);
await savingsWallet.sendTo(accounts[1], paymentAmount, { from: owner });
assert.isTrue(balance.plus(paymentAmount).equals(web3.eth.getBalance(accounts[1])));
const updatedBalance = await ethGetBalance(accounts[1]);
assert.isTrue(balance.plus(paymentAmount).equals(updatedBalance));
});
});