Error in test: Number can only safely store up to 53 bits

Can anyone hellp with this:

  1. Contract: simpletoken
    should assert true:
    Error: Number can only safely store up to 53 bits
1 Like

Hi @crypto_economics,

Can you give some more context on where this is happening? What testing tool are you running, what is in your test etc.

Are you able to share an example contract and test so that I can reproduce?

@abcoathup, thank you for getting back to me! Pls see the code for the SimpleToken and Test below:

// SPDX-License-Identifier: MIT
   pragma solidity ^0.6.0;

   import "../openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

    * @title SimpleToken
    * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
    * Note they can later distribute these tokens as they wish using `transfer` and other
    * `ERC20` functions.
   contract SimpleToken is ERC20 {
       uint8 public constant DECIMALS = 18;
       uint256 public constant INITIAL_SUPPLY = 100000 * (10 ** uint256(DECIMALS));

        * @dev Constructor that gives msg.sender all of existing tokens.
       constructor () public ERC20 ("SimpleToken", "SIM") {
           _mint(msg.sender, INITIAL_SUPPLY);


    var Token = artifacts.require("SimpleToken");contract('simpletoken', function(accounts) {
      it("should assert true", function() {
        var token;
        return Token.deployed().then(function(instance){
         token = instance;
         assert.equal(result.toNumber(), 1000000, 'total supply is wrong');
1 Like

Maybe you can have a try to call token.totalSupply().call(), besides this, you can have a check about this file:

1 Like

Hi @crypto_economics,

Looking at your test you are trying to convert a BigNumber object to a JavaScript number which is too large for a JavaScript number hence why you get the error Number can only safely store up to 53 bits.

OpenZeppelin Test Helpers include bn.js that we can use in our tests.

I have created an example: Simple ERC20 token example which includes a check on the totalSupply (which is uint256 in Solidity).

1 Like