@@ -4,7 +4,7 @@ use alloy_consensus::EMPTY_ROOT_HASH;
44use alloy_eips:: BlockNumberOrTag ;
55use alloy_hardforks:: EthereumHardfork ;
66use alloy_network:: { ReceiptResponse , TransactionBuilder } ;
7- use alloy_primitives:: { Address , B256 , hex} ;
7+ use alloy_primitives:: { Address , B256 , U256 , bytes , hex} ;
88use alloy_provider:: Provider ;
99use alloy_rpc_types:: TransactionRequest ;
1010use alloy_sol_types:: SolCall ;
@@ -139,6 +139,30 @@ async fn test_can_use_default_genesis_block_number() {
139139 assert_eq ! ( 0 , provider. get_block( 0 . into( ) ) . await . unwrap( ) . unwrap( ) . header. number) ;
140140}
141141
142+ /// Verify that genesis block number affects both RPC and EVM execution layer.
143+ #[ tokio:: test( flavor = "multi_thread" ) ]
144+ async fn test_number_opcode_reflects_genesis_block_number ( ) {
145+ let genesis_number: u64 = 4242 ;
146+ let ( api, handle) =
147+ spawn ( NodeConfig :: test ( ) . with_genesis_block_number ( Some ( genesis_number) ) ) . await ;
148+ let provider = handle. http_provider ( ) ;
149+
150+ // RPC layer should return configured genesis number
151+ let bn = provider. get_block_number ( ) . await . unwrap ( ) ;
152+ assert_eq ! ( bn, genesis_number) ;
153+
154+ // Deploy bytecode that returns block.number
155+ // 0x43 (NUMBER) 0x5f (PUSH0) 0x52 (MSTORE) 0x60 0x20 (PUSH1 0x20) 0x5f (PUSH0) 0xf3 (RETURN)
156+ let target = Address :: random ( ) ;
157+ api. anvil_set_code ( target, bytes ! ( "435f5260205ff3" ) ) . await . unwrap ( ) ;
158+
159+ // EVM execution should reflect genesis number (+ 1 for pending block)
160+ let tx = alloy_rpc_types:: TransactionRequest :: default ( ) . with_to ( target) ;
161+ let out = provider. call ( tx. into ( ) ) . await . unwrap ( ) ;
162+ let returned = U256 :: from_be_slice ( out. as_ref ( ) ) ;
163+ assert_eq ! ( returned, U256 :: from( genesis_number + 1 ) ) ;
164+ }
165+
142166#[ tokio:: test( flavor = "multi_thread" ) ]
143167async fn test_anvil_recover_signature ( ) {
144168 let ( api, handle) = spawn ( NodeConfig :: test ( ) ) . await ;
0 commit comments