Chai 应该是 bignumber equal 是行不通的

Chai should be bignumber equal doesn't work

我需要这样的柴

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

并且在测试期间

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

错误代码是

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)

我的代码也遇到了同样的问题。我找到了一个适合我的好解决方案。

尝试以下操作:

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

正如我在更新中提到的,你可以使用 JS Bigint,用它做所有的数学运算,然后将它作为字符串传递给 BN 构造函数,比如 utils.toBN((1000000n * 5748553687688487n).toString())