OpenZeppelin / openzeppelin-test-helpers

Assertion library for Ethereum smart contract testing
https://docs.openzeppelin.com/test-helpers
MIT License
416 stars 132 forks source link

expectEvent Returns Assertion Failed when Evaluating Event with Big Number Type #193

Closed advra closed 1 year ago

advra commented 1 year ago

I am using Open Zeppelin's Test Helpers in my Hardhat testing to check for events emitted using the librarys expectEvent. The code I have has worked fine for other tests. The code would look like the following:

const reciept= await marketplace.listNFT(
  nftContract.address, 
  tokenId, 
  { from: USER, value: ethers.utils.parseUnits("1","ether")}
);
expectEvent(reciept, 'Listed', { 
   owner: TOKEN_OWNER,
   user: USER,
   nftContract: nft.address.toString(),
   tokenId: tokenId.toString(),
   startDateUNIX: new BN(TOMORROW),
   endDateUNIX: new BN(IN_FIVE_DAYS),
   expires: new BN(TODAY_2),
   Fee: new BN(0)
});

The event emits properly and I am able to test and verify other events except for this test case. I am having trouble with Fee. Initially I put 0 I get the following error:

 expected event argument 'Fee' to have value 0 but got 1000000000000000000
      + expected - actual

      -1000000000000000000
      +0

This is fine as I was creating the unit test for the first time and made a typo. Instead of 0 it should be 1000000000000000000 as I expect the fee 1Eth. So I changed the line to correctly reflect the output like below so it would pass:

  Fee: new BN(1000000000000000000)

I reran the test expecting this to pass. Instead I arrive at a new vague error stating assertion failed. Im unsure why its failing. Is this because of an overflow? How can I test the fee? I dont understand why the error is occuring

Error: Assertion failed
      at assert (node_modules/bn.js/lib/bn.js:6:21)
      at BN._initNumber (node_modules/bn.js/lib/bn.js:128:7)
      at BN.init [as _init] (node_modules/bn.js/lib/bn.js:82:19)
      at new BN (node_modules/bn.js/lib/bn.js:39:12)
      at new BNwrapped (node_modules/web3-utils/lib/utils.js:480:16)
      at Context.<anonymous> (test/Marketplace.js:447:14)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
advra commented 1 year ago

Disregard... bignumbers should be strings in the constructor

Fee: new BN('1000000000000000000')

As a request it would be nice if the error message was more informative. (;