-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(starknet_committer_and_os_cli): separate block-hash tests
- Loading branch information
1 parent
8a4eee2
commit 3ef0653
Showing
7 changed files
with
92 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod run_block_hash_cli; | ||
pub mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
crates/starknet_committer_and_os_cli/src/block_hash_cli/tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod objects; | ||
pub mod python_tests; |
File renamed without changes.
83 changes: 83 additions & 0 deletions
83
crates/starknet_committer_and_os_cli/src/block_hash_cli/tests/python_tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use starknet_api::block_hash::block_hash_calculator::{ | ||
TransactionHashingData, | ||
TransactionOutputForHash, | ||
}; | ||
use starknet_api::state::ThinStateDiff; | ||
use starknet_api::transaction::TransactionExecutionStatus; | ||
|
||
use crate::block_hash_cli::tests::objects::{ | ||
get_thin_state_diff, | ||
get_transaction_output_for_hash, | ||
get_tx_data, | ||
}; | ||
use crate::shared_utils::types::{PythonTestError, PythonTestRunner}; | ||
|
||
pub type BlockHashPythonTestError = PythonTestError<()>; | ||
|
||
// Enum representing different Python tests. | ||
pub enum BlockHashPythonTestRunner { | ||
ParseTxOutput, | ||
ParseStateDiff, | ||
ParseTxData, | ||
} | ||
|
||
/// Implements conversion from a string to the test runner. | ||
impl TryFrom<String> for BlockHashPythonTestRunner { | ||
type Error = BlockHashPythonTestError; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { | ||
match value.as_str() { | ||
"parse_tx_output_test" => Ok(Self::ParseTxOutput), | ||
"parse_state_diff_test" => Ok(Self::ParseStateDiff), | ||
"parse_tx_data_test" => Ok(Self::ParseTxData), | ||
_ => Err(PythonTestError::UnknownTestName(value)), | ||
} | ||
} | ||
} | ||
|
||
impl PythonTestRunner for BlockHashPythonTestRunner { | ||
type SpecificError = (); | ||
/// Runs the test with the given arguments. | ||
async fn run(&self, input: Option<&str>) -> Result<String, BlockHashPythonTestError> { | ||
match self { | ||
Self::ParseTxOutput => { | ||
let tx_output: TransactionOutputForHash = | ||
serde_json::from_str(Self::non_optional_input(input)?)?; | ||
Ok(parse_tx_output_test(tx_output)) | ||
} | ||
Self::ParseStateDiff => { | ||
let tx_output: ThinStateDiff = | ||
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)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
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) | ||
} | ||
|
||
pub(crate) fn parse_state_diff_test(state_diff: ThinStateDiff) -> String { | ||
let expected_object = get_thin_state_diff(); | ||
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", | ||
false => "Failure", | ||
} | ||
.to_owned() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
crates/starknet_committer_and_os_cli/src/committer_cli/tests/utils.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pub mod objects; | ||
pub mod parse_from_python; | ||
pub mod random_structs; |