question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expect fails while comparing BigNumber

See original GitHub issue

Can anyone tell, why both of the following expects are failing

const hre = require("hardhat");
const { ethers } = hre;
const { BigNumber, utils } = ethers;

describe("Deploy YDF token and check balance", function () {
    it("Deployer balance should be equal to 30K", async function () {
        
        expect(utils.parseEther("1.0")).to.equals(utils.parseEther("1.0"));
        expect(BigNumber.from("30000000000000000000000")).to.equals(BigNumber.from("30000000000000000000000"));
    });
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
keithamuscommented, Mar 12, 2021

On second glance this is using a custom BigNumber constructor.

@AbdulRafaySiddiqui you should consider using .deep.equal instead of equals. BigNumber is not a primitive so referential equality will not work on it two instances of BigNumber

0reactions
AbdulRafaySiddiquicommented, Mar 12, 2021

Hmm, that’s the reason, Anyways thanks for your help, I can just use the .deep.equal it’s fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comparing ethers BigNumber does not work
Try like this : expect(totalSupply.eq(BigNumber.from("4")).to.equal(true);. This is because to.equal internally uses the strict equality ...
Read more >
Chai should be bignumber equal doesn't work - Stack Overflow
I faced the same problem, the answer is simple just use the expect function of chai with to.be.bignumber.equal. Example: const { expect } ......
Read more >
Misuse of BigNumber instances in tests · Issue #204 - GitHub
@misteraverin has pointed out that the issue is not only numerical error but also flat out wrong comparisons when two BigNumber objects are ......
Read more >
Chai matchers — waffle documentation - Read the Docs
You must await the expect in order for the matcher to execute properly. Failing to await will cause the assertion to pass whether...
Read more >
Reference | Ethereum development environment for ... - Hardhat
bignumber.js instances. This also works when deep-equal comparisons of arrays or objects are performed:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found