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

Expect fails while comparing BigNumber #1382

Closed
AbdulRafaySiddiqui opened this issue Mar 11, 2021 · 14 comments
Closed

Expect fails while comparing BigNumber #1382

AbdulRafaySiddiqui opened this issue Mar 11, 2021 · 14 comments

Comments

@AbdulRafaySiddiqui
Copy link

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"));
    });
});

@vapier
Copy link
Contributor

vapier commented Mar 11, 2021

i think #1365 fixed it but there isn't interest in fixing the problem in chai for some reason

@AbdulRafaySiddiqui
Copy link
Author

It's been 5 months since you posted the PR, but still no fix, sad :(
It is better to at least fix the problem now, rather than wait to integrate loupe at some later time.

@vapier
Copy link
Contributor

vapier commented Mar 11, 2021

i'd understand if the overhaul was coming soon and no new release were being made, but dev/fixes have continued in the branch, and new releases cut. so it seems odd that @keithamus prefers to leave chai broken.

@AbdulRafaySiddiqui
Copy link
Author

yeah, the latest release was 8 days ago, could have added your PR, even it wasn't that long, just a couple lines of code.

@keithamus
Copy link
Member

If you want to re-raise it on the 4.x.x branch I'll release it.

@vapier
Copy link
Contributor

vapier commented Mar 12, 2021

@AbdulRafaySiddiqui can you give #1383 a try and see if it fixes your problems ?

@keithamus
Copy link
Member

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

@AbdulRafaySiddiqui
Copy link
Author

Thanks, @keithamus , I checked, using .deep.equal it works, but not just equal.
I was following waffle's docs , so it's wrong there I guess.

@keithamus
Copy link
Member

keithamus commented Mar 12, 2021

Looks like it overrides the matchers. Do you have the following added:

import { solidity } from "ethereum-waffle";
chai.use(solidity);

If you don't it won't work

@AbdulRafaySiddiqui
Copy link
Author

AbdulRafaySiddiqui commented Mar 12, 2021

No, I don't have that, I was following hardhat docs

@AbdulRafaySiddiqui
Copy link
Author

AbdulRafaySiddiqui commented Mar 12, 2021

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

const { expect } = require("chai");
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"));
    });
});

This is my exact code.

@keithamus
Copy link
Member

I'm not familiar with any of these APIs so I can't tell you what you need to do but the default behaviour of Chai's .equals operator is the same as ===.

@AbdulRafaySiddiqui
Copy link
Author

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

@JangoCCC
Copy link

JangoCCC commented Apr 9, 2023

Does this issue fixed? I just encoutered the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants