1- use std:: env;
2-
31use blockifier:: blockifier:: config:: ContractClassManagerConfig ;
42use blockifier:: state:: contract_class_manager:: ContractClassManager ;
53use blockifier:: transaction:: transaction_execution:: Transaction as BlockifierTransaction ;
4+ use rstest:: rstest;
65use starknet_api:: abi:: abi_utils:: { get_storage_var_address, selector_from_name} ;
76use starknet_api:: block:: BlockNumber ;
87use starknet_api:: core:: { ChainId , ContractAddress , Nonce } ;
@@ -12,18 +11,8 @@ use starknet_api::{calldata, felt, invoke_tx_args};
1211
1312use crate :: errors:: VirtualBlockExecutorError ;
1413use crate :: virtual_block_executor:: { RpcVirtualBlockExecutor , VirtualBlockExecutor } ;
15-
16- /// Block number to use for testing (mainnet block with known state).
17- const TEST_BLOCK_NUMBER : u64 = 800000 ;
18-
19- /// STRK token contract address on mainnet.
20- const STRK_TOKEN_ADDRESS : & str =
21- "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" ;
22-
23- /// A known account address on mainnet (Starknet Foundation).
24- /// This is a Cairo 0 OpenZeppelin account, which uses the following calldata format:
25- /// [call_array_len, (to, selector, data_offset, data_len)..., calldata_len, calldata...]
26- const SENDER_ADDRESS : & str = "0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8" ;
14+ use crate :: test_utils:: { rpc_state_reader, SENDER_ADDRESS , STRK_TOKEN_ADDRESS , TEST_BLOCK_NUMBER } ;
15+ use crate :: virtual_block_executor:: VirtualBlockExecutor ;
2716
2817/// Test wrapper for RpcStateReader that overrides execution flags to skip validation.
2918struct TestRpcVirtualBlockExecutor ( RpcVirtualBlockExecutor ) ;
@@ -72,8 +61,8 @@ impl VirtualBlockExecutor for TestRpcVirtualBlockExecutor {
7261/// Since we skip validation and fee charging, we can use dummy values for signature,
7362/// nonce, and resource bounds.
7463fn construct_balance_of_invoke ( ) -> ( Transaction , TransactionHash ) {
75- let strk_token = ContractAddress :: try_from ( felt ! ( STRK_TOKEN_ADDRESS ) ) . unwrap ( ) ;
76- let sender = ContractAddress :: try_from ( felt ! ( SENDER_ADDRESS ) ) . unwrap ( ) ;
64+ let strk_token = ContractAddress :: try_from ( STRK_TOKEN_ADDRESS ) . unwrap ( ) ;
65+ let sender = ContractAddress :: try_from ( SENDER_ADDRESS ) . unwrap ( ) ;
7766
7867 // Calldata for account's __execute__ (Cairo 0 OZ account format):
7968 // [call_array_len, call_array..., calldata_len, calldata...]
@@ -117,22 +106,15 @@ fn construct_balance_of_invoke() -> (Transaction, TransactionHash) {
117106/// ```bash
118107/// NODE_URL=https://your-rpc-node cargo test -p starknet_os_runner -- --ignored
119108/// ```
120- #[ test ]
109+ #[ rstest ]
121110#[ ignore] // Requires RPC access
122- fn test_execute_constructed_balance_of_transaction ( ) {
123- let node_url =
124- env:: var ( "NODE_URL" ) . expect ( "NODE_URL environment variable required for this test" ) ;
125-
111+ fn test_execute_constructed_balance_of_transaction ( rpc_state_reader : RpcStateReader ) {
126112 // Construct a balanceOf transaction (with execution flags set).
127113 let ( tx, tx_hash) = construct_balance_of_invoke ( ) ;
128114
129115 // Create the virtual block executor.
130116 let contract_class_manager = ContractClassManager :: start ( ContractClassManagerConfig :: default ( ) ) ;
131- let executor = TestRpcVirtualBlockExecutor ( RpcVirtualBlockExecutor :: new (
132- node_url,
133- ChainId :: Mainnet ,
134- BlockNumber ( TEST_BLOCK_NUMBER ) ,
135- ) ) ;
117+ let executor = TestRpcVirtualBlockExecutor ( rpc_state_reader) ;
136118
137119 // Execute the transaction.
138120 let result = executor
@@ -170,8 +152,8 @@ fn test_execute_constructed_balance_of_transaction() {
170152
171153 // Verify the specific ERC20 balance storage key was read.
172154 // ERC20 contracts store balances in "ERC20_balances" mapping keyed by address.
173- let strk_token = ContractAddress :: try_from ( felt ! ( STRK_TOKEN_ADDRESS ) ) . unwrap ( ) ;
174- let sender = ContractAddress :: try_from ( felt ! ( SENDER_ADDRESS ) ) . unwrap ( ) ;
155+ let strk_token = ContractAddress :: try_from ( STRK_TOKEN_ADDRESS ) . unwrap ( ) ;
156+ let sender = ContractAddress :: try_from ( SENDER_ADDRESS ) . unwrap ( ) ;
175157 let balance_storage_key = get_storage_var_address ( "ERC20_balances" , & [ * sender. 0 . key ( ) ] ) ;
176158 assert ! (
177159 result. initial_reads. storage. contains_key( & ( strk_token, balance_storage_key) ) ,
0 commit comments