@@ -5,32 +5,29 @@ use alloy_primitives::U256;
55use forge:: { MultiContractRunner , MultiContractRunnerBuilder } ;
66use foundry_cli:: utils:: install_crypto_provider;
77use foundry_compilers:: {
8- Project , ProjectCompileOutput , SolcConfig , Vyper ,
8+ Project , ProjectCompileOutput , SolcConfig ,
99 artifacts:: { EvmVersion , Libraries , Settings } ,
1010 compilers:: multi:: MultiCompiler ,
11- utils:: RuntimeOrHandle ,
1211} ;
1312use foundry_config:: {
1413 Config , FsPermissions , FuzzConfig , FuzzCorpusConfig , FuzzDictionaryConfig , InvariantConfig ,
1514 RpcEndpointUrl , RpcEndpoints , fs_permissions:: PathPermission ,
1615} ;
1716use foundry_evm:: { constants:: CALLER , opts:: EvmOpts } ;
1817use foundry_test_utils:: {
19- fd_lock , init_tracing,
18+ init_tracing,
2019 rpc:: { next_http_archive_rpc_url, next_rpc_endpoint} ,
21- test_debug ,
20+ util :: get_compiled ,
2221} ;
2322use revm:: primitives:: hardfork:: SpecId ;
2423use std:: {
2524 env, fmt,
26- io:: Write ,
2725 path:: { Path , PathBuf } ,
2826 sync:: { Arc , LazyLock } ,
2927} ;
3028
3129pub const RE_PATH_SEPARATOR : & str = "/" ;
3230const TESTDATA : & str = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/../../testdata" ) ;
33- static VYPER : LazyLock < PathBuf > = LazyLock :: new ( || std:: env:: temp_dir ( ) . join ( "vyper" ) ) ;
3431
3532/// Profile for the tests group. Used to configure separate configurations for test runs.
3633pub enum ForgeTestProfile {
@@ -256,84 +253,6 @@ impl ForgeTestData {
256253 }
257254}
258255
259- /// Installs Vyper if it's not already present.
260- pub fn get_vyper ( ) -> Vyper {
261- if let Ok ( vyper) = Vyper :: new ( "vyper" ) {
262- return vyper;
263- }
264- if let Ok ( vyper) = Vyper :: new ( & * VYPER ) {
265- return vyper;
266- }
267- RuntimeOrHandle :: new ( ) . block_on ( async {
268- #[ cfg( target_family = "unix" ) ]
269- use std:: { fs:: Permissions , os:: unix:: fs:: PermissionsExt } ;
270-
271- let suffix = match svm:: platform ( ) {
272- svm:: Platform :: MacOsAarch64 => "darwin" ,
273- svm:: Platform :: LinuxAmd64 => "linux" ,
274- svm:: Platform :: WindowsAmd64 => "windows.exe" ,
275- platform => panic ! (
276- "unsupported platform {platform:?} for installing vyper, \
277- install it manually and add it to $PATH"
278- ) ,
279- } ;
280- let url = format ! ( "https://github.com/vyperlang/vyper/releases/download/v0.4.3/vyper.0.4.3+commit.bff19ea2.{suffix}" ) ;
281-
282- test_debug ! ( "downloading vyper from {url}" ) ;
283- let res = reqwest:: Client :: builder ( ) . build ( ) . unwrap ( ) . get ( url) . send ( ) . await . unwrap ( ) ;
284-
285- assert ! ( res. status( ) . is_success( ) ) ;
286-
287- let bytes = res. bytes ( ) . await . unwrap ( ) ;
288-
289- std:: fs:: write ( & * VYPER , bytes) . unwrap ( ) ;
290-
291- #[ cfg( target_family = "unix" ) ]
292- std:: fs:: set_permissions ( & * VYPER , Permissions :: from_mode ( 0o755 ) ) . unwrap ( ) ;
293-
294- Vyper :: new ( & * VYPER ) . unwrap ( )
295- } )
296- }
297-
298- #[ tracing:: instrument]
299- pub fn get_compiled ( project : & mut Project ) -> ProjectCompileOutput {
300- let lock_file_path = project. sources_path ( ) . join ( ".lock" ) ;
301- // Compile only once per test run.
302- // We need to use a file lock because `cargo-nextest` runs tests in different processes.
303- // This is similar to [`foundry_test_utils::util::initialize`], see its comments for more
304- // details.
305- let mut lock = fd_lock:: new_lock ( & lock_file_path) ;
306- let read = lock. read ( ) . unwrap ( ) ;
307- let out;
308-
309- let mut write = None ;
310- if !project. cache_path ( ) . exists ( ) || std:: fs:: read ( & lock_file_path) . unwrap ( ) != b"1" {
311- drop ( read) ;
312- write = Some ( lock. write ( ) . unwrap ( ) ) ;
313- test_debug ! ( "cache miss for {}" , lock_file_path. display( ) ) ;
314- } else {
315- test_debug ! ( "cache hit for {}" , lock_file_path. display( ) ) ;
316- }
317-
318- if project. compiler . vyper . is_none ( ) {
319- project. compiler . vyper = Some ( get_vyper ( ) ) ;
320- }
321-
322- test_debug ! ( "compiling {}" , lock_file_path. display( ) ) ;
323- out = project. compile ( ) . unwrap ( ) ;
324- test_debug ! ( "compiled {}" , lock_file_path. display( ) ) ;
325-
326- if out. has_compiler_errors ( ) {
327- panic ! ( "Compiled with errors:\n {out}" ) ;
328- }
329-
330- if let Some ( ref mut write) = write {
331- write. write_all ( b"1" ) . unwrap ( ) ;
332- }
333-
334- out
335- }
336-
337256/// Default data for the tests group.
338257pub static TEST_DATA_DEFAULT : LazyLock < ForgeTestData > =
339258 LazyLock :: new ( || ForgeTestData :: new ( ForgeTestProfile :: Default ) ) ;
0 commit comments