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

Replace all asserts with chai.should #1183

Merged
merged 9 commits into from
Aug 10, 2018
Merged

Conversation

nventuro
Copy link
Contributor

@nventuro nventuro commented Aug 9, 2018

Fixes part of #1091.

@nventuro nventuro added kind:improvement tests Test suite and helpers. labels Aug 9, 2018
@nventuro nventuro added this to the v2.0 milestone Aug 9, 2018
@nventuro nventuro requested review from frangio and shrugs August 9, 2018 20:55
@@ -3,6 +3,12 @@ const { ethGetBalance } = require('./helpers/web3');

const LimitBalanceMock = artifacts.require('LimitBalanceMock');

const BigNumber = web3.BigNumber;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like doing this pattern if we never use BigNumber by itself again. can we use

require('chai')
  .use(require('chai-bignumber')(web3.BigNumber))
  .should();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some test files do use it though (but I'd have to check and see if it's necessary). Maybe we could add some sort of global helper everyone requires, that initializes chai and exposes both bignumber and should.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually yeah I was wondering about that; just looked it up and we can do this chaijs/chai#868 (comment) to auto-register should, but we'd have to add a custom one to do bignumber.

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 think just having that one require (and making our setup not so magic) is fine for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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'll add that once this is merged then, to keep the PRs tidy.

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Thank you for taking on this gargantuan task!

Is there a special reason you're using .eq instead of .equal? I feel like this goes against the general rule against abbreviations. A large part of this PR consists of changing this, and I feel quite strongly that equal is better.

Everything else looks good.

assert.equal(ownerFinalBalance - ownerStartBalance, 10);

finalBalance.should.be.bignumber.equal(0);
(ownerFinalBalance.sub(ownerStartBalance)).should.be.bignumber.equal(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary parentheses here.

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is such a weird test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, we need to revise all tests at some point, some have poor coverage/are a bit wonky.

@@ -417,7 +423,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) {
await this.token.increaseApproval(spender, amount, { from: owner });

const allowance = await this.token.allowance(owner, spender);
assert.equal(allowance, amount + 1);
allowance.should.be.bignumber.eq(amount + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is amount here a BigNumber instance? We should be using BigNumber addition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not, though it probably should be. Spawned #1189

@@ -453,7 +459,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) {
await this.token.increaseApproval(spender, amount, { from: owner });

const allowance = await this.token.allowance(owner, spender);
assert.equal(allowance, amount + 1);
allowance.should.be.bignumber.eq(amount + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@frangio frangio merged commit ac91af9 into OpenZeppelin:master Aug 10, 2018
@nventuro nventuro deleted the chai-should branch August 11, 2018 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Test suite and helpers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants