Testing integers in smart contract with Truffle and bn.js (Big Number)

In Solidity smart contract, you might have to deal with huge numbers, especially when doing financial transfers. Don’t forget that we need to specify Ether transfers in Wei, a fundamental unit equals to 1 * 10 ^ -18 Ether, so very quickly even small financial values can lead to big numbers.

Dealing with big numbers can create all sort of problems, like underflow or overflow. That is why Truffle uses a special library to deal with integers (i.e the bn.js (Big Number) library). However, this can be confusing. In this video, I show you how to use this library in Solidity tests.

Leave a Reply

Your email address will not be published. Required fields are marked *