Skip to content

Commit a70c367

Browse files
committed
feat(forge build): cache project selectors by default
Calls `cache_local_signatures` function like the "forge selectors cache" command.
1 parent 65650a6 commit a70c367

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

crates/forge/src/cmd/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use super::{install, watch::WatchArgs};
22
use clap::Parser;
33
use eyre::Result;
4-
use foundry_cli::{opts::BuildOpts, utils::LoadConfig};
4+
use foundry_cli::{
5+
opts::BuildOpts,
6+
utils::{cache_local_signatures, LoadConfig},
7+
};
58
use foundry_common::{compile::ProjectCompiler, shell};
69
use foundry_compilers::{
710
compilers::{multi::MultiCompilerLanguage, Language},
@@ -100,6 +103,9 @@ impl BuildArgs {
100103

101104
let output = compiler.compile(&project)?;
102105

106+
// Cache project selectors.
107+
cache_local_signatures(&output, &Config::foundry_cache_dir().unwrap())?;
108+
103109
if format_json && !self.names && !self.sizes {
104110
sh_println!("{}", serde_json::to_string_pretty(&output.output())?)?;
105111
}

crates/forge/tests/cli/test_cmd.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,3 +3828,41 @@ Encountered a total of 1 failing tests, 0 tests succeeded
38283828
38293829
"#]]);
38303830
});
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` to check that the project selectors are cached by default.
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"]).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+
});

0 commit comments

Comments
 (0)