@@ -12,6 +12,7 @@ use crate::{
1212
1313use alloy_eips:: BlockNumberOrTag ;
1414use alloy_network:: Ethereum ;
15+ use alloy_node_bindings:: { Anvil , AnvilInstance } ;
1516use alloy_primitives:: Address ;
1617use alloy_provider:: { ext:: AnvilApi , layers:: CacheLayer , Provider , ProviderBuilder } ;
1718use alloy_rpc_client:: RpcClient ;
@@ -68,7 +69,7 @@ pub struct TestFixture {
6869 /// L1 provider for making L1 RPC calls (if connected to real L1).
6970 pub l1_provider : Option < L1Provider > ,
7071 /// Optional Anvil instance for L1 simulation.
71- pub anvil : Option < anvil :: NodeHandle > ,
72+ pub anvil : Option < AnvilInstance > ,
7273 /// The configuration for the nodes.
7374 pub config : ScrollRollupNodeConfig ,
7475 /// Whether this fixture has a remote source node (always the last node).
@@ -354,7 +355,7 @@ impl TestFixture {
354355 ) ;
355356 let client = RpcClient :: builder ( )
356357 . layer ( retry_layer)
357- . http ( anvil. http_endpoint ( ) . parse ( ) . expect ( "failed to parse anvil http endpoint" ) ) ;
358+ . http ( anvil. endpoint ( ) . parse ( ) . expect ( "failed to parse anvil http endpoint" ) ) ;
358359 let cache_layer = CacheLayer :: new ( constants:: L1_PROVIDER_CACHE_MAX_ITEMS ) ;
359360 ProviderBuilder :: new ( ) . layer ( cache_layer) . connect_client ( client)
360361 } )
@@ -749,7 +750,7 @@ impl TestFixtureBuilder {
749750
750751 // Parse endpoint URL once and reuse
751752 let endpoint_url = handle
752- . http_endpoint ( )
753+ . endpoint ( )
753754 . parse :: < reqwest:: Url > ( )
754755 . map_err ( |e| eyre:: eyre!( "Failed to parse Anvil endpoint URL: {}" , e) ) ?;
755756
@@ -837,31 +838,27 @@ impl TestFixtureBuilder {
837838 chain_id : Option < u64 > ,
838839 block_time : Option < u64 > ,
839840 slots_in_an_epoch : u64 ,
840- ) -> eyre:: Result < anvil :: NodeHandle > {
841- let mut config = anvil :: NodeConfig { port : 0 , .. Default :: default ( ) } ;
841+ ) -> eyre:: Result < AnvilInstance > {
842+ let mut anvil = Anvil :: new ( ) . port ( 0u16 ) ;
842843
843844 if let Some ( id) = chain_id {
844- config . chain_id = Some ( id) ;
845+ anvil = anvil . chain_id ( id) ;
845846 }
846847
847- // Configure block time
848848 if let Some ( time) = block_time {
849- config . block_time = Some ( std :: time:: Duration :: from_secs ( time ) ) ;
849+ anvil = anvil . block_time ( time) ;
850850 }
851851
852- // Load state from file if provided
853852 if let Some ( path) = state_path {
854- let state = anvil :: eth :: backend :: db :: SerializableState :: load ( path) . map_err ( |e| {
855- eyre:: eyre!( "Failed to load Anvil state from {} : {:? }" , path. display( ) , e )
856- } ) ? ;
857- tracing:: info!( "Loaded Anvil state from: {}" , path. display( ) ) ;
858- config . init_state = Some ( state) ;
853+ if ! path. exists ( ) {
854+ return Err ( eyre:: eyre!( "Anvil state file does not exist : {}" , path. display( ) ) ) ;
855+ }
856+ tracing:: info!( "Loading Anvil state from: {}" , path. display( ) ) ;
857+ anvil = anvil . arg ( "--load- state" ) . arg ( path ) ;
859858 }
860859
861- config . slots_in_an_epoch = slots_in_an_epoch;
860+ anvil = anvil . arg ( "--slots-in-an-epoch" ) . arg ( slots_in_an_epoch. to_string ( ) ) ;
862861
863- // Spawn Anvil and return the NodeHandle
864- let ( _api, handle) = anvil:: spawn ( config) . await ;
865- Ok ( handle)
862+ anvil. try_spawn ( ) . map_err ( |e| eyre:: eyre!( "Failed to spawn Anvil: {}" , e) )
866863 }
867864}
0 commit comments