From 0930b05c08bda8c9340d6d053d129f98fec813ef Mon Sep 17 00:00:00 2001 From: Aviv Greenburg Date: Mon, 28 Oct 2024 17:43:27 +0200 Subject: [PATCH] refactor(blockifier): impl .into() from api executable tx to blockifier AccountTransaction --- crates/blockifier/src/test_utils/declare.rs | 5 ++++- .../src/test_utils/deploy_account.rs | 3 ++- crates/blockifier/src/test_utils/invoke.rs | 4 +++- .../transaction/account_transactions_test.rs | 21 +++++++++---------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/crates/blockifier/src/test_utils/declare.rs b/crates/blockifier/src/test_utils/declare.rs index d78f3ff06c..ecd48cf6be 100644 --- a/crates/blockifier/src/test_utils/declare.rs +++ b/crates/blockifier/src/test_utils/declare.rs @@ -7,6 +7,9 @@ use crate::transaction::transactions::DeclareTransaction; pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> AccountTransaction { let tx_hash = declare_tx_args.tx_hash; let declare_tx = starknet_api::test_utils::declare::declare_tx(declare_tx_args); + // TODO(AvivG): use starknet_api::test_utils::declare::executable_declare_tx to + // create executable_declare. + let executable_declare = DeclareTransaction::new(declare_tx, tx_hash, class_info).unwrap(); - AccountTransaction::Declare(DeclareTransaction::new(declare_tx, tx_hash, class_info).unwrap()) + executable_declare.into() } diff --git a/crates/blockifier/src/test_utils/deploy_account.rs b/crates/blockifier/src/test_utils/deploy_account.rs index 51fd5a59f1..e7f018930c 100644 --- a/crates/blockifier/src/test_utils/deploy_account.rs +++ b/crates/blockifier/src/test_utils/deploy_account.rs @@ -16,5 +16,6 @@ pub fn deploy_account_tx( // TODO(AvivG): use the "new" method. let executable_deploy_account_tx = DeployAccountTransaction { tx: deploy_account_tx, only_query: false }; - AccountTransaction::DeployAccount(executable_deploy_account_tx) + + executable_deploy_account_tx.into() } diff --git a/crates/blockifier/src/test_utils/invoke.rs b/crates/blockifier/src/test_utils/invoke.rs index d4fff4923b..2baf0877a2 100644 --- a/crates/blockifier/src/test_utils/invoke.rs +++ b/crates/blockifier/src/test_utils/invoke.rs @@ -20,6 +20,8 @@ pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction { entry_point_selector: selector_from_name(EXECUTE_ENTRY_POINT_NAME), }) } else { + // TODO(AvivG): Have test util 'invoke_tx' support creation of TransactionVersion::ZERO + // invoke transactions. starknet_api::test_utils::invoke::invoke_tx(invoke_args) }; @@ -27,5 +29,5 @@ pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction { true => InvokeTransaction::new_for_query(invoke_tx, tx_hash), false => InvokeTransaction::new(invoke_tx, tx_hash), }; - AccountTransaction::Invoke(invoke_tx) + invoke_tx.into() } diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index abe7d11f30..3af8e29812 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -759,17 +759,16 @@ fn test_fail_declare(block_context: BlockContext, max_fee: Fee) { state.set_contract_class(class_hash, contract_class.clone().try_into().unwrap()).unwrap(); state.set_compiled_class_hash(class_hash, declare_tx.compiled_class_hash).unwrap(); let class_info = calculate_class_info_for_testing(contract_class); - let declare_account_tx = AccountTransaction::Declare( - DeclareTransaction::new( - starknet_api::transaction::DeclareTransaction::V2(DeclareTransactionV2 { - nonce: next_nonce, - ..declare_tx - }), - TransactionHash::default(), - class_info, - ) - .unwrap(), - ); + let declare_account_tx: AccountTransaction = DeclareTransaction::new( + starknet_api::transaction::DeclareTransaction::V2(DeclareTransactionV2 { + nonce: next_nonce, + ..declare_tx + }), + TransactionHash::default(), + class_info, + ) + .unwrap() + .into(); // Fail execution, assert nonce and balance are unchanged. let tx_info = declare_account_tx.create_tx_info();