Promisify web3 sync requests in tests (#1009)
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import { ethGetBalance, ethSendTransaction } from '../helpers/web3';
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
require('chai')
|
||||
@ -19,9 +21,9 @@ contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, pa
|
||||
});
|
||||
|
||||
it('should accept payments', async function () {
|
||||
await web3.eth.sendTransaction({ from: owner, to: this.contract.address, value: amount });
|
||||
await ethSendTransaction({ from: owner, to: this.contract.address, value: amount });
|
||||
|
||||
const balance = web3.eth.getBalance(this.contract.address);
|
||||
const balance = await ethGetBalance(this.contract.address);
|
||||
balance.should.be.bignumber.equal(amount);
|
||||
});
|
||||
|
||||
@ -40,35 +42,35 @@ contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, pa
|
||||
});
|
||||
|
||||
it('should throw if non-payee want to claim', async function () {
|
||||
await web3.eth.sendTransaction({ from: payer1, to: this.contract.address, value: amount });
|
||||
await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount });
|
||||
await this.contract.claim({ from: nonpayee1 }).should.be.rejectedWith(EVMThrow);
|
||||
});
|
||||
|
||||
it('should distribute funds to payees', async function () {
|
||||
await web3.eth.sendTransaction({ from: payer1, to: this.contract.address, value: amount });
|
||||
await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount });
|
||||
|
||||
// receive funds
|
||||
const initBalance = web3.eth.getBalance(this.contract.address);
|
||||
const initBalance = await ethGetBalance(this.contract.address);
|
||||
initBalance.should.be.bignumber.equal(amount);
|
||||
|
||||
// distribute to payees
|
||||
const initAmount1 = web3.eth.getBalance(payee1);
|
||||
const initAmount1 = await ethGetBalance(payee1);
|
||||
await this.contract.claim({ from: payee1 });
|
||||
const profit1 = web3.eth.getBalance(payee1) - initAmount1;
|
||||
const profit1 = await ethGetBalance(payee1) - initAmount1;
|
||||
assert(Math.abs(profit1 - web3.toWei(0.20, 'ether')) < 1e16);
|
||||
|
||||
const initAmount2 = web3.eth.getBalance(payee2);
|
||||
const initAmount2 = await ethGetBalance(payee2);
|
||||
await this.contract.claim({ from: payee2 });
|
||||
const profit2 = web3.eth.getBalance(payee2) - initAmount2;
|
||||
const profit2 = await ethGetBalance(payee2) - initAmount2;
|
||||
assert(Math.abs(profit2 - web3.toWei(0.10, 'ether')) < 1e16);
|
||||
|
||||
const initAmount3 = web3.eth.getBalance(payee3);
|
||||
const initAmount3 = await ethGetBalance(payee3);
|
||||
await this.contract.claim({ from: payee3 });
|
||||
const profit3 = web3.eth.getBalance(payee3) - initAmount3;
|
||||
const profit3 = await ethGetBalance(payee3) - initAmount3;
|
||||
assert(Math.abs(profit3 - web3.toWei(0.70, 'ether')) < 1e16);
|
||||
|
||||
// end balance should be zero
|
||||
const endBalance = web3.eth.getBalance(this.contract.address);
|
||||
const endBalance = await ethGetBalance(this.contract.address);
|
||||
endBalance.should.be.bignumber.equal(0);
|
||||
|
||||
// check correct funds released accounting
|
||||
|
||||
Reference in New Issue
Block a user