How to detect emit in a receiving contract using hardhat?

Viewed 453

I'm trying to replicate expectEvent.inTransaction() from @openzeppelin/test-helpers for hardhat.

The scenario: token is transfering from owner to receiverContract. I want to check that receiverContract emitted a Received event.

The transaction looks like this and is initiated by the owner.

const tx = await token.transferFrom(
  owner.address, // <- From this wallet
  receiverContract.address, // <- To this contract
  tokenId,
  {
    from: owner.address,
  }
);

This test works showing the token emitted a Transfer event.

await expect(tx)
  .to.emit(this.token, "Transfer")
  .withArgs(owner.address, receiverContract.address, tokenId);

But I want to write something like this...

await expect(tx) // <- Not sure what to put here
  .to.emit(receiverContract, "Received") // <- This may also be off
  .withArgs(token, owner.address, tokenId, null);

Or alternatively, I can look through the receiver's receipt object but I'm not sure how to get that either... normally it's via...

const tx = await token.transferFrom(owner.address, receiverContract.address, tokenId, {from: owner.address});
const receipt = await tx.wait();
console.log("receipt", receipt); // <- This will show an events array 
// which I can check. But how do I get this same receipt object for
// the receiverContract
0 Answers
Related