-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
Cmd-forge-testCommand: forge testCommand: forge testT-bugType: bugType: bugT-to-investigateType: to investigateType: to investigate
Milestone
Description
Component
Forge
Have you ensured that all of these are up to date?
- Foundry
- Foundryup
What version of Foundry are you on?
forge 0.2.0 (df49ddd 2023-12-21T00:22:15.620581000Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Intel)
Describe the bug
-
Run
forge init -
Modify these files accordingly:
Counter.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Counter {
event TestEvent(uint n);
constructor() {
emit TestEvent(1);
}
function f() external {
emit TestEvent(2);
}
}Counter.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console2} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";
contract CounterTest is Test {
Counter public counter;
event TestEvent(uint n);
function setUp() public {
counter = new Counter();
}
function test_Bug() public {
// part1
vm.expectEmit();
emit TestEvent(1);
new Counter();
// part2
vm.expectEmit();
emit TestEvent(2);
counter.f();
}
}- Run
forge test -vvv
Expected behavior: test passed
Actual behavior: test failed
Traces:
[77239] CounterTest::test_Bug()
├─ [0] VM::expectEmit()
│ └─ ← ()
├─ emit TestEvent(n: 1)
├─ [33338] → new Counter@0x2e234DAe75C793f67A35089C9d99245E1C58470b
│ ├─ emit TestEvent(n: 1)
│ └─ ← 161 bytes of code
├─ [0] VM::expectEmit()
│ └─ ← ()
├─ emit TestEvent(n: 2)
├─ [1179] Counter::f()
│ ├─ emit TestEvent(n: 2)
│ └─ ← ()
└─ ← log != expected log
Note that when you comment out the three lines of code in part1, or the three lines of code in part2, the test can pass normally.
Metadata
Metadata
Assignees
Labels
Cmd-forge-testCommand: forge testCommand: forge testT-bugType: bugType: bugT-to-investigateType: to investigateType: to investigate
Type
Projects
Status
Completed