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)
console.log(res)
console.log(res.toNumber())
console.log(res.toString(16))
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 ] }
2.1267647932558654e+37
1000000000000001d172c5f60ac00000
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?
BigNumers
(the objects returned by web3js), or transform them into strings and compare the as such.