Skip to content

Commit

Permalink
test: streamline the v0 version tx for invoke tx towards code dedup i…
Browse files Browse the repository at this point in the history
…n test utils
  • Loading branch information
ArniStarkware committed Nov 12, 2024
1 parent bf95e81 commit f4430e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
19 changes: 1 addition & 18 deletions crates/blockifier/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,13 @@ use starknet_api::executable_transaction::{
InvokeTransaction as ExecutableInvokeTransaction,
};
use starknet_api::test_utils::invoke::InvokeTxArgs;
use starknet_api::transaction::{InvokeTransaction, InvokeTransactionV0, TransactionVersion};

use crate::abi::abi_utils::selector_from_name;
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::constants::EXECUTE_ENTRY_POINT_NAME;

pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction {
let tx_hash = invoke_args.tx_hash;
let only_query = invoke_args.only_query;
// TODO: Make TransactionVersion an enum and use match here.
let invoke_tx = if invoke_args.version == TransactionVersion::ZERO {
InvokeTransaction::V0(InvokeTransactionV0 {
max_fee: invoke_args.max_fee,
calldata: invoke_args.calldata,
contract_address: invoke_args.sender_address,
signature: invoke_args.signature,
// V0 transactions should always select the `__execute__` entry point.
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)
};
let invoke_tx = starknet_api::test_utils::invoke::invoke_tx(invoke_args);

let invoke_tx =
ExecutableTransaction::Invoke(ExecutableInvokeTransaction { tx: invoke_tx, tx_hash });
Expand Down
33 changes: 25 additions & 8 deletions crates/starknet_api/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::calldata;
use crate::core::{ContractAddress, Nonce};
use std::sync::LazyLock;

use crate::core::{ContractAddress, EntryPointSelector, Nonce};
use crate::data_availability::DataAvailabilityMode;
use crate::executable_transaction::InvokeTransaction as ExecutableInvokeTransaction;
use crate::transaction::fields::{
Expand All @@ -13,11 +14,13 @@ use crate::transaction::fields::{
};
use crate::transaction::{
InvokeTransaction,
InvokeTransactionV0,
InvokeTransactionV1,
InvokeTransactionV3,
TransactionHash,
TransactionVersion,
};
use crate::{calldata, felt};

#[derive(Clone)]
pub struct InvokeTxArgs {
Expand Down Expand Up @@ -75,15 +78,29 @@ macro_rules! invoke_tx_args {
};
}

/// V0 transactions should always select the `__execute__` entry point.
/// The original code from the blockifier crate was:
///
/// crate::abi::abi_utils::selector_from_name(
/// crate::transaction::constants::EXECUTE_ENTRY_POINT_NAME
/// )
static EXECUTE_ENTRY_POINT_SELECTOR: LazyLock<EntryPointSelector> = LazyLock::new(|| {
const EXECUTE_ENTRY_POINT_NAME_THROUGH_KECCAK: &str =
"0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad";

EntryPointSelector(felt!(EXECUTE_ENTRY_POINT_NAME_THROUGH_KECCAK))
});

pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction {
// TODO: Make TransactionVersion an enum and use match here.
if invoke_args.version == TransactionVersion::ZERO {
// TODO(Arni): Implement V0. See blockifier test utils for reference. There is an issue with
// the computation of the entry_point_selector.
panic!(
"This test util does not supported creation of transaction version: {:?}.",
invoke_args.version
);
InvokeTransaction::V0(InvokeTransactionV0 {
max_fee: invoke_args.max_fee,
calldata: invoke_args.calldata,
contract_address: invoke_args.sender_address,
signature: invoke_args.signature,
entry_point_selector: *EXECUTE_ENTRY_POINT_SELECTOR,
})
} else if invoke_args.version == TransactionVersion::ONE {
InvokeTransaction::V1(InvokeTransactionV1 {
max_fee: invoke_args.max_fee,
Expand Down

0 comments on commit f4430e8

Please sign in to comment.