Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

Solidity returns totalSupply() as 1 trillion + the 9 decimals as 1trillion concat with 9 zeroes.

So when I try to do a mocha test to check the supply is 1T, it fails because the number has 9 extra zeroes at the end and no decimal point.

So how to change

BigNumber { value: "1000000000000000000000" } to 1000000000000 so my test passes.

This is my test which fails;

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

I have the BN.js library but I cant work out the process! I'd like to do it properly without just chopping off the last 9 digits as there will be other tests to write with similar issues.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I write my test in a way that I calculate decimals separately and In assertion, I concatenate decimals zeros with value.

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)
    );
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!