Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

354
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda