@@ -20,17 +20,19 @@ use indexmap::IndexMap;
2020use starknet_api:: block:: StarknetVersion ;
2121use starknet_api:: contract_class:: compiled_class_hash:: { HashVersion , HashableCompiledClass } ;
2222use starknet_api:: contract_class:: { ClassInfo , ContractClass , SierraVersion } ;
23- use starknet_api:: core:: { ClassHash , ContractAddress , EthAddress } ;
23+ use starknet_api:: core:: { ClassHash , ContractAddress , EthAddress , Nonce } ;
2424use starknet_api:: executable_transaction:: {
2525 DeclareTransaction ,
26+ DeployAccountTransaction ,
2627 InvokeTransaction ,
2728 TransactionType ,
2829} ;
2930use starknet_api:: test_utils:: declare:: declare_tx;
31+ use starknet_api:: test_utils:: deploy_account:: deploy_account_tx;
3032use starknet_api:: test_utils:: invoke:: invoke_tx;
3133use starknet_api:: transaction:: { L2ToL1Payload , MessageToL1 } ;
3234use starknet_api:: versioned_constants_logic:: VersionedConstantsTrait ;
33- use starknet_api:: { calldata, declare_tx_args, invoke_tx_args} ;
35+ use starknet_api:: { calldata, declare_tx_args, deploy_account_tx_args , invoke_tx_args} ;
3436use starknet_os:: hint_processor:: constants:: BUILTIN_INSTANCE_SIZES ;
3537use starknet_os:: hint_processor:: os_logger:: ResourceFinalizer ;
3638use starknet_os:: test_utils:: { SHA256_BATCH_RESOURCES_LINEAR , SHA256_BLOCK_TO_ROUND } ;
@@ -446,10 +448,29 @@ async fn test_execute_txs_inner_resources() {
446448 let version = StarknetVersion :: LATEST ;
447449 let mut raw_vc: RawVersionedConstants =
448450 serde_json:: from_str ( VersionedConstants :: json_str ( & version) . unwrap ( ) ) . unwrap ( ) ;
449- // TODO(Dori): DeployAccount, L1Handler.
450- const N_TXS : usize = 2 ;
451+ // TODO(Dori): L1Handler.
452+ const N_TXS : usize = 3 ;
451453
452- let ( os_resources_contract_address, _, mut test_builder) = setup_test_builder ( ) . await ;
454+ let ( os_resources_contract_address, deployable_class_hash, mut test_builder) =
455+ setup_test_builder ( ) . await ;
456+
457+ // Prepare the deploy account tx in advance, so we can fund the address before moving to the
458+ // next block (just so the funding tx is not in our measurement block). Use the special contract
459+ // to prevent noise from changing contract address.
460+ let deploy_tx = DeployAccountTransaction :: create (
461+ deploy_account_tx (
462+ deploy_account_tx_args ! {
463+ class_hash: deployable_class_hash,
464+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
465+ constructor_calldata: calldata![ Felt :: ZERO ] ,
466+ } ,
467+ Nonce :: default ( ) ,
468+ ) ,
469+ & test_builder. chain_id ( ) ,
470+ )
471+ . unwrap ( ) ;
472+ test_builder. add_fund_address_tx_with_default_amount ( deploy_tx. contract_address ) ;
473+ test_builder. move_to_next_block ( ) ;
453474
454475 // Invoke.
455476 // Calldata [0, 0, 0, []] → class_hash=0 → __execute__ returns immediately.
@@ -492,6 +513,9 @@ async fn test_execute_txs_inner_resources() {
492513 . unwrap ( ) ;
493514 test_builder. add_cairo1_declare_tx ( tx, data_gas_contract_sierra) ;
494515
516+ // Deploy account (pre-prepared).
517+ test_builder. add_deploy_account_tx ( deploy_tx) ;
518+
495519 // Execute the business logic and extract the business logic resources for each tx.
496520 let test_runner = test_builder. build ( ) . await ;
497521 let business_logic_resources: [ ExecutionResources ; N_TXS ] = test_runner
@@ -524,21 +548,22 @@ async fn test_execute_txs_inner_resources() {
524548 test_output. perform_default_validations ( ) ;
525549
526550 // Fetch the OS resources for each tx.
527- let [ invoke_overhead, declare_overhead] : [ ExecutionResources ; N_TXS ] = test_output
528- . runner_output
529- . txs_trace
530- . iter ( )
531- . rev ( )
532- . take ( N_TXS )
533- . rev ( )
534- . map ( |trace| trace. get_resources ( ) . unwrap ( ) . clone ( ) )
535- . zip ( business_logic_resources)
536- . map ( |( os_resources, business_logic_resources) | {
537- ( & os_resources - & business_logic_resources) . filter_unused_builtins ( )
538- } )
539- . collect :: < Vec < _ > > ( )
540- . try_into ( )
541- . unwrap ( ) ;
551+ let [ invoke_overhead, declare_overhead, deploy_account_overhead] : [ ExecutionResources ; N_TXS ] =
552+ test_output
553+ . runner_output
554+ . txs_trace
555+ . iter ( )
556+ . rev ( )
557+ . take ( N_TXS )
558+ . rev ( )
559+ . map ( |trace| trace. get_resources ( ) . unwrap ( ) . clone ( ) )
560+ . zip ( business_logic_resources)
561+ . map ( |( os_resources, business_logic_resources) | {
562+ ( & os_resources - & business_logic_resources) . filter_unused_builtins ( )
563+ } )
564+ . collect :: < Vec < _ > > ( )
565+ . try_into ( )
566+ . unwrap ( ) ;
542567
543568 // Invoke: variable cost, with scaling of 2.
544569 // TODO(Dori): Compute linear factor cost.
@@ -585,6 +610,35 @@ async fn test_execute_txs_inner_resources() {
585610 . execute_txs_inner
586611 . insert ( TransactionType :: Declare , VariableResourceParams :: Constant ( declare_overhead) ) ;
587612
613+ // Deploy account: variable cost, with scaling of 2.
614+ // TODO(Dori): Compute linear factor cost.
615+ let VariableResourceParams :: WithFactor ( mut deploy_account_resources_params) =
616+ raw_vc. os_resources . execute_txs_inner . get ( & TransactionType :: DeployAccount ) . unwrap ( ) . clone ( )
617+ else {
618+ panic ! (
619+ "Deploy account resources params has unexpected structure: {:?}" ,
620+ raw_vc. os_resources. execute_txs_inner. get( & TransactionType :: DeployAccount ) . unwrap( )
621+ ) ;
622+ } ;
623+ let VariableCallDataFactor :: Scaled ( ref deploy_account_scaling_factor) =
624+ deploy_account_resources_params. calldata_factor
625+ else {
626+ panic ! (
627+ "Deploy account scaling factor has unexpected structure: {:?}" ,
628+ deploy_account_resources_params. calldata_factor
629+ ) ;
630+ } ;
631+ assert_eq ! (
632+ deploy_account_scaling_factor. scaling_factor, 2 ,
633+ "Deploy account scaling factor has unexpected value: {:?}" ,
634+ deploy_account_scaling_factor. scaling_factor
635+ ) ;
636+ deploy_account_resources_params. constant = deploy_account_overhead;
637+ raw_vc. os_resources . execute_txs_inner . insert (
638+ TransactionType :: DeployAccount ,
639+ VariableResourceParams :: WithFactor ( deploy_account_resources_params) ,
640+ ) ;
641+
588642 // Verify computation.
589643 expect_file ! [ VersionedConstants :: json_path( & version) . unwrap( ) ]
590644 . assert_eq ( & raw_vc. to_string_pretty ( ) ) ;
0 commit comments