Contract returns 来自 Solidity 的 totalSupply as BigNumber 但需要在没有小数的情况下验证它

Contract returns totalSupply from Solidity as BigNumber but need to validate it without the decimals

Solidity returns totalSupply() 为 1 万亿 + 9 位小数为 1 万亿 concat 与 9 个零。

因此,当我尝试进行 mocha 测试以检查供应量是否为 1T 时,它失败了,因为该数字末尾有 9 个额外的零且没有小数点。

那么怎么改

BigNumber { value: "1000000000000000000000" } 到 1000000000000 所以我的测试通过了。

这是我的测试失败了;

        it('Should correctly set totalSupply to: 1T', async () => {
            const totalSupply = await hardhatToken.totalSupply();
            var tokenBalance = totalSupply.toString();
            console.log(tokenBalance);
            console.log(ethers.BigNumber.from(totalSupply, 9));
            expect(totalSupply).should.be.bignumber.equal(1000000000000);
        });

我有 BN.js 库,但我无法计算出过程!我想正确地做到这一点,而不仅仅是砍掉最后 9 位数字,因为还有其他类似问题的测试要写。

我以单独计算小数的方式编写测试,并且在断言中,我将小数零与值连接起来。

it('Should correctly set totalSupply to: 1T', async () => {
    const totalSupply = await hardhatToken.totalSupply();
    const decimals = ethers.BigNumber.from(10).pow(9);

    expect(totalSupply).to.equal(
        ethers.BigNumber.from(1_000_000_000_000).mul(decimals)
    );
});