Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

test(starknet_client): add tests for a 0.13.2 block #2181

Closed
wants to merge 1 commit into from
Closed
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

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());
}
Loading