balanceDifference tests and application (#1514)
* Added balanceDifference tests. * Added balanceDifference tests. * Now using balanceDifference in all (most) tests. * Fixed typo.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
const { ethGetBalance } = require('../helpers/web3');
|
||||
const { balanceDifference } = require('../helpers/balanceDifference');
|
||||
const { ether } = require('../helpers/ether');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
@ -37,16 +37,13 @@ contract('PullPayment', function ([_, payer, payee1, payee2]) {
|
||||
});
|
||||
|
||||
it('can withdraw payment', async function () {
|
||||
const initialBalance = await ethGetBalance(payee1);
|
||||
(await balanceDifference(payee1, async () => {
|
||||
await this.contract.callTransfer(payee1, amount, { from: payer });
|
||||
(await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
|
||||
|
||||
await this.contract.callTransfer(payee1, amount, { from: payer });
|
||||
await this.contract.withdrawPayments(payee1);
|
||||
})).should.be.bignumber.equal(amount);
|
||||
|
||||
(await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
|
||||
|
||||
await this.contract.withdrawPayments(payee1);
|
||||
(await this.contract.payments(payee1)).should.be.bignumber.equal(0);
|
||||
|
||||
const balance = await ethGetBalance(payee1);
|
||||
Math.abs(balance - initialBalance - amount).should.be.lt(1e16);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
const expectEvent = require('../../helpers/expectEvent');
|
||||
const shouldFail = require('../../helpers/shouldFail');
|
||||
const { ethGetBalance } = require('../../helpers/web3');
|
||||
const { balanceDifference } = require('../../helpers/balanceDifference');
|
||||
const { ether } = require('../../helpers/ether');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
@ -61,17 +62,13 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
|
||||
|
||||
describe('withdrawals', async function () {
|
||||
it('can withdraw payments', async function () {
|
||||
const payeeInitialBalance = await ethGetBalance(payee1);
|
||||
|
||||
await this.escrow.deposit(payee1, { from: primary, value: amount });
|
||||
await this.escrow.withdraw(payee1, { from: primary });
|
||||
(await balanceDifference(payee1, async () => {
|
||||
await this.escrow.deposit(payee1, { from: primary, value: amount });
|
||||
await this.escrow.withdraw(payee1, { from: primary });
|
||||
})).should.be.bignumber.equal(amount);
|
||||
|
||||
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(0);
|
||||
|
||||
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(0);
|
||||
|
||||
const payeeFinalBalance = await ethGetBalance(payee1);
|
||||
payeeFinalBalance.sub(payeeInitialBalance).should.be.bignumber.equal(amount);
|
||||
});
|
||||
|
||||
it('can do an empty withdrawal', async function () {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
const shouldFail = require('../../helpers/shouldFail');
|
||||
const expectEvent = require('../../helpers/expectEvent');
|
||||
const { ethGetBalance } = require('../../helpers/web3');
|
||||
const { balanceDifference } = require('../../helpers/balanceDifference');
|
||||
const { ether } = require('../../helpers/ether');
|
||||
const { ZERO_ADDRESS } = require('../../helpers/constants');
|
||||
|
||||
@ -73,11 +73,9 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
|
||||
});
|
||||
|
||||
it('allows beneficiary withdrawal', async function () {
|
||||
const beneficiaryInitialBalance = await ethGetBalance(beneficiary);
|
||||
await this.escrow.beneficiaryWithdraw();
|
||||
const beneficiaryFinalBalance = await ethGetBalance(beneficiary);
|
||||
|
||||
beneficiaryFinalBalance.sub(beneficiaryInitialBalance).should.be.bignumber.equal(amount * refundees.length);
|
||||
(await balanceDifference(beneficiary, () =>
|
||||
this.escrow.beneficiaryWithdraw()
|
||||
)).should.be.bignumber.equal(amount * refundees.length);
|
||||
});
|
||||
|
||||
it('prevents entering the refund state', async function () {
|
||||
@ -109,11 +107,9 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
|
||||
|
||||
it('refunds refundees', async function () {
|
||||
for (const refundee of [refundee1, refundee2]) {
|
||||
const refundeeInitialBalance = await ethGetBalance(refundee);
|
||||
await this.escrow.withdraw(refundee, { from: primary });
|
||||
const refundeeFinalBalance = await ethGetBalance(refundee);
|
||||
|
||||
refundeeFinalBalance.sub(refundeeInitialBalance).should.be.bignumber.equal(amount);
|
||||
(await balanceDifference(refundee, () =>
|
||||
this.escrow.withdraw(refundee, { from: primary }))
|
||||
).should.be.bignumber.equal(amount);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user