Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escrows #1014

Merged
merged 15 commits into from
Jul 3, 2018
Merged

Escrows #1014

11 changes: 4 additions & 7 deletions test/payment/RefundEscrow.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import EVMRevert from '../helpers/EVMRevert';
import { inLogs } from '../helpers/expectEvent';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preferred usage for better readability is:

import expectEvent from '../helpers/expectEvent';

expectEvent.inLogs(receipt.logs);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that made more sense, but preferred to copy the existing code style :/

Copy link
Contributor

@frangio frangio Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const BigNumber = web3.BigNumber;

Expand Down Expand Up @@ -40,8 +41,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {

const receipt = await this.escrow.close({ from: owner });

receipt.logs.length.should.equal(1);
receipt.logs[0].event.should.equal('Closed');
await inLogs(receipt.logs, 'Closed');
});

context('closed state', function () {
Expand Down Expand Up @@ -73,8 +73,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {

const receipt = await this.escrow.enableRefunds({ from: owner });

receipt.logs.length.should.equal(1);
receipt.logs[0].event.should.equal('RefundsEnabled');
inLogs(receipt.logs, 'RefundsEnabled');
});

context('refund state', function () {
Expand All @@ -96,9 +95,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) {

refundeeFinalBalance.sub(refundeeInitialBalance).should.be.bignumber.equal(amount);

receipt.logs.length.should.equal(1);
receipt.logs[0].event.should.equal('Refunded');
receipt.logs[0].args.refundee.should.equal(refundee);
inLogs(receipt.logs, 'Refunded', { refundee });
receipt.logs[0].args.weiAmount.should.be.bignumber.equal(amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that the helper returns the event, so you can do

const event = expectEvent.inLogs(receipt.logs, 'Refunded', { refundee });
event.args.weiAmount.should.be.bignumber.equal(amount);

In this way you also stop relying on the event being at index 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, I missed that bit, ty!

}
});
Expand Down