diff --git a/crates/starknet_api/src/test_utils/declare.rs b/crates/starknet_api/src/test_utils/declare.rs index 6e4c0cca59..b90bfb03ec 100644 --- a/crates/starknet_api/src/test_utils/declare.rs +++ b/crates/starknet_api/src/test_utils/declare.rs @@ -1,5 +1,7 @@ -use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; +use crate::contract_class::ClassInfo; +use crate::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; +use crate::executable_transaction::DeclareTransaction as ExecutableDeclareTransaction; use crate::transaction::{ AccountDeploymentData, DeclareTransaction, @@ -10,6 +12,7 @@ use crate::transaction::{ PaymasterData, Tip, TransactionHash, + TransactionHasher, TransactionSignature, TransactionVersion, ValidResourceBounds, @@ -117,3 +120,15 @@ pub fn declare_tx(declare_tx_args: DeclareTxArgs) -> DeclareTransaction { panic!("Unsupported transaction version: {:?}.", declare_tx_args.version) } } + +pub fn executable_declare_tx( + declare_tx_args: DeclareTxArgs, + class_info: ClassInfo, +) -> ExecutableDeclareTransaction { + let transaction_version = declare_tx_args.version; + let tx = declare_tx(declare_tx_args); + let tx_hash = tx + .calculate_transaction_hash(&ChainId::create_for_testing(), &transaction_version) + .unwrap(); + ExecutableDeclareTransaction { tx, tx_hash, class_info } +} diff --git a/crates/starknet_api/src/test_utils/deploy_account.rs b/crates/starknet_api/src/test_utils/deploy_account.rs index 0d0ca06019..de64c1a99a 100644 --- a/crates/starknet_api/src/test_utils/deploy_account.rs +++ b/crates/starknet_api/src/test_utils/deploy_account.rs @@ -1,5 +1,6 @@ -use crate::core::{ClassHash, ContractAddress, Nonce}; +use crate::core::{calculate_contract_address, ClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; +use crate::executable_transaction::DeployAccountTransaction as ExecutableDeployAccountTransaction; use crate::transaction::{ Calldata, ContractAddressSalt, @@ -9,6 +10,7 @@ use crate::transaction::{ Fee, PaymasterData, Tip, + TransactionHash, TransactionSignature, TransactionVersion, ValidResourceBounds, @@ -99,3 +101,20 @@ pub fn deploy_account_tx( panic!("Unsupported transaction version: {:?}.", deploy_tx_args.version) } } + +pub fn executable_deploy_account_tx( + deploy_tx_args: DeployAccountTxArgs, + nonce: Nonce, +) -> ExecutableDeployAccountTransaction { + 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 tx = deploy_account_tx(deploy_tx_args, nonce); + + ExecutableDeployAccountTransaction { tx, tx_hash: default_tx_hash, contract_address } +} diff --git a/crates/starknet_api/src/test_utils/invoke.rs b/crates/starknet_api/src/test_utils/invoke.rs index c343e6b107..09f9f84721 100644 --- a/crates/starknet_api/src/test_utils/invoke.rs +++ b/crates/starknet_api/src/test_utils/invoke.rs @@ -1,6 +1,7 @@ use crate::calldata; use crate::core::{ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; +use crate::executable_transaction::InvokeTransaction as ExecutableInvokeTransaction; use crate::transaction::{ AccountDeploymentData, Calldata, @@ -10,6 +11,7 @@ use crate::transaction::{ InvokeTransactionV3, PaymasterData, Tip, + TransactionHash, TransactionSignature, TransactionVersion, ValidResourceBounds, @@ -103,3 +105,10 @@ pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction { panic!("Unsupported transaction version: {:?}.", invoke_args.version) } } + +pub fn executable_invoke_tx(invoke_args: InvokeTxArgs) -> ExecutableInvokeTransaction { + let default_tx_hash = TransactionHash::default(); + let tx = invoke_tx(invoke_args); + + ExecutableInvokeTransaction { tx, tx_hash: default_tx_hash } +}