-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misuse of BigNumber instances in tests #204
Comments
Great idea @frangio, thanks! |
I've fixed some of these assertions but we should check the rest of the tests in case I missed other errors. @misteraverin has pointed out that the issue is not only numerical error but also flat out wrong comparisons when two BigNumber objects are compared. |
@frangio Nice fix. But it can be confusing for somebody to see that in one place you compare it as BigNumbers and in another as Strings (equal case). |
The thing with that is that assertion error messages are more useful when they show the expected and actual values. Using I pushed my quick fix to get this going, but like I said before we should probably write an |
includes fix to MultisigWallet test because bigger balances result in floating point errors (see #204)
We're incorporating chai into our tests. For now only crowdsale and TokenTimelock tests are written in this way. The rest will have to be gradually ported. This issue will be addressed by using chai-bignumber as seen in the Crowdsale tests. |
includes fix to MultisigWallet test because bigger balances result in floating point errors (see OpenZeppelin#204)
I think this has been fixed. |
@Aniket-Engg Perhaps! If you've checked would you mind sharing what things you searched for? I found a few more cases of this in |
@frangio I haven't checked it specifically. I supposed that as per the last comment |
@frangio I have gone through almost each test file to introduce changes. Have a look to changelog and let me know if anything has left. |
* signing prefix added * Minor improvement * Successfully tested * Minor improvements * Minor improvements * Revert "Dangling commas are now required. (#1359)" This reverts commit a688977. * updates * fixes #1404 * approve failing test * suggested changes done * ISafeERC20 removed * conflict fixes * added examples * fixes #706 * linting * fixes #204 * file fixing * deep bignumber comparison removed * Update SafeERC20Helper.sol * Update IERC20.sol * Update SafeERC20.sol * Update package-lock.json * Revert "deep bignumber comparison removed" This reverts commit 230b272.
Most of the values obtained interacting with web3 are bignums, for example the
web3.eth.getBalance
return value. In most of the assertions throughout the tests we compare them with JavaScript numbers. This coerces them into numbers and possibly introduces numerical errors. (Because JavaScript's native numbers are floating point, and e.g. 1000000000000000000 is indistinguishable from 1000000000000000001.)I find it unlikely that this is causing false positives, but it should be fixed nevertheless. The numbers we work with in Ethereum can be pretty big and prone to this kind of error. For example the number shown in the previous paragraph is equivalent to 1 ether.
Apart from that, we should probably establish some convention to avoid this problem in the future, and document it in the contribution guidelines. I think it might be good to wrap
assert.equal
, etc., to treat bignums specially.The text was updated successfully, but these errors were encountered: