Skip to content

Commit

Permalink
test: add test for custom type decoding (#6587)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 12, 2023
1 parent 7d21fe7 commit fa26c84
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ forgetest_init!(exit_code_error_on_fail_fast_with_json, |prj, cmd| {
cmd.assert_err();
});

// <https://github.com/foundry-rs/foundry/issues/6531>
forgetest_init!(repro_6531, |prj, cmd| {
prj.wipe_contracts();

Expand Down Expand Up @@ -401,3 +402,33 @@ contract USDCCallingTest is Test {

cmd.args(["test", "-vvvv"]).unchecked_output().stdout_matches_content(&expected);
});

// <https://github.com/foundry-rs/foundry/issues/6579>
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"),
);
});
25 changes: 25 additions & 0 deletions crates/forge/tests/fixtures/include_custom_types_in_traces.stdout
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fa26c84

Please sign in to comment.