Suppose I have:
function func(uint256 x) external {
...
}
I would like to test this function via web3.js, with the maximum possible value of x.
In a Truffle test, I have noticed that I can simply call func(-1).
My Truffle version is 4.1.15, which relies on Web3 v0.20.6.
I'm not sure who's in charge of this conversion (whether it's Truffle or Web3), but I would like to know if this a guaranteed behavior as far as web3.js states.
In the documentation of web3.js v1.x there is web3.utils.toTwosComplement(number), which implies to me that such conversion is not guaranteed (but must be performed explicitly using this function).
However, my Truffle version relies on the previous Web3 version, so I am unable to know for sure.
Any idea?
Side note: I know I can use web3.toBigNumber(2).pow(256).minus(1), but I'd rather use the -1 option, which is cleaner IMO.
SafeMathhas nothing to do with my use-case, as I'm merely sending the value from the off-chain to the on-chain (whileSafeMathis designated for detecting overflows and underflows as a result of an arithmetic operation executed in the on-chain). – goodvibration Feb 20 '19 at 21:34