Replaced assertJump, assertRevert and expectThrow with shouldFail. (#1363)

* Replaced assertJump, assertRevert and expectThrow with shouldFail.

* Fixed linter errors.

* Fixed typo.

* Made the helpers async.
This commit is contained in:
Nicolás Venturo
2018-10-09 16:23:55 -03:00
committed by GitHub
parent 58a42443df
commit b0da0fded0
46 changed files with 282 additions and 352 deletions

View File

@ -1,6 +1,6 @@
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const shouldFail = require('../helpers/shouldFail');
const { ether } = require('../helpers/ether');
const BigNumber = web3.BigNumber;
@ -34,7 +34,7 @@ contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
it('reverts on withdrawals', async function () {
await this.escrow.deposit(payee, { from: owner, value: amount });
await expectThrow(this.escrow.withdraw(payee, { from: owner }), EVMRevert);
await shouldFail.reverting(this.escrow.withdraw(payee, { from: owner }));
});
});
});

View File

@ -1,6 +1,5 @@
const expectEvent = require('../helpers/expectEvent');
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const shouldFail = require('../helpers/shouldFail');
const { ethGetBalance } = require('../helpers/web3');
const { ether } = require('../helpers/ether');
@ -28,7 +27,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
});
it('only the primary account can deposit', async function () {
await expectThrow(this.escrow.deposit(payee1, { from: payee2 }), EVMRevert);
await shouldFail.reverting(this.escrow.deposit(payee1, { from: payee2 }));
});
it('emits a deposited event', async function () {
@ -80,7 +79,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
});
it('only the primary account can withdraw', async function () {
await expectThrow(this.escrow.withdraw(payee1, { from: payee1 }), EVMRevert);
await shouldFail.reverting(this.escrow.withdraw(payee1, { from: payee1 }));
});
it('emits a withdrawn event', async function () {

View File

@ -1,5 +1,4 @@
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert');
const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const { ethGetBalance } = require('../helpers/web3');
const { ether } = require('../helpers/ether');
@ -18,7 +17,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
const refundees = [refundee1, refundee2];
it('requires a non-null beneficiary', async function () {
await expectThrow(
await shouldFail.reverting(
RefundEscrow.new(ZERO_ADDRESS, { from: primary })
);
});
@ -42,17 +41,17 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
it('does not refund refundees', async function () {
await this.escrow.deposit(refundee1, { from: primary, value: amount });
await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
await shouldFail.reverting(this.escrow.withdraw(refundee1));
});
it('does not allow beneficiary withdrawal', async function () {
await this.escrow.deposit(refundee1, { from: primary, value: amount });
await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
await shouldFail.reverting(this.escrow.beneficiaryWithdraw());
});
});
it('only the primary account can enter closed state', async function () {
await expectThrow(this.escrow.close({ from: beneficiary }), EVMRevert);
await shouldFail.reverting(this.escrow.close({ from: beneficiary }));
const { logs } = await this.escrow.close({ from: primary });
expectEvent.inLogs(logs, 'Closed');
@ -66,11 +65,11 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
});
it('rejects deposits', async function () {
await expectThrow(this.escrow.deposit(refundee1, { from: primary, value: amount }), EVMRevert);
await shouldFail.reverting(this.escrow.deposit(refundee1, { from: primary, value: amount }));
});
it('does not refund refundees', async function () {
await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
await shouldFail.reverting(this.escrow.withdraw(refundee1));
});
it('allows beneficiary withdrawal', async function () {
@ -82,16 +81,16 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
});
it('prevents entering the refund state', async function () {
await expectThrow(this.escrow.enableRefunds({ from: primary }), EVMRevert);
await shouldFail.reverting(this.escrow.enableRefunds({ from: primary }));
});
it('prevents re-entering the closed state', async function () {
await expectThrow(this.escrow.close({ from: primary }), EVMRevert);
await shouldFail.reverting(this.escrow.close({ from: primary }));
});
});
it('only the primary account can enter refund state', async function () {
await expectThrow(this.escrow.enableRefunds({ from: beneficiary }), EVMRevert);
await shouldFail.reverting(this.escrow.enableRefunds({ from: beneficiary }));
const { logs } = await this.escrow.enableRefunds({ from: primary });
expectEvent.inLogs(logs, 'RefundsEnabled');
@ -105,7 +104,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
});
it('rejects deposits', async function () {
await expectThrow(this.escrow.deposit(refundee1, { from: primary, value: amount }), EVMRevert);
await shouldFail.reverting(this.escrow.deposit(refundee1, { from: primary, value: amount }));
});
it('refunds refundees', async function () {
@ -119,15 +118,15 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
});
it('does not allow beneficiary withdrawal', async function () {
await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
await shouldFail.reverting(this.escrow.beneficiaryWithdraw());
});
it('prevents entering the closed state', async function () {
await expectThrow(this.escrow.close({ from: primary }), EVMRevert);
await shouldFail.reverting(this.escrow.close({ from: primary }));
});
it('prevents re-entering the refund state', async function () {
await expectThrow(this.escrow.enableRefunds({ from: primary }), EVMRevert);
await shouldFail.reverting(this.escrow.enableRefunds({ from: primary }));
});
});
});

View File

@ -9,35 +9,34 @@ require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const { expectThrow } = require('../helpers/expectThrow');
const { EVMRevert } = require('../helpers/EVMRevert.js');
const shouldFail = require('../helpers/shouldFail');
const SplitPayment = artifacts.require('SplitPayment');
contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
const amount = ether(1.0);
it('rejects an empty set of payees', async function () {
await expectThrow(SplitPayment.new([], []), EVMRevert);
await shouldFail.reverting(SplitPayment.new([], []));
});
it('rejects more payees than shares', async function () {
await expectThrow(SplitPayment.new([payee1, payee2, payee3], [20, 30]), EVMRevert);
await shouldFail.reverting(SplitPayment.new([payee1, payee2, payee3], [20, 30]));
});
it('rejects more shares than payees', async function () {
await expectThrow(SplitPayment.new([payee1, payee2], [20, 30, 40]), EVMRevert);
await shouldFail.reverting(SplitPayment.new([payee1, payee2], [20, 30, 40]));
});
it('rejects null payees', async function () {
await expectThrow(SplitPayment.new([payee1, ZERO_ADDRESS], [20, 30]), EVMRevert);
await shouldFail.reverting(SplitPayment.new([payee1, ZERO_ADDRESS], [20, 30]));
});
it('rejects zero-valued shares', async function () {
await expectThrow(SplitPayment.new([payee1, payee2], [20, 0]), EVMRevert);
await shouldFail.reverting(SplitPayment.new([payee1, payee2], [20, 0]));
});
it('rejects repeated payees', async function () {
await expectThrow(SplitPayment.new([payee1, payee1], [20, 30]), EVMRevert);
await shouldFail.reverting(SplitPayment.new([payee1, payee1], [20, 30]));
});
context('once deployed', function () {
@ -74,12 +73,12 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1,
});
it('should throw if no funds to claim', async function () {
await expectThrow(this.contract.release(payee1), EVMRevert);
await shouldFail.reverting(this.contract.release(payee1));
});
it('should throw if non-payee want to claim', async function () {
await sendEther(payer1, this.contract.address, amount);
await expectThrow(this.contract.release(nonpayee1), EVMRevert);
await shouldFail.reverting(this.contract.release(nonpayee1));
});
it('should distribute funds to payees', async function () {