Unable to Use expectEvent

How do I pull out events to assert certain things happened? I’m currently sending a tx, awaiting the response, then using openzeppelin’s expectEvent to figure out that my event got emitted correctly. Conceptually, this is a very simple task, however the SDK doesn’t seem to want to play nice with what I am giving it.

My setup is I’m running hardhat with openzeppelin/test-helpers.

receipt = await this.cosmosBridge.connect(userFour).newProphecyClaim(

Then, I’m asserting I am getting proper event like so:

expectEvent(receipt, 'LogNewProphecyClaim');

And that expectEvent function gives me the following error:

     Error: Unknown transaction receipt object
      at expectEvent (node_modules/@openzeppelin/test-helpers/src/expectEvent.js:31:11)
      at Context.<anonymous> (test/testHardhat.js:208:7)

Any help would be appreciated.

When I send a tx, this is the response from hardhat local network:

   '0xb9a3942762e7dee18fcc314c6ae71e4db310e0688baced7df65f77a038f9051f',
  type: null,
  accessList: null,
  blockHash:
   '0xcff92bc6e484a45a962433006db90f09116ba0ada6f5f8b60e7eee28a8c915da',
  blockNumber: 40,
  transactionIndex: 0,
  confirmations: 1,
  from: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
  gasPrice: BigNumber { _hex: '0x01dcd65000', _isBigNumber: true },
  gasLimit: BigNumber { _hex: '0x8223b8', _isBigNumber: true },
  to: '0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  nonce: 11,
  data:
   '0x9fc9ec9d000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000100000000000000000000000014dc79964da2c08b23698b3d3cc7ca32193d99550000000000000000000000007a2088a1bfc9d81c55368ae168c2c02570cb814f0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000002a736966316e78363530733871397732386632673374397a74787967343875676c64707475777a706163650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000045445535400000000000000000000000000000000000000000000000000000000',
  r:
   '0x9b75d3d16d28a9ae41dff0ed0d477a1be8b73a7b437e2da4f21bcfe6f05b589b',
  s:
   '0x44c9462ad34859ebe4f1cc0f0e5acf8c2dad1851aa49912af46040dda306e8fc',
  v: 62710,
  creates: null,
  chainId: 31337,
  wait: [Function] }

Even after I await for the wait function, I get logs out, but when I pass that new object to the expect event function, I’m still not getting any luck.

1 Like

Hi @elliot,

I assume you are using the Truffle plugin with Hardhat as OpenZeppelin Test Helpers is web3.js based:

OpenZeppelin Test Helpers is web3.js based, thus Hardhat users should use the Truffle plugin for compatibility, or use Waffle with ethers.js, which offers similar functionality.
From: https://docs.openzeppelin.com/learn/writing-automated-tests#performing-complex-assertions

If so, I suggest trying with a simple example such as: https://docs.openzeppelin.com/learn/writing-automated-tests#performing-complex-assertions

I am not using the truffle plugin, just hardhat and ethers. I have imported web3, but that is not where we get the web3 provider from, that is provided by hardhat.

That document on performing complex assertions doesn’t help me as I’m still unsure how to get around this error.

1 Like

Hi @elliot,

If you want to use OpenZeppelin Test Helpers then you need to use the Truffle plugin, importing web3 isn’t sufficient. Alternatively you can use Waffle with ethers.js.