Home > Software engineering >  Chai should be bignumber equal doesn't work
Chai should be bignumber equal doesn't work

Time:05-13

I am requireing chai like this

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

and during test

let balance = await contract.balanceOf(accountToReceive);
should.be.bignumber.eql(countToSend); //works fine
ownerBalance = await contract.balanceOf(owner);
should.be.bignumber.equal(settings.initialSupply.mul(utils.toBN(10).pow(_decimals)).sub(countToSend)); // gives en error

Error code is

AssertionError: expected <BN: 94e47b8d68171533ffff9c> to equal <BN: 94e47b8d68171533ffff9c>
       expected - actual

     at Context.<anonymous> (test/MOS.test.js:79:33)
     at processTicksAndRejections (node:internal/process/task_queues:96:5)

CodePudding user response:

I also faced the same issue with my code. I found a good solution which works for me.

Try the following:

require('chai').use(require('chai-as-promised')).should();
.use(bnChai(web3.utils.BN));

CodePudding user response:

As I've mentioned in update, you can use JS Bigint, do all your math with it and then just pass it to BN constructor as a string, like utils.toBN((1000000n * 5748553687688487n).toString())

  • Related