Skip to content

Commit

Permalink
refactor(execution): put all create for testing methods under testing…
Browse files Browse the repository at this point in the history
… config
  • Loading branch information
meship-starkware committed Jul 30, 2024
1 parent a65d3f9 commit 8d43db2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
28 changes: 25 additions & 3 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use std::sync::Arc;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde_json::Value;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, ContractAddress, PatriciaKey};
use starknet_api::transaction::Fee;
use starknet_api::{contract_address, felt, patricia_key};
use starknet_api::core::{ChainId, ContractAddress, Nonce, PatriciaKey};
use starknet_api::transaction::{Calldata, Fee, TransactionHash, TransactionVersion};
use starknet_api::{calldata, contract_address, felt, patricia_key};
use starknet_types_core::felt::Felt;

use super::update_json_value;
use crate::abi::abi_utils::selector_from_name;
use crate::blockifier::block::{BlockInfo, GasPrices};
use crate::bouncer::{BouncerConfig, BouncerWeights};
use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext};
Expand Down Expand Up @@ -40,6 +42,7 @@ use crate::transaction::objects::{
TransactionInfo,
TransactionResources,
};
use crate::transaction::transactions::L1HandlerTransaction;
use crate::versioned_constants::{
GasCosts,
OsConstants,
Expand Down Expand Up @@ -230,3 +233,22 @@ impl ContractClassV1 {
Self::try_from_json_string(&raw_contract_class).unwrap()
}
}

impl L1HandlerTransaction {
pub fn create_for_testing(l1_fee: Fee, contract_address: ContractAddress) -> Self {
let calldata = calldata![
Felt::from(0x123), // from_address.
Felt::from(0x876), // key.
Felt::from(0x44) // value.
];
let tx = starknet_api::transaction::L1HandlerTransaction {
version: TransactionVersion::ZERO,
nonce: Nonce::default(),
contract_address,
entry_point_selector: selector_from_name("l1_handler_set_value"),
calldata,
};
let tx_hash = TransactionHash::default();
Self { tx, tx_hash, paid_fee_on_l1: l1_fee }
}
}
19 changes: 0 additions & 19 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use starknet_api::calldata;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::transaction::{
Expand All @@ -15,7 +14,6 @@ use starknet_api::transaction::{
TransactionSignature,
TransactionVersion,
};
use starknet_types_core::felt::Felt;

use crate::abi::abi_utils::selector_from_name;
use crate::context::{BlockContext, TransactionContext};
Expand Down Expand Up @@ -507,23 +505,6 @@ impl L1HandlerTransaction {
// The calldata includes the "from" field, which is not a part of the payload.
self.tx.calldata.0.len() - 1
}

pub fn create_for_testing(l1_fee: Fee, contract_address: ContractAddress) -> Self {
let calldata = calldata![
Felt::from(0x123), // from_address.
Felt::from(0x876), // key.
Felt::from(0x44) // value.
];
let tx = starknet_api::transaction::L1HandlerTransaction {
version: TransactionVersion::ZERO,
nonce: Nonce::default(),
contract_address,
entry_point_selector: selector_from_name("l1_handler_set_value"),
calldata,
};
let tx_hash = TransactionHash::default();
Self { tx, tx_hash, paid_fee_on_l1: l1_fee }
}
}

impl HasRelatedFeeType for L1HandlerTransaction {
Expand Down
3 changes: 2 additions & 1 deletion crates/gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ impl Default for ChainInfoConfig {
ChainInfo::default().into()
}
}

impl ChainInfoConfig {
#[cfg(any(test, feature = "testing"))]
pub fn create_for_testing() -> Self {
BlockContext::create_for_testing().chain_info().clone().into()
}
Expand Down Expand Up @@ -285,6 +285,7 @@ impl SerializeConfig for StatefulTransactionValidatorConfig {
}
}

#[cfg(any(test, feature = "testing"))]
impl StatefulTransactionValidatorConfig {
pub fn create_for_testing() -> Self {
StatefulTransactionValidatorConfig {
Expand Down

0 comments on commit 8d43db2

Please sign in to comment.