Skip to content

Commit

Permalink
chore: create executable tx creator for testing (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Sep 9, 2024
1 parent 7d7a6c2 commit e34425f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
17 changes: 16 additions & 1 deletion crates/starknet_api/src/test_utils/declare.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,6 +12,7 @@ use crate::transaction::{
PaymasterData,
Tip,
TransactionHash,
TransactionHasher,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
Expand Down Expand Up @@ -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 }
}
21 changes: 20 additions & 1 deletion crates/starknet_api/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,6 +10,7 @@ use crate::transaction::{
Fee,
PaymasterData,
Tip,
TransactionHash,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
Expand Down Expand Up @@ -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 }
}
9 changes: 9 additions & 0 deletions crates/starknet_api/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,6 +11,7 @@ use crate::transaction::{
InvokeTransactionV3,
PaymasterData,
Tip,
TransactionHash,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
Expand Down Expand Up @@ -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 }
}

0 comments on commit e34425f

Please sign in to comment.