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

166
Views
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
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!