Expect fails while comparing BigNumber
See original GitHub issueCan 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:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
On second glance this is using a custom
BigNumber
constructor.@AbdulRafaySiddiqui you should consider using
.deep.equal
instead ofequals
.BigNumber
is not a primitive so referential equality will not work on it two instances ofBigNumber
Hmm, that’s the reason, Anyways thanks for your help, I can just use the
.deep.equal
it’s fine.