File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 1
1
use super :: { install, watch:: WatchArgs } ;
2
2
use clap:: Parser ;
3
3
use eyre:: Result ;
4
- use foundry_cli:: { opts:: BuildOpts , utils:: LoadConfig } ;
4
+ use foundry_cli:: { opts:: BuildOpts , utils:: { cache_local_signatures , LoadConfig } } ;
5
5
use foundry_common:: { compile:: ProjectCompiler , shell} ;
6
6
use foundry_compilers:: {
7
7
compilers:: { multi:: MultiCompilerLanguage , Language } ,
@@ -56,6 +56,11 @@ pub struct BuildArgs {
56
56
#[ serde( skip) ]
57
57
pub ignore_eip_3860 : bool ,
58
58
59
+ /// Cache project selectors (enables trace with local contracts functions and events).
60
+ #[ arg( long) ]
61
+ #[ serde( skip) ]
62
+ pub selectors_cache : bool ,
63
+
59
64
#[ command( flatten) ]
60
65
#[ serde( flatten) ]
61
66
pub build : BuildOpts ,
@@ -100,6 +105,10 @@ impl BuildArgs {
100
105
101
106
let output = compiler. compile ( & project) ?;
102
107
108
+ if self . selectors_cache {
109
+ cache_local_signatures ( & output, & Config :: foundry_cache_dir ( ) . unwrap ( ) ) ?
110
+ }
111
+
103
112
if format_json && !self . names && !self . sizes {
104
113
sh_println ! ( "{}" , serde_json:: to_string_pretty( & output. output( ) ) ?) ?;
105
114
}
Original file line number Diff line number Diff line change @@ -3828,3 +3828,41 @@ Encountered a total of 1 failing tests, 0 tests succeeded
3828
3828
3829
3829
"# ] ] ) ;
3830
3830
} ) ;
3831
+
3832
+ // This test is a copy of `error_event_decode_with_cache` in cast/tests/cli/selectors.rs
3833
+ // but it uses `forge build --selectors-cache` to build the project and cache the project selectors.
3834
+ forgetest_init ! ( build_with_selectors_cache, |prj, cmd| {
3835
+ prj. add_source(
3836
+ "LocalProjectContract" ,
3837
+ r#"
3838
+ contract ContractWithCustomError {
3839
+ error AnotherValueTooHigh(uint256, address);
3840
+ event MyUniqueEventWithinLocalProject(uint256 a, address b);
3841
+ }
3842
+ "# ,
3843
+ )
3844
+ . unwrap( ) ;
3845
+ // Build and cache project selectors.
3846
+ cmd. forge_fuse( ) . args( [ "build" , "--selectors-cache" ] ) . assert_success( ) ;
3847
+
3848
+ // Assert cast can decode custom error with local cache.
3849
+ cmd. cast_fuse( )
3850
+ . args( [ "decode-error" , "0x7191bc6200000000000000000000000000000000000000000000000000000000000000650000000000000000000000000000000000000000000000000000000000D0004F" ] )
3851
+ . assert_success( )
3852
+ . stdout_eq( str ![ [ r#"
3853
+ AnotherValueTooHigh(uint256,address)
3854
+ 101
3855
+ 0x0000000000000000000000000000000000D0004F
3856
+
3857
+ "# ] ] ) ;
3858
+ // Assert cast can decode event with local cache.
3859
+ cmd. cast_fuse( )
3860
+ . args( [ "decode-event" , "0xbd3699995dcc867b64dbb607be2c33be38df9134bef1178df13bfb9446e73104000000000000000000000000000000000000000000000000000000000000004e00000000000000000000000000000000000000000000000000000dd00000004e" ] )
3861
+ . assert_success( )
3862
+ . stdout_eq( str ![ [ r#"
3863
+ MyUniqueEventWithinLocalProject(uint256,address)
3864
+ 78
3865
+ 0x00000000000000000000000000000DD00000004e
3866
+
3867
+ "# ] ] ) ;
3868
+ } ) ;
You can’t perform that action at this time.
0 commit comments