@@ -13,7 +13,7 @@ use cairo_vm::types::builtin_name::BuiltinName;
1313use expect_test:: expect;
1414use rstest:: rstest;
1515use starknet_api:: abi:: abi_utils:: { get_storage_var_address, selector_from_name} ;
16- use starknet_api:: block:: { BlockInfo , BlockNumber , BlockTimestamp } ;
16+ use starknet_api:: block:: { BlockInfo , BlockNumber , BlockTimestamp , GasPrice } ;
1717use starknet_api:: contract_class:: compiled_class_hash:: { HashVersion , HashableCompiledClass } ;
1818use starknet_api:: contract_class:: { ClassInfo , ContractClass } ;
1919use starknet_api:: core:: {
@@ -2153,3 +2153,117 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) {
21532153 test_manager. execute_test_with_default_block_contexts ( & TestParameters :: default ( ) ) . await ;
21542154 test_output. perform_default_validations ( ) ;
21552155}
2156+
2157+ #[ rstest]
2158+ #[ tokio:: test]
2159+ async fn test_initial_sierra_gas ( ) {
2160+ let account_contract = FeatureContract :: Experimental ;
2161+ let ( mut test_manager, mut nonce_manager, [ account_address] ) =
2162+ TestManager :: < DictStateReader > :: new_with_default_initial_state ( [ (
2163+ account_contract,
2164+ calldata ! [ ] ,
2165+ ) ] )
2166+ . await ;
2167+
2168+ // Fund the account.
2169+ let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS . max_possible_fee ( Tip ( 0 ) ) . 0 ;
2170+ let fund_tx_args = invoke_tx_args ! {
2171+ sender_address: * FUNDED_ACCOUNT_ADDRESS ,
2172+ nonce: nonce_manager. next( * FUNDED_ACCOUNT_ADDRESS ) ,
2173+ calldata: create_calldata(
2174+ * STRK_FEE_TOKEN_ADDRESS ,
2175+ "transfer" ,
2176+ & [ * * account_address, Felt :: from( transfer_amount) , Felt :: ZERO ]
2177+ ) ,
2178+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
2179+ } ;
2180+ test_manager. add_invoke_tx_from_args ( fund_tx_args, & CHAIN_ID_FOR_TESTS , None ) ;
2181+
2182+ // Test invoke gas limits.
2183+ let os_constants = & VersionedConstants :: latest_constants ( ) . os_constants ;
2184+ let validate_max_sierra_gas = os_constants. validate_max_sierra_gas . 0 ;
2185+ let execute_max_sierra_gas = os_constants. execute_max_sierra_gas . 0 ;
2186+ for l2_gas_amount in [
2187+ validate_max_sierra_gas - 123456 ,
2188+ validate_max_sierra_gas + 123456 ,
2189+ 10 * execute_max_sierra_gas,
2190+ ] {
2191+ // Set up gas parameters.
2192+ let resource_bounds = match * NON_TRIVIAL_RESOURCE_BOUNDS {
2193+ ValidResourceBounds :: AllResources ( all_resource_bounds) => {
2194+ ValidResourceBounds :: AllResources ( AllResourceBounds {
2195+ l2_gas : ResourceBounds {
2196+ max_amount : GasAmount ( l2_gas_amount) ,
2197+ max_price_per_unit : GasPrice ( 1 << 40 ) ,
2198+ } ,
2199+ ..all_resource_bounds
2200+ } )
2201+ }
2202+ _ => panic ! ( "Resource bounds are not all resources" ) ,
2203+ } ;
2204+ let expected_validate_gas_upper_limit = u64:: min ( l2_gas_amount, validate_max_sierra_gas) ;
2205+ let expected_validate_gas_lower_limit = expected_validate_gas_upper_limit - 50000 ;
2206+ let expected_execute_gas_upper_limit =
2207+ u64:: min ( l2_gas_amount - 50000 , execute_max_sierra_gas) ;
2208+ let expected_execute_gas_lower_limit = expected_execute_gas_upper_limit - 150000 ;
2209+
2210+ // Invoke verify_gas_limits.
2211+ let invoke_args = invoke_tx_args ! {
2212+ sender_address: account_address,
2213+ nonce: nonce_manager. next( account_address) ,
2214+ calldata: create_calldata(
2215+ account_address,
2216+ "verify_gas_limits" ,
2217+ & [
2218+ Felt :: from( expected_validate_gas_lower_limit) ,
2219+ Felt :: from( expected_validate_gas_upper_limit) ,
2220+ Felt :: from( expected_execute_gas_lower_limit) ,
2221+ Felt :: from( expected_execute_gas_upper_limit)
2222+ ]
2223+ ) ,
2224+ resource_bounds: resource_bounds,
2225+ } ;
2226+ test_manager. add_invoke_tx_from_args ( invoke_args, & CHAIN_ID_FOR_TESTS , None ) ;
2227+ }
2228+
2229+ // L1 handler bounds test.
2230+ let expected_l1_handler_gas_upper_bound = os_constants. l1_handler_max_amount_bounds . l2_gas . 0 ;
2231+ let expected_l1_handler_gas_lower_bound = expected_l1_handler_gas_upper_bound - 10001 ;
2232+ let from_address = Felt :: from_hex_unchecked ( "0xDEADACC" ) ;
2233+ let selector = selector_from_name ( "verify_gas_limits_l1_handler" ) ;
2234+ let calldata = vec ! [
2235+ Felt :: from( expected_l1_handler_gas_lower_bound) ,
2236+ Felt :: from( expected_l1_handler_gas_upper_bound) ,
2237+ ] ;
2238+ let l1_handler_tx = ExecutableL1HandlerTransaction :: create (
2239+ L1HandlerTransaction {
2240+ version : L1HandlerTransaction :: VERSION ,
2241+ nonce : Nonce :: default ( ) ,
2242+ contract_address : account_address,
2243+ entry_point_selector : selector,
2244+ calldata : Calldata ( Arc :: new ( [ vec ! [ from_address] , calldata. clone ( ) ] . concat ( ) ) ) ,
2245+ } ,
2246+ & CHAIN_ID_FOR_TESTS ,
2247+ Fee ( 1_000_000 ) ,
2248+ )
2249+ . unwrap ( ) ;
2250+ test_manager. add_l1_handler_tx ( l1_handler_tx. clone ( ) , None ) ;
2251+ let messages_to_l2 = vec ! [ MessageToL2 {
2252+ from_address: EthAddress :: try_from( from_address) . unwrap( ) ,
2253+ to_address: account_address,
2254+ nonce: Nonce :: default ( ) ,
2255+ selector,
2256+ payload: L1ToL2Payload ( calldata) ,
2257+ } ] ;
2258+
2259+ // Run test.
2260+ let test_output = test_manager
2261+ . execute_test_with_default_block_contexts ( & TestParameters {
2262+ use_kzg_da : true ,
2263+ messages_to_l2,
2264+ ..Default :: default ( )
2265+ } )
2266+ . await ;
2267+
2268+ test_output. perform_default_validations ( ) ;
2269+ }
0 commit comments