@@ -21,17 +21,19 @@ use indexmap::IndexMap;
2121use starknet_api:: block:: StarknetVersion ;
2222use starknet_api:: contract_class:: compiled_class_hash:: HashVersion ;
2323use starknet_api:: contract_class:: SierraVersion ;
24- use starknet_api:: core:: { ContractAddress , EthAddress } ;
24+ use starknet_api:: core:: { ContractAddress , EthAddress , Nonce } ;
2525use starknet_api:: executable_transaction:: {
2626 DeclareTransaction ,
27+ DeployAccountTransaction ,
2728 InvokeTransaction ,
2829 TransactionType ,
2930} ;
3031use starknet_api:: test_utils:: declare:: declare_tx;
32+ use starknet_api:: test_utils:: deploy_account:: deploy_account_tx;
3133use starknet_api:: test_utils:: invoke:: invoke_tx;
3234use starknet_api:: transaction:: { L2ToL1Payload , MessageToL1 } ;
3335use starknet_api:: versioned_constants_logic:: VersionedConstantsTrait ;
34- use starknet_api:: { calldata, declare_tx_args, invoke_tx_args} ;
36+ use starknet_api:: { calldata, declare_tx_args, deploy_account_tx_args , invoke_tx_args} ;
3537use starknet_os:: hint_processor:: constants:: BUILTIN_INSTANCE_SIZES ;
3638use starknet_os:: hint_processor:: os_logger:: ResourceFinalizer ;
3739use starknet_os:: test_utils:: { SHA256_BATCH_RESOURCES_LINEAR , SHA256_BLOCK_TO_ROUND } ;
@@ -400,11 +402,31 @@ async fn test_execute_txs_inner_resources() {
400402 let version = StarknetVersion :: LATEST ;
401403 let mut raw_vc: RawVersionedConstants =
402404 serde_json:: from_str ( VersionedConstants :: json_str ( & version) . unwrap ( ) ) . unwrap ( ) ;
403- // TODO(Dori): DeployAccount, L1Handler.
404- const N_TXS : usize = 2 ;
405+ // TODO(Dori): L1Handler.
406+ const N_TXS : usize = 3 ;
405407
406408 let ( os_resources_contract_address, mut test_builder) = setup_test_builder ( ) . await ;
407409
410+ // Prepare the deploy account tx in advance, so we can fund the address before moving to the
411+ // next block (just so the funding tx is not in our measurement block). The OS resources
412+ // contract is also an account contract, so we can use it to deploy an account.
413+ let os_resources_contract = FeatureContract :: OsResourcesTest ( RunnableCairo1 :: Casm ) ;
414+ let class_hash = get_class_hash_of_feature_contract ( os_resources_contract) ;
415+ let deploy_tx = DeployAccountTransaction :: create (
416+ deploy_account_tx (
417+ deploy_account_tx_args ! {
418+ class_hash,
419+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
420+ constructor_calldata: calldata![ Felt :: ZERO ] ,
421+ } ,
422+ Nonce :: default ( ) ,
423+ ) ,
424+ & test_builder. chain_id ( ) ,
425+ )
426+ . unwrap ( ) ;
427+ test_builder. add_fund_address_tx_with_default_amount ( deploy_tx. contract_address ) ;
428+ test_builder. move_to_next_block ( ) ;
429+
408430 // Invoke.
409431 // Calldata [0, 0, 0] → class_hash=0 → __execute__ returns immediately.
410432 let invoke_args = invoke_tx_args ! {
@@ -439,6 +461,9 @@ async fn test_execute_txs_inner_resources() {
439461 . unwrap ( ) ;
440462 test_builder. add_cairo1_declare_tx ( tx, & sierra) ;
441463
464+ // Deploy account (pre-prepared).
465+ test_builder. add_deploy_account_tx ( deploy_tx) ;
466+
442467 // Execute the business logic and extract the business logic resources for each tx.
443468 let test_runner = test_builder. build ( ) . await ;
444469 let business_logic_resources: [ ExecutionResources ; N_TXS ] = test_runner
@@ -471,21 +496,22 @@ async fn test_execute_txs_inner_resources() {
471496 test_output. perform_default_validations ( ) ;
472497
473498 // Fetch the OS resources for each tx.
474- let [ invoke_overhead, declare_overhead] : [ ExecutionResources ; N_TXS ] = test_output
475- . runner_output
476- . txs_trace
477- . iter ( )
478- . rev ( )
479- . take ( N_TXS )
480- . rev ( )
481- . map ( |trace| trace. get_resources ( ) . unwrap ( ) . clone ( ) )
482- . zip ( business_logic_resources)
483- . map ( |( os_resources, business_logic_resources) | {
484- ( & os_resources - & business_logic_resources) . filter_unused_builtins ( )
485- } )
486- . collect :: < Vec < _ > > ( )
487- . try_into ( )
488- . unwrap ( ) ;
499+ let [ invoke_overhead, declare_overhead, deploy_account_overhead] : [ ExecutionResources ; N_TXS ] =
500+ test_output
501+ . runner_output
502+ . txs_trace
503+ . iter ( )
504+ . rev ( )
505+ . take ( N_TXS )
506+ . rev ( )
507+ . map ( |trace| trace. get_resources ( ) . unwrap ( ) . clone ( ) )
508+ . zip ( business_logic_resources)
509+ . map ( |( os_resources, business_logic_resources) | {
510+ ( & os_resources - & business_logic_resources) . filter_unused_builtins ( )
511+ } )
512+ . collect :: < Vec < _ > > ( )
513+ . try_into ( )
514+ . unwrap ( ) ;
489515
490516 // Invoke: variable cost, with scaling of 2.
491517 // TODO(Dori): Compute linear factor cost.
@@ -532,6 +558,35 @@ async fn test_execute_txs_inner_resources() {
532558 . execute_txs_inner
533559 . insert ( TransactionType :: Declare , VariableResourceParams :: Constant ( declare_overhead) ) ;
534560
561+ // Deploy account: variable cost, with scaling of 2.
562+ // TODO(Dori): Compute linear factor cost.
563+ let VariableResourceParams :: WithFactor ( mut deploy_account_resources_params) =
564+ raw_vc. os_resources . execute_txs_inner . get ( & TransactionType :: DeployAccount ) . unwrap ( ) . clone ( )
565+ else {
566+ panic ! (
567+ "Deploy account resources params has unexpected structure: {:?}" ,
568+ raw_vc. os_resources. execute_txs_inner. get( & TransactionType :: DeployAccount ) . unwrap( )
569+ ) ;
570+ } ;
571+ let VariableCallDataFactor :: Scaled ( ref deploy_account_scaling_factor) =
572+ deploy_account_resources_params. calldata_factor
573+ else {
574+ panic ! (
575+ "Deploy account scaling factor has unexpected structure: {:?}" ,
576+ deploy_account_resources_params. calldata_factor
577+ ) ;
578+ } ;
579+ assert_eq ! (
580+ deploy_account_scaling_factor. scaling_factor, 2 ,
581+ "Deploy account scaling factor has unexpected value: {:?}" ,
582+ deploy_account_scaling_factor. scaling_factor
583+ ) ;
584+ deploy_account_resources_params. constant = deploy_account_overhead;
585+ raw_vc. os_resources . execute_txs_inner . insert (
586+ TransactionType :: DeployAccount ,
587+ VariableResourceParams :: WithFactor ( deploy_account_resources_params) ,
588+ ) ;
589+
535590 // Verify computation.
536591 expect_file ! [ VersionedConstants :: json_path( & version) . unwrap( ) ]
537592 . assert_eq ( & raw_vc. to_string_pretty ( ) ) ;
0 commit comments