Skip to content

Commit

Permalink
test(block_hash): tx data test
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavGrs committed Jun 10, 2024
1 parent f6cfecb commit 7907cd2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
9 changes: 0 additions & 9 deletions crates/committer_cli/src/block_hash.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/committer_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use filled_tree_output::filled_forest::SerializedForest;
use parse_input::read::parse_input;
use std::io;

pub mod block_hash;
pub mod filled_tree_output;
pub mod parse_input;
pub mod tests;
Expand Down
35 changes: 17 additions & 18 deletions crates/committer_cli/src/tests/python_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::block_hash::BlockInfo;
use crate::filled_tree_output::errors::FilledForestError;
use crate::filled_tree_output::filled_forest::SerializedForest;
use crate::parse_input::read::parse_input;
Expand All @@ -24,14 +23,17 @@ use committer::storage::map_storage::MapStorage;
use committer::storage::storage_trait::{Storage, StorageKey, StorageValue};
use ethnum::U256;
use serde_json::json;
use starknet_api::block_hash::block_hash_calculator::TransactionOutputForHash;
use starknet_api::block_hash::block_hash_calculator::{
TransactionHashingData, TransactionOutputForHash,
};
use starknet_api::state::ThinStateDiff;
use starknet_api::transaction::TransactionExecutionStatus;
use starknet_types_core::hash::{Pedersen, StarkHash};
use std::fmt::Debug;
use std::{collections::HashMap, io};
use thiserror;

use super::utils::objects::{get_thin_state_diff, get_transaction_output_for_hash};
use super::utils::objects::{get_thin_state_diff, get_transaction_output_for_hash, get_tx_data};

// Enum representing different Python tests.
pub(crate) enum PythonTest {
Expand All @@ -46,9 +48,9 @@ pub(crate) enum PythonTest {
StorageNode,
FilledForestOutput,
TreeHeightComparison,
ParseBlockInfo,
ParseTxOutput,
ParseStateDiff,
ParseTxData,
SerializeForRustCommitterFlowTest,
}

Expand Down Expand Up @@ -93,10 +95,10 @@ impl TryFrom<String> for PythonTest {
"compare_python_hash_constants" => Ok(Self::ComparePythonHashConstants),
"storage_node_test" => Ok(Self::StorageNode),
"filled_forest_output" => Ok(Self::FilledForestOutput),
"parse_block_info" => Ok(Self::ParseBlockInfo),
"compare_tree_height" => Ok(Self::TreeHeightComparison),
"parse_tx_output_test" => Ok(Self::ParseTxOutput),
"parse_state_diff_test" => Ok(Self::ParseStateDiff),
"parse_tx_data_test" => Ok(Self::ParseTxData),
"serialize_to_rust_committer_flow_test" => Ok(Self::SerializeForRustCommitterFlowTest),
_ => Err(PythonTestError::UnknownTestName(value)),
}
Expand Down Expand Up @@ -142,10 +144,6 @@ impl PythonTest {
}
Self::FilledForestOutput => filled_forest_output_test(),
Self::TreeHeightComparison => Ok(get_actual_tree_height()),
Self::ParseBlockInfo => {
let block_info: BlockInfo = serde_json::from_str(Self::non_optional_input(input)?)?;
Ok(parse_block_info_test(block_info))
}
Self::ParseTxOutput => {
let tx_output: TransactionOutputForHash =
serde_json::from_str(Self::non_optional_input(input)?)?;
Expand All @@ -156,6 +154,11 @@ impl PythonTest {
serde_json::from_str(Self::non_optional_input(input)?)?;
Ok(parse_state_diff_test(tx_output))
}
Self::ParseTxData => {
let tx_data: TransactionHashingData =
serde_json::from_str(Self::non_optional_input(input)?)?;
Ok(parse_tx_data_test(tx_data))
}
Self::SerializeForRustCommitterFlowTest => {
let input: HashMap<String, String> =
serde_json::from_str(Self::non_optional_input(input)?)?;
Expand Down Expand Up @@ -202,15 +205,6 @@ pub(crate) fn example_test(test_args: HashMap<String, String>) -> String {
format!("Calling example test with args: x: {}, y: {}", x, y)
}

pub(crate) fn parse_block_info_test(block_info: BlockInfo) -> String {
format!(
"da mode: {}, gas: {:?}, data_gas: {:?}",
block_info.da_mode,
block_info.l1_gas_price_per_token,
block_info.l1_data_gas_price_per_token
)
}

pub(crate) fn parse_tx_output_test(tx_execution_info: TransactionOutputForHash) -> String {
let expected_object = get_transaction_output_for_hash(&tx_execution_info.execution_status);
is_success_string(expected_object == tx_execution_info)
Expand All @@ -221,6 +215,11 @@ pub(crate) fn parse_state_diff_test(state_diff: ThinStateDiff) -> String {
is_success_string(expected_object == state_diff)
}

pub(crate) fn parse_tx_data_test(tx_data: TransactionHashingData) -> String {
let expected_object = get_tx_data(&TransactionExecutionStatus::Succeeded);
is_success_string(expected_object == tx_data)
}

fn is_success_string(is_success: bool) -> String {
match is_success {
true => "Success",
Expand Down
16 changes: 14 additions & 2 deletions crates/committer_cli/src/tests/utils/objects.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use indexmap::indexmap;
use starknet_api::{
block_hash::block_hash_calculator::TransactionOutputForHash,
block_hash::block_hash_calculator::{TransactionHashingData, TransactionOutputForHash},
core::{ClassHash, CompiledClassHash, ContractAddress, EthAddress, Nonce, PatriciaKey},
state::{StorageKey, ThinStateDiff},
transaction::{
Event, EventContent, EventData, EventKey, Fee, GasVector, L2ToL1Payload, MessageToL1,
RevertedTransactionExecutionStatus, TransactionExecutionStatus,
RevertedTransactionExecutionStatus, TransactionExecutionStatus, TransactionHash,
TransactionSignature,
},
};
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -68,3 +69,14 @@ pub(crate) fn get_thin_state_diff() -> ThinStateDiff {
replaced_classes: indexmap! {},
}
}

pub(crate) fn get_tx_data(execution_status: &TransactionExecutionStatus) -> TransactionHashingData {
TransactionHashingData {
transaction_signature: Some(TransactionSignature(vec![
Felt::from_bytes_be_slice(&[1_u8]),
Felt::from_bytes_be_slice(&[2_u8]),
])),
transaction_output: get_transaction_output_for_hash(execution_status),
transaction_hash: TransactionHash(Felt::from_bytes_be_slice(&[3_u8])),
}
}

0 comments on commit 7907cd2

Please sign in to comment.