Skip to content

Misuse of BigNumber instances in tests #204

@frangio

Description

@frangio

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.

  • Establish how to deal with this. Possibly defining some helper functions.
  • Find all coercions to number (implicit or explicit) and fix them.
  • Add a section in CONTRIBUTING.md.

Metadata

Metadata

Assignees

Labels

buggood first issueLow hanging fruit for new contributors to get involved!testsTest suite and helpers.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions