To simplify my question, let's say I have a Test.sol with a function that simply output the input:

function testFunc(uint256 value) public pure returns (uint256) {
  return value;

Now I want to test it in truffle

it('uint input test', async () => {
  var test = await Test.deployed()
  res = await test.testFunc.call(0x10000000000000000000000000000001)
  assert.equal(res, 0x10000000000000000000000000000001, 'wrong')

I'm expecting the result should be same as the input, but it fails the assert. Outputs:

BigNumber { s: 1, e: 37, c: [ 2126764793, 25586540000000 ] }

So 0x10000000000000000000000000000001 is changed to 0x1000000000000001d172c5f60ac00000, I assume it's the JavaScript number overflow problem?

It causes problem when I try to test the bit operations, such as checking ERC721 token ID. How can I bypass it?

  • 1
    The problem is javascript numbers do not have enough precision. Either compare them as BigNumers (the objects returned by web3js), or transform them into strings and compare the as such. – Ismael Jul 24 '18 at 3:36

While this may not be an exact answer, it works when using chai promise:



const res = await test.testFunc.call(0x10000000000000000000000000000001)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.