@@ -595,51 +595,81 @@ async fn test_set_storage() {
595595 let mut node = TestNode :: new ( anvil_node_config. clone ( ) , substrate_node_config) . await . unwrap ( ) ;
596596 let alith = Account :: from ( subxt_signer:: eth:: dev:: alith ( ) ) ;
597597
598- let contract_code = get_contract_code ( "SimpleStorage" ) ;
599- let tx_hash = node. deploy_contract ( & contract_code. init , alith. address ( ) , None ) . await ;
600- unwrap_response :: < ( ) > ( node. eth_rpc ( EthRequest :: Mine ( None , None ) ) . await . unwrap ( ) ) . unwrap ( ) ;
601- tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 400 ) ) . await ;
602- let receipt = node. get_transaction_receipt ( tx_hash) . await ;
603- let contract_address = receipt. contract_address . unwrap ( ) ;
604-
605- // Check the default value for slot 0.
606- let result = node
607- . eth_rpc ( EthRequest :: EthGetStorageAt (
608- Address :: from ( ReviveAddress :: new ( contract_address) ) ,
609- U256 :: from ( 0 ) ,
610- None ,
611- ) )
612- . await
598+ // Set storage of a new random account.
599+ {
600+ let random_addr = Address :: random ( ) ;
601+
602+ let stored_value =
603+ node. get_storage_at ( U256 :: from ( 0 ) , ReviveAddress :: from ( random_addr) . inner ( ) ) . await ;
604+ assert_eq ! ( stored_value, 0 ) ;
605+
606+ // Set a new value for the slot 0.
607+ unwrap_response :: < ( ) > (
608+ node. eth_rpc ( EthRequest :: SetStorageAt (
609+ random_addr,
610+ U256 :: from ( 0 ) ,
611+ B256 :: from ( U256 :: from ( 511 ) ) ,
612+ ) )
613+ . await
614+ . unwrap ( ) ,
615+ )
613616 . unwrap ( ) ;
614- let hex_string = unwrap_response :: < String > ( result) . unwrap ( ) ;
615- let hex_value = hex_string. strip_prefix ( "0x" ) . unwrap_or ( & hex_string) ;
616- let stored_value = U256 :: from_str_radix ( hex_value, 16 ) . unwrap ( ) ;
617- assert_eq ! ( stored_value, 0 ) ;
618617
619- // Set a new value for the slot 0.
620-
621- unwrap_response :: < ( ) > (
622- node. eth_rpc ( EthRequest :: SetStorageAt (
623- Address :: from ( ReviveAddress :: new ( contract_address) ) ,
624- U256 :: from ( 0 ) ,
625- B256 :: from ( U256 :: from ( 511 ) ) ,
626- ) )
627- . await
628- . unwrap ( ) ,
629- )
630- . unwrap ( ) ;
618+ // Check that the value was updated
619+ let stored_value =
620+ node. get_storage_at ( U256 :: from ( 0 ) , ReviveAddress :: from ( random_addr) . inner ( ) ) . await ;
621+ assert_eq ! ( stored_value, 511 ) ;
622+ }
623+
624+ // Update the storage of an existing account
625+ {
626+ let contract_code = get_contract_code ( "SimpleStorage" ) ;
627+ let tx_hash = node. deploy_contract ( & contract_code. init , alith. address ( ) , None ) . await ;
628+ unwrap_response :: < ( ) > ( node. eth_rpc ( EthRequest :: Mine ( None , None ) ) . await . unwrap ( ) ) . unwrap ( ) ;
629+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 400 ) ) . await ;
630+ let receipt = node. get_transaction_receipt ( tx_hash) . await ;
631+ let contract_address = receipt. contract_address . unwrap ( ) ;
632+
633+ // Check the default value for slot 0.
634+ let stored_value = node. get_storage_at ( U256 :: from ( 0 ) , contract_address) . await ;
635+ assert_eq ! ( stored_value, 0 ) ;
636+
637+ // Set a new value for the slot 0.
638+ unwrap_response :: < ( ) > (
639+ node. eth_rpc ( EthRequest :: SetStorageAt (
640+ Address :: from ( ReviveAddress :: new ( contract_address) ) ,
641+ U256 :: from ( 0 ) ,
642+ B256 :: from ( U256 :: from ( 511 ) ) ,
643+ ) )
644+ . await
645+ . unwrap ( ) ,
646+ )
647+ . unwrap ( ) ;
631648
632- // Check that the value was updated
633- let result = node
634- . eth_rpc ( EthRequest :: EthGetStorageAt (
635- Address :: from ( ReviveAddress :: new ( contract_address) ) ,
636- U256 :: from ( 0 ) ,
637- None ,
638- ) )
639- . await
649+ // Check that the value was updated
650+ let stored_value = node. get_storage_at ( U256 :: from ( 0 ) , contract_address) . await ;
651+ assert_eq ! ( stored_value, 511 ) ;
652+ }
653+
654+ // Set storage for a EOA account (Alith).
655+ {
656+ let stored_value = node. get_storage_at ( U256 :: from ( 0 ) , alith. address ( ) ) . await ;
657+ assert_eq ! ( stored_value, 0 ) ;
658+
659+ // Set a new value for the slot 0.
660+ unwrap_response :: < ( ) > (
661+ node. eth_rpc ( EthRequest :: SetStorageAt (
662+ Address :: from ( ReviveAddress :: new ( alith. address ( ) ) ) ,
663+ U256 :: from ( 0 ) ,
664+ B256 :: from ( U256 :: from ( 511 ) ) ,
665+ ) )
666+ . await
667+ . unwrap ( ) ,
668+ )
640669 . unwrap ( ) ;
641- let hex_string = unwrap_response :: < String > ( result) . unwrap ( ) ;
642- let hex_value = hex_string. strip_prefix ( "0x" ) . unwrap_or ( & hex_string) ;
643- let stored_value = U256 :: from_str_radix ( hex_value, 16 ) . unwrap ( ) ;
644- assert_eq ! ( stored_value, 511 ) ;
670+
671+ // Check that the value was updated
672+ let stored_value = node. get_storage_at ( U256 :: from ( 0 ) , alith. address ( ) ) . await ;
673+ assert_eq ! ( stored_value, 511 ) ;
674+ }
645675}
0 commit comments