1

Here is what i've done: I have create a project this way:

truffle unbox react
npm install @openzeppelin/test-helpers

I have keep SimpleStorage.sol sample contract and here is my test file:

const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const {expect} = require("chai");

const SimpleStorage = artifacts.require("./SimpleStorage.sol");

contract("SimpleStorage", accounts => {

  it("my test", async () => {
    const simpleStorageInstance = await SimpleStorage.deployed();

    await simpleStorageInstance.set(2, { from: accounts[0] });
    const ret = await simpleStorageInstance.get();
    expect(ret).to.equal(new BN(2));
  });
});

I get this error:

AssertionError: expected <BN: 2> to equal <BN: 2>

I do not understand ! <BN: 2> is the same thing than <BN: 2> !

Which does this assertion fails ?

Thanks

0

It might be comparing the references of the objects instead of the data inside them. Try using the big comparisions of bignumbers the chai-bn package provides.

Heres an example from the package page

const actual = new BN('100000000000000000').plus(new BN('1'));
const expected = '100000000000000001';

actual.should.be.a.bignumber.that.equals(expected);

Here is a link to the chai plugin https://www.chaijs.com/plugins/chai-bn/

2
  • Thanks but what is the goal of ".be", ".a", ".that". Is it just for lisibility, this functions does nothing ? – Bob5421 Jan 31 at 11:53
  • yeah I think its just for lisibility, some kind of syntax trick theyre pulling to make it feel like youre reading the test in english. Im not really sure how it works, but I have something similar in my test suite and if you type it, it work so ¯_(ツ)_/¯ – Bruce Darcy Jan 31 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.