From 49b511a3d2a3dc934dba64a4c997c2268beff131 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Mon, 9 Sep 2024 11:55:24 +0300 Subject: [PATCH] test: use the exeutable tx creator test util for the account tx creator test util --- .../blockifier/src/test_utils/deploy_account.rs | 17 +++-------------- crates/blockifier/src/test_utils/invoke.rs | 9 ++------- .../src/test_utils/deploy_account.rs | 4 +++- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/crates/blockifier/src/test_utils/deploy_account.rs b/crates/blockifier/src/test_utils/deploy_account.rs index ffcd247dad1..d6745d46f25 100644 --- a/crates/blockifier/src/test_utils/deploy_account.rs +++ b/crates/blockifier/src/test_utils/deploy_account.rs @@ -1,7 +1,5 @@ -use starknet_api::core::calculate_contract_address; use starknet_api::test_utils::deploy_account::DeployAccountTxArgs; use starknet_api::test_utils::NonceManager; -use starknet_api::transaction::TransactionHash; use crate::transaction::transactions::DeployAccountTransaction; @@ -9,18 +7,9 @@ pub fn deploy_account_tx( deploy_tx_args: DeployAccountTxArgs, nonce_manager: &mut NonceManager, ) -> DeployAccountTransaction { - let default_tx_hash = TransactionHash::default(); - let contract_address = calculate_contract_address( - deploy_tx_args.contract_address_salt, - deploy_tx_args.class_hash, - &deploy_tx_args.constructor_calldata, - deploy_tx_args.deployer_address, - ) - .unwrap(); - - let deploy_account_tx = starknet_api::test_utils::deploy_account::deploy_account_tx( + let deploy_account_tx = starknet_api::test_utils::deploy_account::executable_deploy_account_tx( deploy_tx_args, - nonce_manager.next(contract_address), + nonce_manager, ); - DeployAccountTransaction::new(deploy_account_tx, default_tx_hash, contract_address) + DeployAccountTransaction { tx: deploy_account_tx, only_query: false } } diff --git a/crates/blockifier/src/test_utils/invoke.rs b/crates/blockifier/src/test_utils/invoke.rs index db5915d6cfd..ea80f40b332 100644 --- a/crates/blockifier/src/test_utils/invoke.rs +++ b/crates/blockifier/src/test_utils/invoke.rs @@ -1,16 +1,11 @@ use starknet_api::test_utils::invoke::InvokeTxArgs; -use starknet_api::transaction::TransactionHash; use crate::transaction::transactions::InvokeTransaction; pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction { - let default_tx_hash = TransactionHash::default(); let only_query = invoke_args.only_query; // TODO: Make TransactionVersion an enum and use match here. - let invoke_tx = starknet_api::test_utils::invoke::invoke_tx(invoke_args); + let invoke_tx = starknet_api::test_utils::invoke::executable_invoke_tx(invoke_args); - match only_query { - true => InvokeTransaction::new_for_query(invoke_tx, default_tx_hash), - false => InvokeTransaction::new(invoke_tx, default_tx_hash), - } + InvokeTransaction { tx: invoke_tx, only_query } } diff --git a/crates/starknet_api/src/test_utils/deploy_account.rs b/crates/starknet_api/src/test_utils/deploy_account.rs index de64c1a99ae..08057bb77e2 100644 --- a/crates/starknet_api/src/test_utils/deploy_account.rs +++ b/crates/starknet_api/src/test_utils/deploy_account.rs @@ -1,3 +1,4 @@ +use super::NonceManager; use crate::core::{calculate_contract_address, ClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; use crate::executable_transaction::DeployAccountTransaction as ExecutableDeployAccountTransaction; @@ -104,7 +105,7 @@ pub fn deploy_account_tx( pub fn executable_deploy_account_tx( deploy_tx_args: DeployAccountTxArgs, - nonce: Nonce, + nonce_manager: &mut NonceManager, ) -> ExecutableDeployAccountTransaction { let default_tx_hash = TransactionHash::default(); let contract_address = calculate_contract_address( @@ -114,6 +115,7 @@ pub fn executable_deploy_account_tx( deploy_tx_args.deployer_address, ) .unwrap(); + let nonce = nonce_manager.next(contract_address); let tx = deploy_account_tx(deploy_tx_args, nonce); ExecutableDeployAccountTransaction { tx, tx_hash: default_tx_hash, contract_address }