In the Truffle v5 Release Notes, the breaking changes section says:
Numeric return values are now BN objects instead of the previously default BigNumber.js. These two projects use significantly different API semantics, so you may want to review those.
Truffle provides a compatibility mode for projects unable to make the switch wholesale. Set numberFormat to "BigNumber", "String", or "BN" to choose. See example number format override:
// Choices are: `["BigNumber", "BN", "String"].
const Example = artifacts.require("Example");
Example.numberFormat = "BigNumber";
I had previously developed a test suite that includes someBigNumber.plus(1) and similar lines.
Upgrading to Truffle 5 and running truffle test, the tests failed with messages like TypeError: someBigNumber.plus is not a function.
Adding the MyContract.numberFormat = "BigNumber"; line after ...require("MyContract"); per the example, I now get the error:
TypeError: BigNumber is not a constructor
at _convertNumber (C:\Users\me\AppData\Local\node\node_modules\truffle\build\webpack:\packages\truffle-contract\lib\reformat.js:17:1)
at abiSegment.forEach (C:\Users\me\AppData\Local\node\node_modules\truffle\build\webpack:\packages\truffle-contract\lib\reformat.js:80:1)
at Array.forEach (<anonymous>)
at Function.numbers (C:\Users\me\AppData\Local\node\node_modules\truffle\build\webpack:\packages\truffle-contract\lib\reformat.js:47:1)
at Promise (C:\Users\me\AppData\Local\node\node_modules\truffle\build\webpack:\packages\truffle-contract\lib\execute.js:125:1)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
Develop tests using BigNumber.
Attempt to use the documented compatibility mode to not have to change over everything in the test suite immediately to Truffle v5.
Limit tests to one file and include the .numberFormat line as documented in release notes/above.
Encounter errors as shown above.
No errors. With the adaptation, the test suite runs as before.
truffle version): 5.0.0node --version): 9.3.0npm --version): 6.5.0npm show bignumber version): 1.1.0 (this is the latest, with the same version being listed after npm i bignumber runs successfully). Same issue here
Same here
OS: linux
Truffle v5.0.1
Node verison v10.15.0
Npm version 6.4.1
I think there is some issue with bignumber.js bundling with webpack https://github.com/MikeMcl/bignumber.js/issues/166.
I will try and have a fix for this soon.
A fix was merged in https://github.com/trufflesuite/truffle/pull/1631.
Truffle v5.0.2 should have fixed this problem, I am going to close this issue. Please re-open if you are still having problems with this!