@@ -118,7 +118,7 @@ async fn bitfinity_test_node_forward_eth_get_genesis_balances() {
118118 // Arrange
119119 let _log = init_logs ( ) ;
120120
121- let eth_server = EthImpl :: with_genesis_balances ( vec ! [
121+ let eth_server = EthImpl :: new ( ) . with_genesis_balances ( vec ! [
122122 ( Address :: from_slice( & [ 1u8 ; 20 ] ) , U256 :: from( 10 ) ) ,
123123 ( Address :: from_slice( & [ 2u8 ; 20 ] ) , U256 :: from( 20 ) ) ,
124124 ( Address :: from_slice( & [ 3u8 ; 20 ] ) , U256 :: from( 30 ) ) ,
@@ -156,7 +156,7 @@ async fn bitfinity_test_node_forward_ic_get_genesis_balances() {
156156 // Arrange
157157 let _log = init_logs ( ) ;
158158
159- let eth_server = EthImpl :: with_genesis_balances ( vec ! [
159+ let eth_server = EthImpl :: new ( ) . with_genesis_balances ( vec ! [
160160 ( Address :: from_slice( & [ 1u8 ; 20 ] ) , U256 :: from( 10 ) ) ,
161161 ( Address :: from_slice( & [ 2u8 ; 20 ] ) , U256 :: from( 20 ) ) ,
162162 ( Address :: from_slice( & [ 3u8 ; 20 ] ) , U256 :: from( 30 ) ) ,
@@ -347,7 +347,9 @@ pub async fn mock_eth_server_start(methods: impl Into<Methods>) -> (ServerHandle
347347}
348348
349349/// Starts a local mock server that combines methods from different sources.
350- pub async fn mock_multi_server_start ( methods : impl IntoIterator < Item = Methods > ) -> ( ServerHandle , SocketAddr ) {
350+ pub async fn mock_multi_server_start (
351+ methods : impl IntoIterator < Item = Methods > ,
352+ ) -> ( ServerHandle , SocketAddr ) {
351353 let addr = SocketAddr :: from ( ( [ 127 , 0 , 0 , 1 ] , 0 ) ) ;
352354 let server = Server :: builder ( ) . build ( addr) . await . unwrap ( ) ;
353355
@@ -373,6 +375,7 @@ pub mod eth_server {
373375 use did:: { keccak, BlockConfirmationData , BlockConfirmationResult , BlockNumber , H256 , U64 } ;
374376 use ethereum_json_rpc_client:: CertifiedResult ;
375377 use jsonrpsee:: { core:: RpcResult , proc_macros:: rpc} ;
378+
376379 use reth_trie:: EMPTY_ROOT_HASH ;
377380 use revm_primitives:: { Address , B256 , U256 } ;
378381
@@ -424,7 +427,10 @@ pub mod eth_server {
424427 trait BfEvm {
425428 /// Send block confirmation request.
426429 #[ method( name = "sendConfirmBlock" ) ]
427- async fn confirm_block ( & self , data : BlockConfirmationData ) -> RpcResult < BlockConfirmationResult > ;
430+ async fn confirm_block (
431+ & self ,
432+ data : BlockConfirmationData ,
433+ ) -> RpcResult < BlockConfirmationResult > ;
428434 }
429435
430436 /// Eth server implementation for local testing
@@ -447,6 +453,8 @@ pub mod eth_server {
447453 pub genesis_balances : Vec < ( Address , U256 ) > ,
448454 /// Unsafe blocks count
449455 pub unsafe_blocks_count : u64 ,
456+ /// Custom state root hash
457+ pub custom_state_root : H256 ,
450458 }
451459
452460 impl EthImpl {
@@ -483,6 +491,7 @@ pub mod eth_server {
483491 block_task,
484492 genesis_balances : vec ! [ ] ,
485493 unsafe_blocks_count : 0 ,
494+ custom_state_root : EMPTY_ROOT_HASH . into ( ) ,
486495 }
487496 }
488497
@@ -494,18 +503,21 @@ pub mod eth_server {
494503 }
495504
496505 /// Set the genesis balances
497- pub fn with_genesis_balances ( balances : Vec < ( Address , U256 ) > ) -> Self {
498- let mut instance = Self :: new ( ) ;
499- instance. genesis_balances = balances;
500- instance
506+ pub fn with_genesis_balances ( mut self , balances : Vec < ( Address , U256 ) > ) -> Self {
507+ self . genesis_balances = balances;
508+ self
509+ }
510+
511+ /// Set a custom state root hash
512+ pub fn with_state_root ( mut self , state_root : did:: H256 ) -> Self {
513+ self . custom_state_root = state_root;
514+ self
501515 }
502516
503517 /// Returns an implementation of Bitfinity EVM canister API
504518 pub fn bf_impl ( & mut self , unsafe_blocks_count : u64 ) -> BfEvmImpl {
505519 self . unsafe_blocks_count = unsafe_blocks_count;
506- BfEvmImpl {
507- confirm_until : u64:: MAX ,
508- }
520+ BfEvmImpl { confirm_until : u64:: MAX }
509521 }
510522 }
511523
@@ -550,7 +562,7 @@ pub mod eth_server {
550562 timestamp : did:: U256 :: from ( 1234567890_u64 + block_num) ,
551563 gas_limit : did:: U256 :: from ( 30_000_000_u64 ) ,
552564 base_fee_per_gas : Some ( did:: U256 :: from ( 7_u64 ) ) ,
553- state_root : EMPTY_ROOT_HASH . into ( ) ,
565+ state_root : self . custom_state_root . clone ( ) ,
554566 receipts_root : EMPTY_RECEIPTS . into ( ) ,
555567 transactions_root : EMPTY_TRANSACTIONS . into ( ) ,
556568 parent_hash : if block_num == 0 {
@@ -625,7 +637,10 @@ pub mod eth_server {
625637
626638 #[ async_trait:: async_trait]
627639 impl BfEvmServer for BfEvmImpl {
628- async fn confirm_block ( & self , data : BlockConfirmationData ) -> RpcResult < BlockConfirmationResult > {
640+ async fn confirm_block (
641+ & self ,
642+ data : BlockConfirmationData ,
643+ ) -> RpcResult < BlockConfirmationResult > {
629644 if data. block_number > self . confirm_until {
630645 Ok ( BlockConfirmationResult :: NotConfirmed )
631646 } else {
0 commit comments