From 7907cd2471150920bd581aef726b5f596b117571 Mon Sep 17 00:00:00 2001 From: Yoav Gross Date: Mon, 10 Jun 2024 14:23:53 +0300 Subject: [PATCH] test(block_hash): tx data test --- crates/committer_cli/src/block_hash.rs | 9 ----- crates/committer_cli/src/main.rs | 1 - .../committer_cli/src/tests/python_tests.rs | 35 +++++++++---------- .../committer_cli/src/tests/utils/objects.rs | 16 +++++++-- 4 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 crates/committer_cli/src/block_hash.rs diff --git a/crates/committer_cli/src/block_hash.rs b/crates/committer_cli/src/block_hash.rs deleted file mode 100644 index 29da6f73..00000000 --- a/crates/committer_cli/src/block_hash.rs +++ /dev/null @@ -1,9 +0,0 @@ -use serde::Deserialize; -use starknet_api::block::GasPricePerToken; - -#[derive(Debug, Deserialize)] -pub(crate) struct BlockInfo { - pub da_mode: bool, - pub l1_gas_price_per_token: GasPricePerToken, - pub l1_data_gas_price_per_token: GasPricePerToken, -} diff --git a/crates/committer_cli/src/main.rs b/crates/committer_cli/src/main.rs index 21dc4924..91fd5fd4 100644 --- a/crates/committer_cli/src/main.rs +++ b/crates/committer_cli/src/main.rs @@ -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; diff --git a/crates/committer_cli/src/tests/python_tests.rs b/crates/committer_cli/src/tests/python_tests.rs index ad600e7b..669c1767 100644 --- a/crates/committer_cli/src/tests/python_tests.rs +++ b/crates/committer_cli/src/tests/python_tests.rs @@ -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; @@ -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 { @@ -46,9 +48,9 @@ pub(crate) enum PythonTest { StorageNode, FilledForestOutput, TreeHeightComparison, - ParseBlockInfo, ParseTxOutput, ParseStateDiff, + ParseTxData, SerializeForRustCommitterFlowTest, } @@ -93,10 +95,10 @@ impl TryFrom 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)), } @@ -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)?)?; @@ -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 = serde_json::from_str(Self::non_optional_input(input)?)?; @@ -202,15 +205,6 @@ pub(crate) fn example_test(test_args: HashMap) -> 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) @@ -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", diff --git a/crates/committer_cli/src/tests/utils/objects.rs b/crates/committer_cli/src/tests/utils/objects.rs index 0da222fd..7a8273c1 100644 --- a/crates/committer_cli/src/tests/utils/objects.rs +++ b/crates/committer_cli/src/tests/utils/objects.rs @@ -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; @@ -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])), + } +}