@@ -301,4 +301,28 @@ mod tests {
301301 assert ! ( loaded. is_some( ) ) ;
302302 assert_eq ! ( loaded. unwrap( ) , info) ;
303303 }
304+
305+ /// Verifies that `ForkDbStateSnapshot::storage_ref` reads from `state_snapshot.storage`
306+ /// when the slot is missing from `local.cache.accounts`. Without this lookup the call
307+ /// would fall through to the backend and return the unrelated remote value.
308+ #[ tokio:: test( flavor = "multi_thread" ) ]
309+ async fn fork_db_state_snapshot_reads_storage_from_snapshot ( ) {
310+ let rpc = foundry_test_utils:: rpc:: next_http_rpc_endpoint ( ) ;
311+ let provider = get_http_provider ( rpc. clone ( ) ) ;
312+ let meta = BlockchainDbMeta :: new ( Default :: default ( ) , rpc) ;
313+ let db = BlockchainDb :: new ( meta, None ) ;
314+ let backend = SharedBackend :: spawn_backend ( Arc :: new ( provider) , db, None ) . await ;
315+
316+ let address = Address :: random ( ) ;
317+ let slot = U256 :: from ( 42u64 ) ;
318+ let expected = U256 :: from ( 0xdeadbeefu64 ) ;
319+
320+ let mut state_snapshot = StateSnapshot :: default ( ) ;
321+ state_snapshot. storage . entry ( address) . or_default ( ) . insert ( slot, expected) ;
322+
323+ let snapshot = ForkDbStateSnapshot { local : CacheDB :: new ( backend) , state_snapshot } ;
324+
325+ let got = DatabaseRef :: storage_ref ( & snapshot, address, slot) . unwrap ( ) ;
326+ assert_eq ! ( got, expected) ;
327+ }
304328}
0 commit comments