makoto / blockparty

NO BLOCK NO PARTY
MIT License
164 stars 41 forks source link

Correctly use toNumber() and toString() for BigNumber #51

Closed adamdossa closed 7 years ago

adamdossa commented 7 years ago

Currently test fails on a new testrpc network (so all accounts have 100ETH):

  1) Contract: Conference on setLimitOfParticipants returns only your deposit for multiple invalidations:
     AssertionError: expected false to equal true
      at test/conference.js:68:16
      at process._tickCallback (internal/process/next_tick.js:103:7)

This is because the assert relies on comparing the "raw" BigNumber objects, not the underlying numbers and ">" may behave unexpectedly on the raw object. In this case the two BigNumber objects are:

{ [String: '100000000000000000000'] s: 1, e: 20, c: [ 1000000 ] }
{ [String: '99996975500000000000'] s: 1, e: 19, c: [ 999969, 75500000000000 ] }

and the ">" operator returns false.

I also fixed up the other assert operators for similar edge cases, using toString when comparing against a string, and toNumber when comparing against a number (as in the above failing case).

All tests run to success.

makoto commented 7 years ago

@adamdossa I have been wondering why the test occasionally fails. Thank you so much!!