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

Julien Klepatch

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.

0 Comments

Leave a Reply

More great articles

ToDo List Ethereum Dapp (Step9) | Toggle Task Done & Keep Frontend Updated

This tutorial is part of the series ToDo List Ethereum Dapp. This is the Step 9. Tutorials already published: (more…)

Read Story

Unit vs integration tests for smart contracts

Before you rush into testing your Solidity smart contracts, it's important to understand the difference between unit tests and integration…

Read Story

Ether wallet – Part II

In the previous episode we started an Ether wallet smart contract, and we can now send Ether to another address.…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]
Arrow-up