Replace all asserts with chai.should (#1183)

* Moving towards chai.should.

* Fixed failing tests.

* Fixed linter errors.

* Revert package-lock.json changes.

* Fixed failing tests.

* s/eq/equal

* Addressed review comment
This commit is contained in:
Nicolás Venturo
2018-08-10 19:03:04 -03:00
committed by Francisco Giordano
parent a2e7103869
commit ac91af9a6a
41 changed files with 396 additions and 297 deletions

View File

@ -7,22 +7,22 @@ require('chai')
.should();
const { expectThrow } = require('../helpers/expectThrow');
const EVMThrow = require('../helpers/EVMThrow.js');
const { EVMRevert } = require('../helpers/EVMRevert.js');
const SplitPayment = artifacts.require('SplitPayment');
contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
const amount = web3.toWei(1.0, 'ether');
it('cannot be created with no payees', async function () {
await expectThrow(SplitPayment.new([], []), EVMThrow);
await expectThrow(SplitPayment.new([], []), EVMRevert);
});
it('requires shares for each payee', async function () {
await expectThrow(SplitPayment.new([payee1, payee2, payee3], [20, 30]), EVMThrow);
await expectThrow(SplitPayment.new([payee1, payee2, payee3], [20, 30]), EVMRevert);
});
it('requires a payee for each share', async function () {
await expectThrow(SplitPayment.new([payee1, payee2], [20, 30, 40]), EVMThrow);
await expectThrow(SplitPayment.new([payee1, payee2], [20, 30, 40]), EVMRevert);
});
context('once deployed', function () {
@ -42,7 +42,7 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1,
it('should store shares if address is payee', async function () {
const shares = await this.contract.shares.call(payee1);
shares.should.be.bignumber.not.equal(0);
shares.should.be.bignumber.not.eq(0);
});
it('should not store shares if address is not payee', async function () {
@ -51,12 +51,12 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1,
});
it('should throw if no funds to claim', async function () {
await expectThrow(this.contract.claim({ from: payee1 }), EVMThrow);
await expectThrow(this.contract.claim({ from: payee1 }), EVMRevert);
});
it('should throw if non-payee want to claim', async function () {
await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount });
await expectThrow(this.contract.claim({ from: nonpayee1 }), EVMThrow);
await expectThrow(this.contract.claim({ from: nonpayee1 }), EVMRevert);
});
it('should distribute funds to payees', async function () {
@ -69,18 +69,18 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1,
// distribute to payees
const initAmount1 = await ethGetBalance(payee1);
await this.contract.claim({ from: payee1 });
const profit1 = await ethGetBalance(payee1) - initAmount1;
assert(Math.abs(profit1 - web3.toWei(0.20, 'ether')) < 1e16);
const profit1 = (await ethGetBalance(payee1)).sub(initAmount1);
profit1.sub(web3.toWei(0.20, 'ether')).abs().should.be.bignumber.lt(1e16);
const initAmount2 = await ethGetBalance(payee2);
await this.contract.claim({ from: payee2 });
const profit2 = await ethGetBalance(payee2) - initAmount2;
assert(Math.abs(profit2 - web3.toWei(0.10, 'ether')) < 1e16);
const profit2 = (await ethGetBalance(payee2)).sub(initAmount2);
profit2.sub(web3.toWei(0.10, 'ether')).abs().should.be.bignumber.lt(1e16);
const initAmount3 = await ethGetBalance(payee3);
await this.contract.claim({ from: payee3 });
const profit3 = await ethGetBalance(payee3) - initAmount3;
assert(Math.abs(profit3 - web3.toWei(0.70, 'ether')) < 1e16);
const profit3 = (await ethGetBalance(payee3)).sub(initAmount3);
profit3.sub(web3.toWei(0.70, 'ether')).abs().should.be.bignumber.lt(1e16);
// end balance should be zero
const endBalance = await ethGetBalance(this.contract.address);