Skip to content

Commit 1b7ea13

Browse files
central_systest_blobs: sort hashsets when dumping
1 parent 9c6fcc0 commit 1b7ea13

5 files changed

Lines changed: 50 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/central_systest_blobs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ expect-test.workspace = true
1919
google-cloud-storage.workspace = true
2020
http.workspace = true
2121
mockall.workspace = true
22+
serde.workspace = true
2223
serde_json.workspace = true
2324
starknet_api = { workspace = true, features = ["testing"] }
2425
starknet_committer = { workspace = true, features = ["testing"] }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4
1+
5
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
22
"block_number": 0,
3-
"round": 0,
4-
"write_iteration": 0,
53
"pre_confirmed_block": {
6-
"status": "PRE_CONFIRMED",
7-
"starknet_version": "0.14.3",
84
"l1_da_mode": "CALLDATA",
9-
"l1_gas_price": {
5+
"l1_data_gas_price": {
106
"price_in_fri": "0x1",
117
"price_in_wei": "0x1"
128
},
13-
"l1_data_gas_price": {
9+
"l1_gas_price": {
1410
"price_in_fri": "0x1",
1511
"price_in_wei": "0x1"
1612
},
1713
"l2_gas_price": {
1814
"price_in_fri": "0x1",
1915
"price_in_wei": "0x1"
2016
},
21-
"timestamp": 1000,
2217
"sequencer_address": "0x1000",
23-
"transactions": [],
18+
"starknet_version": "0.14.3",
19+
"status": "PRE_CONFIRMED",
20+
"timestamp": 1000,
2421
"transaction_receipts": [],
25-
"transaction_state_diffs": []
26-
}
27-
}
22+
"transaction_state_diffs": [],
23+
"transactions": []
24+
},
25+
"round": 0,
26+
"write_iteration": 0
27+
}

crates/central_systest_blobs/src/cende_blob_regression_test.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,38 @@ impl BlobFactory {
498498
// Blob file storage
499499
// =====================
500500

501+
/// Sorts arrays of HashSet-backed fields that have non-deterministic iteration order.
502+
/// Object keys are already deterministic because serde_json::Value uses BTreeMap.
503+
fn normalize_set_arrays(value: &mut serde_json::Value) {
504+
const SET_FIELDS: &[&str] =
505+
&["accessed_blocks", "accessed_contract_addresses", "accessed_storage_keys"];
506+
match value {
507+
serde_json::Value::Object(map) => {
508+
for (key, val) in map.iter_mut() {
509+
if SET_FIELDS.contains(&key.as_str()) {
510+
if let serde_json::Value::Array(arr) = val {
511+
arr.sort_by_key(|a| a.to_string());
512+
}
513+
} else {
514+
normalize_set_arrays(val);
515+
}
516+
}
517+
}
518+
serde_json::Value::Array(arr) => {
519+
for item in arr.iter_mut() {
520+
normalize_set_arrays(item);
521+
}
522+
}
523+
_ => {}
524+
}
525+
}
526+
527+
fn to_normalized_json(value: &impl serde::Serialize) -> String {
528+
let mut json_value = serde_json::to_value(value).unwrap();
529+
normalize_set_arrays(&mut json_value);
530+
format!("{}\n", serde_json::to_string_pretty(&json_value).unwrap())
531+
}
532+
501533
async fn gcs_client() -> Client {
502534
Client::new(ClientConfig::default().with_auth().await.expect(
503535
"Failed to create GCS client config. Did you run `gcloud auth application-default login`?",
@@ -538,8 +570,8 @@ async fn fetch_raw_blobs_at_generation(
538570
}
539571

540572
/// Pushes the blobs to GCS.
541-
async fn bump_generation_and_store_blob_file(blobs: &[AerospikeBlob], client: &Client) {
542-
let blobs_json = serde_json::to_string_pretty(blobs).unwrap();
573+
async fn bump_generation_and_store_blob_file(blobs: Vec<AerospikeBlob>, client: &Client) {
574+
let blobs_json = to_normalized_json(&blobs);
543575
let next_generation = find_next_available_blobs_generation(client).await;
544576
client
545577
.upload_object(
@@ -574,13 +606,12 @@ async fn test_make_data() {
574606
// TODO(Dori): create txs.
575607
let (blobs, preconfirmed_block) = blob_factory.finalize().await;
576608
expect_file![CHAIN_INFO_PATH].assert_eq(&serde_json::to_string_pretty(&chain_info).unwrap());
577-
expect_file![PRECONFIRMED_BLOCK_PATH]
578-
.assert_eq(&serde_json::to_string_pretty(&preconfirmed_block).unwrap());
609+
expect_file![PRECONFIRMED_BLOCK_PATH].assert_eq(&to_normalized_json(&preconfirmed_block));
579610

580611
// Upload or download blobs depending on the fix mode.
581612
let client = gcs_client().await;
582613
if env::var("UPDATE_EXPECT").is_ok() {
583-
bump_generation_and_store_blob_file(&blobs, &client).await;
614+
bump_generation_and_store_blob_file(blobs, &client).await;
584615
} else {
585616
let fetched_blobs = fetch_blob_file(&client).await;
586617
assert_eq!(

0 commit comments

Comments
 (0)