From 01d6315bb49e798730bda4a51cfb5baa902609f3 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 12 Dec 2023 17:17:08 +0100 Subject: [PATCH] test: add test for custom type decoding --- crates/forge/tests/cli/test_cmd.rs | 31 +++++++++++++++++++ .../include_custom_types_in_traces.stdout | 25 +++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 crates/forge/tests/fixtures/include_custom_types_in_traces.stdout diff --git a/crates/forge/tests/cli/test_cmd.rs b/crates/forge/tests/cli/test_cmd.rs index e7ed7747b1c8..25a30a1fd040 100644 --- a/crates/forge/tests/cli/test_cmd.rs +++ b/crates/forge/tests/cli/test_cmd.rs @@ -368,6 +368,7 @@ forgetest_init!(exit_code_error_on_fail_fast_with_json, |prj, cmd| { cmd.assert_err(); }); +// forgetest_init!(repro_6531, |prj, cmd| { prj.wipe_contracts(); @@ -401,3 +402,33 @@ contract USDCCallingTest is Test { cmd.args(["test", "-vvvv"]).unchecked_output().stdout_matches_content(&expected); }); + +// +forgetest_init!(include_custom_types_in_traces, |prj, cmd| { + prj.wipe_contracts(); + + prj.add_test( + "Contract.t.sol", + r#" +import {Test} from "forge-std/Test.sol"; + +error PoolNotInitialized(); +event MyEvent(uint256 a); + +contract CustomTypesTest is Test { + function testErr() public pure { + revert PoolNotInitialized(); + } + function testEvent() public { + emit MyEvent(100); + } +} + "#, + ) + .unwrap(); + + cmd.args(["test", "-vvvv"]).unchecked_output().stdout_matches_path( + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("tests/fixtures/include_custom_types_in_traces.stdout"), + ); +}); diff --git a/crates/forge/tests/fixtures/include_custom_types_in_traces.stdout b/crates/forge/tests/fixtures/include_custom_types_in_traces.stdout new file mode 100644 index 000000000000..be5d7706debb --- /dev/null +++ b/crates/forge/tests/fixtures/include_custom_types_in_traces.stdout @@ -0,0 +1,25 @@ +Compiling 1 files with 0.8.23 +Solc 0.8.23 finished in 798.51ms +Compiler run successful! + +Running 2 tests for test/Contract.t.sol:CustomTypesTest +[FAIL. Reason: PoolNotInitialized()] testErr() (gas: 231) +Traces: + [231] CustomTypesTest::testErr() + └─ ← PoolNotInitialized() + +[PASS] testEvent() (gas: 1312) +Traces: + [1312] CustomTypesTest::testEvent() + ├─ emit MyEvent(a: 100) + └─ ← () + +Test result: FAILED. 1 passed; 1 failed; 0 skipped; finished in 3.88ms + +Ran 1 test suites: 1 tests passed, 1 failed, 0 skipped (2 total tests) + +Failing tests: +Encountered 1 failing test in test/Contract.t.sol:CustomTypesTest +[FAIL. Reason: PoolNotInitialized()] testErr() (gas: 231) + +Encountered a total of 1 failing tests, 1 tests succeeded