Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(block_hash): tx data test #216

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/committer_cli/src/tests/python_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,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 @@ -49,6 +52,7 @@ pub(crate) enum PythonTest {
ParseBlockInfo,
ParseTxOutput,
ParseStateDiff,
ParseTxData,
SerializeForRustCommitterFlowTest,
}

Expand Down Expand Up @@ -97,6 +101,7 @@ impl TryFrom<String> for PythonTest {
"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 @@ -156,6 +161,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 @@ -221,6 +231,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])),
}
}
Loading