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:

  type: null,
  accessList: null,
  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,
  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.