Skip to content

Commit

Permalink
test: use the exeutable tx creator test util for the account tx creat…
Browse files Browse the repository at this point in the history
…or test util
  • Loading branch information
ArniStarkware committed Sep 18, 2024
1 parent 5762c79 commit 49b511a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
17 changes: 3 additions & 14 deletions crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
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;

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 }
}
9 changes: 2 additions & 7 deletions crates/blockifier/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
4 changes: 3 additions & 1 deletion crates/starknet_api/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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 }
Expand Down

0 comments on commit 49b511a

Please sign in to comment.