# Testing contracts

**URL:** <https://forum.openzeppelin.com/t/testing-contracts/9805>\
**Category:** Support\
**Created:** [June 3, 2021, 9:24pm UTC](https://forum.openzeppelin.com/t/testing-contracts/9805 "2021-06-03T21:24:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexS](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alexs/32/6029_2.png) [@AlexS](https://forum.openzeppelin.com/u/AlexS)\
**Post date:** [June 3, 2021, 9:24pm UTC](https://forum.openzeppelin.com/t/testing-contracts/9805/1 "2021-06-03T21:24:59Z")

</div>

I'm writing tests for my smart-contract, mostly everything work as expected. However, there's one thing that does not and I can't understand why (I'm far from being a javascript expert, so please bear with me if I'm doing something stupid)

#### 🔢 Code to reproduce

```auto
// This is a tracker on the default account
let senderTracker = await balance.tracker(defaultSender, "ether");

// later
console.log(`*** Before payment: ${await senderTracker.get() }`);

//call the payWinners function in my contract, it should also send a fee to default sender account
let sharedPot = await forecast.payWinners([accounts[2]]);
let fee = await senderTracker.delta();

console.log(`*** is BN: ${ Web3.utils.isBN(fee) }`);
console.log(`*** After payment: ${ await senderTracker.get() }`);
console.log(`*** Fee: ${ Web3.utils.fromWei(fee, "milliether") }`);

```

And in the console I get:

> Pay Winners  
> \*\*\* Before payment: 99818042788  
> \*\*\* is BN: true  
> \*\*\* After payment: 99818484256  
> 1) should pay the winner
> 
> 6 passing (1s)  
> 1 failing
> 
> 1. Pay Winners  
> should pay the winner:  
> Error: [number-to-bn] while converting number "3fffffff81afa7c" to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.

If the isBN() function returns true, how is it possible that I get this error saying that the value should be BN?

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [June 3, 2021, 11:52pm UTC](https://forum.openzeppelin.com/t/testing-contracts/9805/2 "2021-06-03T23:52:23Z")

</div>

This may be a web3.js bug. As a workaround, you can use `fee.toString()`:

```auto
Web3.utils.fromWei(fee.toString(), "milliether")

```

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [June 4, 2021, 1:18am UTC](https://forum.openzeppelin.com/t/testing-contracts/9805/3 "2021-06-04T01:18:11Z")

</div>

Hi, just make a test, it looks all work well.

```auto
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8545');

let number = web3.utils.toBN("1000000000000000000"); // 1e18
console.log("number is: ", number);
console.log("number is bignumber:", web3.utils.isBN(number));

let readableNumber = web3.utils.fromWei(number, "milliether");
console.log("human readable number is:", readableNumber);

```

result is:

![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/2/2714b7285b0f9782ce4c6d2fdd1cd1f8256c1e8c.png)

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [June 4, 2021, 1:25pm UTC](https://forum.openzeppelin.com/t/testing-contracts/9805/4 "2021-06-04T13:25:27Z")

</div>

This may be happening due to a mismatch of the `BN` version used by Test Helpers and Web3.js.

This shouldn’t be happening. @AlexS If you want to share your repository I can take a look at why that would be happening. It could be caused by a complex interaction between dependencies so it might be hard to reproduce in isolation without the full list of dependencies.

---

<div class="post-metadata">

**Author:** ![AlexS](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/alexs/32/6029_2.png) [@AlexS](https://forum.openzeppelin.com/u/AlexS)\
**Post date:** [June 4, 2021, 7:02pm UTC](https://forum.openzeppelin.com/t/testing-contracts/9805/5 "2021-06-04T19:02:09Z")

</div>

I found what the problem was:

When I defined the tracker, I used “ether” as units.  
`let senderTracker = await balance.tracker(defaultSender, "ether");`

So then I tried to use fromWei(), with a number that was in ether. As soon as I changed the tracker units to “wei”, everything worked as expected.  
Thanks for your help.
