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

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 2, 2024
1 parent f5265b6 commit c1aa4e5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 24 deletions.
70 changes: 70 additions & 0 deletions crates/starknet_client/resources/reader/block_post_0_13_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"block_hash": "0x26a1b4d94a5d35895c9924249fc27593e0f7ee6ff3a8fa1e60ad76070bc7251",
"block_number": 1,
"event_commitment": "0x0",
"l1_da_mode": "CALLDATA",
"l1_data_gas_price": {
"price_in_fri": "0x3e8",
"price_in_wei": "0x186a0"
},
"l1_gas_price": {
"price_in_fri": "0x6fc23ac00",
"price_in_wei": "0x2540be400"
},
"parent_block_hash": "0x638e44cbea0a1c46ff915b2d2d3f26e57e993b597f6abfd60407302237b9bc7",
"receipt_commitment": "0x62c4810f6d3c10592ba3106ddb7b49a6fee1e3576c0707d94f49b63a79a1b22",
"sequencer_address": "0x795488c127693ffb36733cc054f9e2be39241a794a4877dc8fc1dbe52750488",
"starknet_version": "0.13.2",
"state_diff_commitment": "0x75137e8ea75384964ece1ff6f06cf231d889409081b2030fc9700d45d92e084",
"state_diff_length": 3,
"state_root": "0x36e170bb62c21bc0a913d281f6294ff15c7c948b5a9122ef194e19ecd359c0a",
"status": "ACCEPTED_ON_L2",
"timestamp": 1719829055,
"transaction_commitment": "0x34a8c619b2600ebb2c9e0cb89242e49fdbb7227a105c6293459a879d2e6a4f6",
"transaction_receipts": [
{
"actual_fee": "0x0",
"events": [],
"execution_resources": {
"builtin_instance_counter": {
"ecdsa_builtin": 1,
"pedersen_builtin": 25,
"range_check_builtin": 66
},
"data_availability": {
"l1_data_gas": 0,
"l1_gas": 3305
},
"n_memory_holes": 0,
"n_steps": 3975,
"total_gas_consumed": {
"l1_data_gas": 0,
"l1_gas": 3315
}
},
"execution_status": "SUCCEEDED",
"l2_to_l1_messages": [],
"transaction_hash": "0xeeed489eb468ea78fd187a3aa5e872cfa94c51139b84b2c6bb8d5431f804af",
"transaction_index": 0
}
],
"transactions": [
{
"class_hash": "0x5253fc1990a26cf6bee7cac703261daf0b78d7d1f28921e09d564bcc03637f4",
"constructor_calldata": [
"0x19d717905f7fd4a616392485cd42a357c2d5809dd7ffca089c5f7fcabb20a1a"
],
"contract_address": "0x6e00fd2d239b1cf26f5180301c14b39258683ff927f8dbcbbee5d1314a1b2b9",
"contract_address_salt": "0x26fa4d8f1c895849a91080badfecb0a66e33b50055b68b97247b2c41b744f53",
"max_fee": "0x0",
"nonce": "0x0",
"signature": [
"0x3d7852381ae47aa6b92f9344ba95326bfd4c38c23a6ce1cc6bfab7f33362a60",
"0x770552e1fdd813b7ad8563bb175b35a955283a93f0483a0e64e05c30cf19dd1"
],
"transaction_hash": "0xeeed489eb468ea78fd187a3aa5e872cfa94c51139b84b2c6bb8d5431f804af",
"type": "DEPLOY_ACCOUNT",
"version": "0x1"
}
]
}
56 changes: 32 additions & 24 deletions crates/starknet_client/src/reader/objects/block_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ use crate::reader::objects::state::{
StateUpdate,
StorageEntry,
};
use crate::reader::objects::transaction::TransactionReceipt;
use crate::reader::ReaderClientError;
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,15 +105,11 @@ 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();
Expand Down Expand Up @@ -160,21 +155,34 @@ async fn to_starknet_api_block_and_version() {
)
);

let mut err_block: BlockPostV0_13_1 = serde_json::from_str(&raw_block).unwrap();
err_block.transaction_receipts[0] = TransactionReceipt {
transaction_hash: err_block.transactions[1].transaction_hash(),
..err_block.transaction_receipts[0].clone()
};
let err = err_block.to_starknet_api_block_and_version().unwrap_err();
assert_matches!(
err,
ReaderClientError::TransactionReceiptsError(
TransactionReceiptsError::MismatchTransactionHash {
block_number: _,
tx_index: _,
tx_hash: _,
receipt_tx_hash: _,
}
)
);
// TODO(shahak): Find a block with at least 2 transactions, and uncomment the code below.
// let mut err_block: BlockPostV0_13_1 = serde_json::from_str(&raw_block).unwrap();
// err_block.transaction_receipts[0] = TransactionReceipt {
// transaction_hash: err_block.transactions[1].transaction_hash(),
// ..err_block.transaction_receipts[0].clone()
// };
// let err = err_block.to_starknet_api_block_and_version().unwrap_err();
// assert_matches!(
// err,
// ReaderClientError::TransactionReceiptsError(
// TransactionReceiptsError::MismatchTransactionHash {
// block_number: _,
// tx_index: _,
// tx_hash: _,
// receipt_tx_hash: _,
// }
// )
// );
}

#[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 c1aa4e5

Please sign in to comment.