Help setting up Bignumbers tests with Test helpers

Hello,

Having a littlebit of trouble with big numbers in OpenZeppelin's test helpers. I would apprecaiate a little bit of help.

I am trying to test 2 big numbers are equal,
My contract is the one from the hardhat tutorial, but I changed solidity's version to 0.8.2 and added test-helpers from Open Zeppelin

const { expect } = require('chai');
const {
    BN,           // Big Number support
    constants,    // Common constants, like the zero address and largest integers
    expectEvent,  // Assertions for emitted events
    expectRevert, // Assertions for transactions that should fail
} = require('@openzeppelin/test-helpers');

(TEstin gbasic equality between Big Numbers)

        it("big numbers should be equal", async function () {
            const total = await hardhatToken.totalSupply();
            console.log('total->', total);
            expect(total).to.be.bignumber.equal(total);
        });

the error is:

  3) Token contract
       Deployment
         big numbers should be equal:
     AssertionError: expected { Object (_hex, _isBigNumber) } to be an instance of BN or string

and

console.log('total->', total);
gives:
total-> BigNumber { _hex: '0x0f4240', _isBigNumber: true }

Solved :slight_smile:
BigNumbers that appear in hardhat with format

{ _hex: '0x0f4240', _isBigNumber: true } 

are from 'ethers.js' BigNumbers Library.

you can check it yourself:

let biggy = ethers.BigNumber.from("42");
console.log('biggy->', biggy);
console.log('biggy->', biggy.toString());

outputs:

biggy-> BigNumber { _hex: '0x2a', _isBigNumber: true }
biggy-> 42

and you can test equality and other things with the methods defined for ethers Big Numbers.

biggy.eq('42');
biggy.add(1);
ethers.BigNumber.isBigNumber(biggy);

check out ethers.js BigNumbers Docs: