1

I want to be able to tell how many approval event were sent during my test as I cannot tell how many where sent since they are auto-approved by hardhat Running Environment.

1 Answer 1

1

what I did in the end

import ERC20ABI from "@openzeppelin/contracts/build/contracts/ERC20.json";

// [...]

it('perform a complex multi-contract operation', async function () {
  // Load the contract instance using the deployment function
  const {
    myCoolContractDeployed,
    myCoolToken
  } = await loadFixture(deploy);

  await myCoolContractDeployed.write.CoolFunct([BigInt(1)]);

  const publicClient = await hre.viem.getPublicClient();
  const logs = await  publicClient.getContractEvents({
      abi: ERC20ABI.abi,
      address: myCoolToken.address, // optional filter
      eventName: 'Approval', // optional filter, name taken form the ABI (erc20: Transfer, Approval)
  })
  console.log(logs);
  expect(logs.length).to.equal(1);
});
   
1
  • This sucks big time, but it works! However, when I use it with coverage plugin the event list is empty. Any idea? I tried removing address and eventName filter and it is still empty.
    – steven2308
    Commented Feb 19 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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