@@ -21,13 +21,18 @@ use expect_test::expect_file;
2121use indexmap:: IndexMap ;
2222use starknet_api:: block:: StarknetVersion ;
2323use starknet_api:: contract_class:: SierraVersion ;
24- use starknet_api:: core:: { ClassHash , ContractAddress , EthAddress } ;
25- use starknet_api:: executable_transaction:: { InvokeTransaction , TransactionType } ;
24+ use starknet_api:: core:: { ClassHash , ContractAddress , EthAddress , Nonce } ;
25+ use starknet_api:: executable_transaction:: {
26+ DeployAccountTransaction ,
27+ InvokeTransaction ,
28+ TransactionType ,
29+ } ;
30+ use starknet_api:: test_utils:: deploy_account:: deploy_account_tx;
2631use starknet_api:: test_utils:: invoke:: invoke_tx;
2732use starknet_api:: transaction:: fields:: { Calldata , ContractAddressSalt } ;
2833use starknet_api:: transaction:: { L2ToL1Payload , MessageToL1 } ;
2934use starknet_api:: versioned_constants_logic:: VersionedConstantsTrait ;
30- 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} ;
3136use starknet_os:: hint_processor:: os_logger:: ResourceFinalizer ;
3237use starknet_os:: test_utils:: { SHA256_BATCH_RESOURCES_LINEAR_UNSCALED , SHA256_BATCH_SIZE } ;
3338use starknet_types_core:: felt:: Felt ;
@@ -504,16 +509,59 @@ async fn test_execute_txs_inner_resources() {
504509 let version = StarknetVersion :: LATEST ;
505510 let mut raw_vc: RawVersionedConstants =
506511 serde_json:: from_str ( VersionedConstants :: json_str ( & version) . unwrap ( ) ) . unwrap ( ) ;
507- // TODO(Dori): DeployAccount, L1Handler.
508- const N_TXS : usize = 3 ;
512+ // TODO(Dori): L1Handler.
513+ const N_TXS : usize = 5 ;
509514
510515 // For linear factor measurements, it's not enough to just add one more calldata element; the
511516 // increase is not the same per element. The linear scale is on average.
512517 const INVOKE_SCALING_FACTOR : usize = 2 ;
518+ const DEPLOY_SCALING_FACTOR : usize = 2 ;
513519 const INVOKE_EXTRA_ARGS : usize = 10 ;
520+ const DEPLOY_EXTRA_ARGS : usize = 10 ;
514521
515- let OsResourcesTestSetup { stable_contract_address, mut test_builder, .. } =
516- setup_test_builder ( Some ( & raw_vc) ) . await ;
522+ let OsResourcesTestSetup {
523+ stable_contract_address,
524+ stable_contract_class_hash,
525+ mut test_builder,
526+ ..
527+ } = setup_test_builder ( Some ( & raw_vc) ) . await ;
528+
529+ // Prepare the deploy account txs in advance, so we can fund the address before moving to the
530+ // next block (just so the funding tx is not in our measurement block). Use the stable contract
531+ // to prevent noise from changing contract address.
532+ let deploy_tx_first = DeployAccountTransaction :: create (
533+ deploy_account_tx (
534+ deploy_account_tx_args ! {
535+ class_hash: stable_contract_class_hash,
536+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
537+ constructor_calldata: calldata![ Felt :: ZERO ] ,
538+ // The stable contract was already deployed (from deployer address zero) with
539+ // trivial salt, so use non-trivial salt to get a new address.
540+ contract_address_salt: ContractAddressSalt ( Felt :: from( 100 ) ) ,
541+ } ,
542+ Nonce :: default ( ) ,
543+ ) ,
544+ & test_builder. chain_id ( ) ,
545+ )
546+ . unwrap ( ) ;
547+ test_builder. add_fund_address_tx_with_default_amount ( deploy_tx_first. contract_address ) ;
548+ let deploy_tx_second = DeployAccountTransaction :: create (
549+ deploy_account_tx (
550+ deploy_account_tx_args ! {
551+ class_hash: stable_contract_class_hash,
552+ resource_bounds: * NON_TRIVIAL_RESOURCE_BOUNDS ,
553+ constructor_calldata: span_calldata( DEPLOY_EXTRA_ARGS ) ,
554+ // The stable contract was already deployed (from deployer address zero) with
555+ // trivial salt, so use non-trivial salt to get a new address.
556+ contract_address_salt: ContractAddressSalt ( Felt :: from( 100 ) ) ,
557+ } ,
558+ Nonce :: default ( ) ,
559+ ) ,
560+ & test_builder. chain_id ( ) ,
561+ )
562+ . unwrap ( ) ;
563+ test_builder. add_fund_address_tx_with_default_amount ( deploy_tx_second. contract_address ) ;
564+ test_builder. move_to_next_block ( ) ;
517565
518566 // Invoke.
519567 let invoke_args = invoke_tx_args ! {
@@ -553,6 +601,10 @@ async fn test_execute_txs_inner_resources() {
553601 & test_builder. chain_id ( ) ,
554602 ) ;
555603
604+ // Deploy account (pre-prepared).
605+ test_builder. add_deploy_account_tx ( deploy_tx_first) ;
606+ test_builder. add_deploy_account_tx ( deploy_tx_second) ;
607+
556608 // Execute the business logic and extract the business logic resources for each tx.
557609 let test_runner = test_builder. build ( ) . await ;
558610 let business_logic_resources: [ ExecutionResources ; N_TXS ] = test_runner
@@ -585,7 +637,13 @@ async fn test_execute_txs_inner_resources() {
585637 test_output. perform_default_validations ( ) ;
586638
587639 // Fetch the OS resources for each tx.
588- let [ invoke_first, invoke_second, declare_constant] : [ ExecutionResources ; N_TXS ] = test_output
640+ let [
641+ invoke_first,
642+ invoke_second,
643+ declare_constant,
644+ deploy_first,
645+ deploy_second,
646+ ] : [ ExecutionResources ; N_TXS ] = test_output
589647 . runner_output
590648 . txs_trace
591649 . iter ( )
@@ -608,6 +666,9 @@ async fn test_execute_txs_inner_resources() {
608666 let invoke_linear_factor = ( & ( & invoke_second - & invoke_first) . filter_unused_builtins ( )
609667 * INVOKE_SCALING_FACTOR )
610668 . div_ceil ( INVOKE_EXTRA_ARGS ) ;
669+ let deploy_linear_factor = ( & ( & deploy_second - & deploy_first) . filter_unused_builtins ( )
670+ * DEPLOY_SCALING_FACTOR )
671+ . div_ceil ( DEPLOY_EXTRA_ARGS ) ;
611672 raw_vc. os_resources . execute_txs_inner . extend ( [
612673 (
613674 TransactionType :: InvokeFunction ,
@@ -620,6 +681,16 @@ async fn test_execute_txs_inner_resources() {
620681 } ) ,
621682 ) ,
622683 ( TransactionType :: Declare , VariableResourceParams :: Constant ( declare_constant) ) ,
684+ (
685+ TransactionType :: DeployAccount ,
686+ VariableResourceParams :: WithFactor ( ResourcesParams {
687+ constant : ( & deploy_first - & deploy_linear_factor) . filter_unused_builtins ( ) ,
688+ calldata_factor : VariableCallDataFactor :: Scaled ( CallDataFactor {
689+ resources : deploy_linear_factor,
690+ scaling_factor : DEPLOY_SCALING_FACTOR ,
691+ } ) ,
692+ } ) ,
693+ ) ,
623694 ] ) ;
624695
625696 // Verify computation.
0 commit comments