-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
misleading error message on failed expectEmit cheat code #908
Comments
Seems there may have been an |
Damn the FWIW this is probably a regression as @mds1 pointed out. The error message is for when you call |
I can't reproduce this anymore: // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
contract A {
event Test(uint256 a);
function b() external {
emit Test(1);
}
}
contract ContractTest is Test {
event Test(uint256 a);
function testExample() public {
A a = new A();
vm.expectEmit(false, true, false, true);
emit Test(2);
a.b();
}
}
Because of this I am going to close this issue: improved error messages for |
hi @onbjerg, error: $ forge test --mt testEmitEventTrycatch -vvvvvvv
[⠰] Compiling...
[⠃] Compiling 2 files with 0.8.20
[⠒] Solc 0.8.20 finished in 1.48s
Compiler run successful!
Running 1 test for test/TestTryCatch.t.sol:TryCatchTest
[FAIL. Reason: Expected an emit, but the call reverted instead. Ensure you're testing the happy path when using the `expectEmit` cheatcode.] testEmitEventTrycatch() (gas: 11742)
Traces:
[273525] TryCatchTest::setUp()
├─ [218863] → new TryCatchEg@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← 1093 bytes of code
└─ ← ()
[11742] TryCatchTest::testEmitEventTrycatch()
├─ [0] VM::expectEmit()
│ └─ ← ()
├─ [3701] TryCatchEg::LetsTryCatch(21, 4234)
│ ├─ [411] TryCatchEg::Add(21, 4234) [staticcall]
│ │ └─ ← 4255
│ ├─ emit ShowResult(result: 4255)
│ ├─ emit Log(message: Add successful)
│ └─ ← ()
└─ ← "Log != expected log"
Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 610.74µs
Ran 1 test suites: 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/TestTryCatch.t.sol:TryCatchTest
[FAIL. Reason: Expected an emit, but the call reverted instead. Ensure you're testing the happy path when using the `expectEmit` cheatcode.] testEmitEventTrycatch() (gas: 11742)
Encountered a total of 1 failing tests, 0 tests succeeded my test script: function testEmitEventTrycatch() public {
vm.expectEmit();
egoftrycatch.LetsTryCatch(21, 4234);
}
The function I am testing: function LetsTryCatch(uint256 firstDigit, uint256 secondDigit) external {
try this.Add(firstDigit, secondDigit) returns (uint256 result) {
emit ShowResult(result);
emit Log("Add successful");
} catch Error(string memory errorMessage) {
emit Log(errorMessage);
// revert(errorMessage);
} catch (bytes memory errorData) {
emit Log(string(errorData));
// revert(string(errorData));
}
} Thanks in advance |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.1.0 (05eb664 2022-03-07T00:08:24.917561+00:00)
What command(s) is the bug in?
forge test
Operating System
macOS (M1)
Describe the bug
After invoking the
expectEmit
cheatcode, if any of the topics or data in the log does not match what was expected, it gives a misleading fail message,FAIL. Reason: Expected an emit, but no logs were emitted afterward
In my example, I had coded:
but I made a mistake, the 3rd parameter shouldve been user2.
I got this:
It would be nice to have a better message - at least something like "topics or data did not match what was expected" or even better if we could show exactly what was wrong, e.g. "Expected 0xabcbcbcbcb for topic2 but got 0x010191911991"
The text was updated successfully, but these errors were encountered: