@@ -13,7 +13,7 @@ use alloy_primitives::{Address, Bytes, U256, address, map::HashMap};
13
13
use eyre:: Result ;
14
14
use foundry_common:: { TestFunctionExt , TestFunctionKind , contracts:: ContractsByAddress } ;
15
15
use foundry_compilers:: utils:: canonicalized;
16
- use foundry_config:: Config ;
16
+ use foundry_config:: { Config , FuzzCorpusConfig } ;
17
17
use foundry_evm:: {
18
18
constants:: CALLER ,
19
19
decode:: RevertDecoder ,
@@ -725,11 +725,18 @@ impl<'a> FunctionRunner<'a> {
725
725
executor
726
726
. inspector_mut ( )
727
727
. collect_edge_coverage ( invariant_config. corpus . collect_edge_coverage ( ) ) ;
728
+ let mut config = invariant_config. clone ( ) ;
729
+ let ( failure_dir, failure_file) = test_paths (
730
+ & mut config. corpus ,
731
+ invariant_config. failure_persist_dir . clone ( ) . unwrap ( ) ,
732
+ self . cr . name ,
733
+ & func. name ,
734
+ ) ;
728
735
729
736
let mut evm = InvariantExecutor :: new (
730
737
executor,
731
738
runner,
732
- invariant_config . clone ( ) ,
739
+ config ,
733
740
identified_contracts,
734
741
& self . cr . mcr . known_contracts ,
735
742
) ;
@@ -739,12 +746,6 @@ impl<'a> FunctionRunner<'a> {
739
746
call_after_invariant,
740
747
abi : & self . cr . contract . abi ,
741
748
} ;
742
-
743
- let ( failure_dir, failure_file) = test_failure_paths (
744
- invariant_config. failure_persist_dir . clone ( ) . unwrap ( ) ,
745
- self . cr . name ,
746
- & invariant_contract. invariant_function . name ,
747
- ) ;
748
749
let show_solidity = invariant_config. show_solidity ;
749
750
750
751
// Try to replay recorded failure if any.
@@ -934,7 +935,13 @@ impl<'a> FunctionRunner<'a> {
934
935
}
935
936
936
937
let runner = self . fuzz_runner ( ) ;
937
- let fuzz_config = self . config . fuzz . clone ( ) ;
938
+ let mut fuzz_config = self . config . fuzz . clone ( ) ;
939
+ let ( failure_dir, failure_file) = test_paths (
940
+ & mut fuzz_config. corpus ,
941
+ fuzz_config. failure_persist_dir . clone ( ) . unwrap ( ) ,
942
+ self . cr . name ,
943
+ & func. name ,
944
+ ) ;
938
945
939
946
let progress = start_fuzz_progress (
940
947
self . cr . progress ,
@@ -944,12 +951,6 @@ impl<'a> FunctionRunner<'a> {
944
951
fuzz_config. runs ,
945
952
) ;
946
953
947
- let ( failure_dir, failure_file) = test_failure_paths (
948
- fuzz_config. failure_persist_dir . clone ( ) . unwrap ( ) ,
949
- self . cr . name ,
950
- & func. name ,
951
- ) ;
952
-
953
954
let mut executor = self . executor . into_owned ( ) ;
954
955
// Enable edge coverage if running with coverage guided fuzzing or with edge coverage
955
956
// metrics (useful for benchmarking the fuzzer).
@@ -1105,14 +1106,18 @@ fn persisted_call_sequence(path: &Path, bytecode: &Bytes) -> Option<Vec<BaseCoun
1105
1106
)
1106
1107
}
1107
1108
1108
- /// Helper functions to return canonicalized test failure paths.
1109
- fn test_failure_paths (
1109
+ /// Helper function to set test corpus dir and to compose persisted failure paths.
1110
+ fn test_paths (
1111
+ corpus_config : & mut FuzzCorpusConfig ,
1110
1112
persist_dir : PathBuf ,
1111
1113
contract_name : & str ,
1112
- invariant_name : & str ,
1114
+ test_name : & str ,
1113
1115
) -> ( PathBuf , PathBuf ) {
1114
- let dir = persist_dir. join ( "failures" ) . join ( contract_name. split ( ':' ) . next_back ( ) . unwrap ( ) ) ;
1115
- let dir = canonicalized ( dir) ;
1116
- let file = canonicalized ( dir. join ( invariant_name) ) ;
1117
- ( dir, file)
1116
+ let contract = contract_name. split ( ':' ) . next_back ( ) . unwrap ( ) ;
1117
+ // Update config with corpus dir for current test.
1118
+ corpus_config. with_test ( contract, test_name) ;
1119
+
1120
+ let failures_dir = canonicalized ( persist_dir. join ( "failures" ) . join ( contract) ) ;
1121
+ let failure_file = canonicalized ( failures_dir. join ( test_name) ) ;
1122
+ ( failures_dir, failure_file)
1118
1123
}
0 commit comments