matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment
Apache License 2.0
299 stars 130 forks source link

vm.recordLogs does not record events emitted by calls #515

Closed spengrah closed 2 months ago

spengrah commented 3 months ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.0.2 (5a8f447 2024-08-12T00:23:55.353531000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

I am trying to use foundry's vm.recordLogs and vm.getRecordedLogs feature to get the logs emitted by a call within one of my tests. However, no logs are recorded. I can get it to record a log that I manually emit, but not logs emitted by a call.

Specifically, these work


contract LogTest {
  event Event();

  function doEvent() public {
    emit Event();
  }

  function test_A() public {
    vm.recordLogs();
    emit Event();
    Vm.Log[] memory logs = vm.getRecordedLogs();
    assertEq(logs.length, 1); // true
  }

  function test_B() public {
    vm.recordLogs();
    doEvent();
    Vm.Log[] memory logs = vm.getRecordedLogs();
    assertEq(logs.length, 1); // true
  }
}

But this doesn't

import "DeployedContract.sol";

contract LogTest2 {

// DeployedContract.doThingscalls other contracts resulting in a handful of emitted events total
DeployedContract deployedContract = 0xabcd...1234;

  function test_C() public {
    vm.recordLogs();
    deployedContract.doThings();
    Vm.Log[] memory logs = vm.getRecordedLogs();
    assertGt(logs.length, 0); // false
  }
}