Skip to content

Commit

Permalink
test(starknet_client): add tests for a 0.13.2 block
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahakShama committed Jul 25, 2024
1 parent cd31074 commit 19c30db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.

Large diffs are not rendered by default.

47 changes: 18 additions & 29 deletions crates/starknet_client/src/reader/objects/block_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::test_utils::read_resource::read_resource_file;
#[test]
fn load_block_succeeds() {
for block_path in [
// TODO: add 0_13_2 block.
"reader/block_post_0_13_2.json",
"reader/block_post_0_13_1.json",
"reader/old_block_post_0_13_1_no_sn_version.json",
"reader/old_block_post_0_13_1_no_sequencer.json",
Expand Down Expand Up @@ -106,27 +106,19 @@ fn load_block_state_update_succeeds() {

#[tokio::test]
async fn to_starknet_api_block_and_version() {
// TODO(yair): Add block.json for a 0.13.1 block.
let raw_block = read_resource_file("reader/block_post_0_13_1.json");
let raw_block = read_resource_file("reader/block_post_0_13_2.json");
let block: Block = serde_json::from_str(&raw_block).unwrap();
let expected_num_of_tx_outputs = block.transactions().len();
let starknet_api_block = block.to_starknet_api_block_and_version().unwrap();
assert_eq!(expected_num_of_tx_outputs, starknet_api_block.body.transaction_outputs.len());
// Check that for pre 0.13.2 blocks, we erase their hash since it's a deprecated formula.
assert!(starknet_api_block.header.event_commitment.is_none());
assert!(starknet_api_block.header.transaction_commitment.is_none());

let mut err_block: BlockPostV0_13_1 = serde_json::from_str(&raw_block).unwrap();
err_block.transaction_receipts.pop();
let err = err_block.to_starknet_api_block_and_version().unwrap_err();
assert_matches!(
err,
ReaderClientError::TransactionReceiptsError(
TransactionReceiptsError::WrongNumberOfReceipts {
block_number: _,
num_of_txs: _,
num_of_receipts: _,
}
TransactionReceiptsError::WrongNumberOfReceipts { .. }
)
);

Expand All @@ -136,12 +128,7 @@ async fn to_starknet_api_block_and_version() {
assert_matches!(
err,
ReaderClientError::TransactionReceiptsError(
TransactionReceiptsError::MismatchTransactionIndex {
block_number: _,
tx_index: _,
tx_hash: _,
receipt_tx_index: _,
}
TransactionReceiptsError::MismatchTransactionIndex { .. }
)
);

Expand All @@ -151,12 +138,7 @@ async fn to_starknet_api_block_and_version() {
assert_matches!(
err,
ReaderClientError::TransactionReceiptsError(
TransactionReceiptsError::MismatchTransactionHash {
block_number: _,
tx_index: _,
tx_hash: _,
receipt_tx_hash: _,
}
TransactionReceiptsError::MismatchTransactionHash { .. }
)
);

Expand All @@ -169,12 +151,19 @@ async fn to_starknet_api_block_and_version() {
assert_matches!(
err,
ReaderClientError::TransactionReceiptsError(
TransactionReceiptsError::MismatchTransactionHash {
block_number: _,
tx_index: _,
tx_hash: _,
receipt_tx_hash: _,
}
TransactionReceiptsError::MismatchTransactionHash { .. }
)
);
}

#[tokio::test]
async fn to_starknet_api_block_and_version_0_13_1() {
let raw_block = read_resource_file("reader/block_post_0_13_1.json");
let block: Block = serde_json::from_str(&raw_block).unwrap();
let expected_num_of_tx_outputs = block.transactions().len();
let starknet_api_block = block.to_starknet_api_block_and_version().unwrap();
assert_eq!(expected_num_of_tx_outputs, starknet_api_block.body.transaction_outputs.len());
// Check that for pre 0.13.2 blocks, we erase their hash since it's a deprecated formula.
assert!(starknet_api_block.header.event_commitment.is_none());
assert!(starknet_api_block.header.transaction_commitment.is_none());
}

0 comments on commit 19c30db

Please sign in to comment.