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

168
Vistas
Using toString() in Hardhat

function rewardPerToken() public view returns (uint) {
        if (totalSupply == 0) {
            return rewardPerTokenStored;
        }
        return
            rewardPerTokenStored +
            (((block.timestamp - lastUpdateTime) * rewardRate * 1e18) / totalSupply);
    }

      describe("rewardPerToken", () => {
            it("Returns the reward amount of 1 share based off the locked up time", async () => {
                
                await mockWETH.connect(player1).approve(mutuals.address, amount0)
                await achiever.connect(player1).approve(mutuals.address, amount1)
                await mutuals.connect(player1).addLiquidity(amount0, amount1)
                // await moveTime(SECONDS_IN_A_DAY)
                // await moveBlocks(1)
                // let reward = await mutuals.rewardPerToken()
                // let expectedReward = "86"
                // assert.equal(reward.toString(), expectedReward)

                await moveTime(SECONDS_IN_A_YEAR)
                await moveBlocks(1)
                reward = await mutuals.rewardPerToken()
                expectedReward = "31536"
                console.log(ethers.utils.formatEther(reward))
                assert.equal(reward.toString(), expectedReward)
            })
        })
    rewardPerToken
Moving blocks...
Moved forward in time  seconds
Moving blocks...
Moved  blocks
0.000000000000031536
      ✓ Returns the reward amount of 1 share based off the locked up time

I was doing some unit testing and notice that reward.toString() would simply ignore the factor of 1e18. The display result in Remix would include 1e18 though.

Is that how Javacript interpret Big Number? Thanks.

about 4 years ago · Juan Pablo Isaza
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