Skip to content

Commit

Permalink
test(starknet_api): use const for l1 handler tx version
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Dec 18, 2024
1 parent 6984361 commit 8fbc491
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
6 changes: 0 additions & 6 deletions crates/blockifier/src/abi/constants.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
use starknet_api::transaction::TransactionVersion;
use starknet_types_core::felt::Felt;

// The version is considered 0 for L1-Handler transaction hash calculation purposes.
pub const L1_HANDLER_VERSION: TransactionVersion = TransactionVersion(Felt::ZERO);

// OS-related constants.
pub const L1_TO_L2_MSG_HEADER_SIZE: usize = 5;
pub const L2_TO_L1_MSG_HEADER_SIZE: usize = 3;
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/test_utils/l1_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use starknet_api::calldata;
use starknet_api::core::ContractAddress;
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::test_utils::l1_handler::{executable_l1_handler_tx, L1HandlerTxArgs};
use starknet_api::transaction::constants::L1_HANDLER_VERSION;
use starknet_api::transaction::fields::Fee;
use starknet_api::transaction::TransactionVersion;
use starknet_types_core::felt::Felt;

pub fn l1handler_tx(l1_fee: Fee, contract_address: ContractAddress) -> L1HandlerTransaction {
Expand All @@ -15,7 +15,7 @@ pub fn l1handler_tx(l1_fee: Fee, contract_address: ContractAddress) -> L1Handler
];

executable_l1_handler_tx(L1HandlerTxArgs {
version: TransactionVersion::ZERO,
version: L1_HANDLER_VERSION,
contract_address,
entry_point_selector: selector_from_name("l1_handler_set_value"),
calldata,
Expand Down
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_l1_handler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::sync::Arc;

use blockifier::abi::constants;
use pyo3::prelude::*;
use starknet_api::core::{ContractAddress, EntryPointSelector, Nonce};
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::transaction::fields::{Calldata, Fee};
use starknet_api::transaction::TransactionHash;
use starknet_api::transaction::{constants, TransactionHash};

use crate::errors::{NativeBlockifierInputError, NativeBlockifierResult};
use crate::py_utils::{from_py_felts, py_attr, PyFelt};
Expand Down
3 changes: 2 additions & 1 deletion crates/papyrus_protobuf/src/converters/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use prost::Message;
use starknet_api::block::GasPrice;
use starknet_api::core::{ClassHash, CompiledClassHash, EntryPointSelector, Nonce};
use starknet_api::execution_resources::GasAmount;
use starknet_api::transaction::constants::L1_HANDLER_VERSION;
use starknet_api::transaction::fields::{
AccountDeploymentData,
AllResourceBounds,
Expand Down Expand Up @@ -1253,7 +1254,7 @@ impl From<DeployTransaction> for protobuf::transaction::Deploy {
impl TryFrom<protobuf::transaction::L1HandlerV0> for L1HandlerTransaction {
type Error = ProtobufConversionError;
fn try_from(value: protobuf::transaction::L1HandlerV0) -> Result<Self, Self::Error> {
let version = TransactionVersion(Felt::ZERO);
let version = L1_HANDLER_VERSION;

let nonce = Nonce(
value
Expand Down
5 changes: 3 additions & 2 deletions crates/papyrus_rpc/src/v0_8/transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use papyrus_test_utils::{
use pretty_assertions::assert_eq;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::transaction::constants::L1_HANDLER_VERSION;
use starknet_api::transaction::fields::{
AccountDeploymentData,
Calldata,
Expand All @@ -16,7 +17,7 @@ use starknet_api::transaction::fields::{
Tip,
TransactionSignature,
};
use starknet_api::transaction::{L1HandlerTransaction, Transaction, TransactionVersion};
use starknet_api::transaction::{L1HandlerTransaction, Transaction};
use starknet_api::{calldata, contract_address, felt, nonce};
use starknet_client::writer::objects::transaction as client_transaction;

Expand All @@ -38,7 +39,7 @@ use super::{
lazy_static::lazy_static! {
// A transaction from MAINNET with tx hash 0x439e12f67962c353182d72b4af12c3f11eaba4b36e552aebcdcd6db66971bdb.
static ref L1_HANDLER_TX: L1HandlerTransaction = L1HandlerTransaction {
version: TransactionVersion::ZERO,
version: L1_HANDLER_VERSION,
nonce: nonce!(0x18e94d),
contract_address: contract_address!(
"0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82"
Expand Down
4 changes: 4 additions & 0 deletions crates/starknet_api/src/transaction/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ use std::sync::LazyLock;

use starknet_types_core::felt::Felt;

use super::TransactionVersion;
use crate::core::ascii_as_felt;

// The version is considered 0 for L1-Handler transaction hash calculation purposes.
pub const L1_HANDLER_VERSION: TransactionVersion = TransactionVersion::ZERO;

pub const EXECUTE_ENTRY_POINT_NAME: &str = "__execute__";
pub const TRANSFER_ENTRY_POINT_NAME: &str = "transfer";
pub const VALIDATE_ENTRY_POINT_NAME: &str = "__validate__";
Expand Down

0 comments on commit 8fbc491

Please sign in to comment.