Is this an issue with deep matching/object identity?

AssertionError: expected <BN: 204fce5e3e25026110000000> to equal <BN: 204fce5e3e25026110000000>

It seems strange that chai.should seems to work fine with the same vars:

// works

// doesn't work
assert.equal(supplyCap, _cap);

3 Answers 3


Change this:

assert.equal(supplyCap, _cap);

To this:

assert.equal(supplyCap.toString(), _cap.toString());
  • Makes sense. This is because there is some internal difference between the objects?
    – errata
    Jan 25, 2020 at 17:49
  • 1
    @errata: I think that assert.equal just uses ==, and since you're passing two different objects, it fails. You can verify my conjecture by calling assert.equal(supplyCap, supplyCap) and see if it passes. Jan 25, 2020 at 19:18
  • interesting point.. thx again
    – errata
    Jan 25, 2020 at 20:48

Consider using bn-chai if you do it a lot.

Then you can do:

expect(new BN('1')).to.eq.BN(new BN('1'));
expect(new BN('1')).to.eq.BN('1');
expect(new BN('1')).to.eq.BN(1);
  • Ya that does look a lot more pleasant. Perhaps I'll try to migrate. thx!
    – errata
    Sep 14, 2020 at 23:24

I'm not sure if this solution applies to your case, but whenever I handle numbers from smart contracts I use the Number(...) constructor as follows.

assert.equal(Number(supplyCap), Number(_cap));

And works perfectly for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.