Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/central_systest_blobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ expect-test.workspace = true
google-cloud-storage.workspace = true
http.workspace = true
mockall.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet_api = { workspace = true, features = ["testing"] }
starknet_committer = { workspace = true, features = ["testing"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
5
22 changes: 11 additions & 11 deletions crates/central_systest_blobs/resources/preconfirmed_block.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"block_number": 0,
"round": 0,
"write_iteration": 0,
"pre_confirmed_block": {
"status": "PRE_CONFIRMED",
"starknet_version": "0.14.3",
"l1_da_mode": "CALLDATA",
"l1_gas_price": {
"l1_data_gas_price": {
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"l1_data_gas_price": {
"l1_gas_price": {
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"l2_gas_price": {
"price_in_fri": "0x1",
"price_in_wei": "0x1"
},
"timestamp": 1000,
"sequencer_address": "0x1000",
"transactions": [],
"starknet_version": "0.14.3",
"status": "PRE_CONFIRMED",
"timestamp": 1000,
"transaction_receipts": [],
"transaction_state_diffs": []
}
}
"transaction_state_diffs": [],
"transactions": []
},
"round": 0,
"write_iteration": 0
}
41 changes: 36 additions & 5 deletions crates/central_systest_blobs/src/cende_blob_regression_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,38 @@ impl BlobFactory {
// Blob file storage
// =====================

/// Sorts arrays of HashSet-backed fields that have non-deterministic iteration order.
/// Object keys are already deterministic because serde_json::Value uses BTreeMap.
fn normalize_set_arrays(value: &mut serde_json::Value) {
const SET_FIELDS: &[&str] =
&["accessed_blocks", "accessed_contract_addresses", "accessed_storage_keys"];
match value {
serde_json::Value::Object(map) => {
for (key, val) in map.iter_mut() {
if SET_FIELDS.contains(&key.as_str()) {
if let serde_json::Value::Array(arr) = val {
arr.sort_by_key(|a| a.to_string());
}
} else {
normalize_set_arrays(val);
}
}
}
serde_json::Value::Array(arr) => {
for item in arr.iter_mut() {
normalize_set_arrays(item);
}
}
_ => {}
}
}

fn to_normalized_json(value: &impl serde::Serialize) -> String {
let mut json_value = serde_json::to_value(value).unwrap();
normalize_set_arrays(&mut json_value);
format!("{}\n", serde_json::to_string_pretty(&json_value).unwrap())
}

async fn gcs_client() -> Client {
Client::new(ClientConfig::default().with_auth().await.expect(
"Failed to create GCS client config. Did you run `gcloud auth application-default login`?",
Expand Down Expand Up @@ -538,8 +570,8 @@ async fn fetch_raw_blobs_at_generation(
}

/// Pushes the blobs to GCS.
async fn bump_generation_and_store_blob_file(blobs: &[AerospikeBlob], client: &Client) {
let blobs_json = serde_json::to_string_pretty(blobs).unwrap();
async fn bump_generation_and_store_blob_file(blobs: Vec<AerospikeBlob>, client: &Client) {
let blobs_json = to_normalized_json(&blobs);
let next_generation = find_next_available_blobs_generation(client).await;
client
.upload_object(
Expand Down Expand Up @@ -574,13 +606,12 @@ async fn test_make_data() {
// TODO(Dori): create txs.
let (blobs, preconfirmed_block) = blob_factory.finalize().await;
expect_file![CHAIN_INFO_PATH].assert_eq(&serde_json::to_string_pretty(&chain_info).unwrap());
expect_file![PRECONFIRMED_BLOCK_PATH]
.assert_eq(&serde_json::to_string_pretty(&preconfirmed_block).unwrap());
expect_file![PRECONFIRMED_BLOCK_PATH].assert_eq(&to_normalized_json(&preconfirmed_block));

// Upload or download blobs depending on the fix mode.
let client = gcs_client().await;
if env::var("UPDATE_EXPECT").is_ok() {
bump_generation_and_store_blob_file(&blobs, &client).await;
bump_generation_and_store_blob_file(blobs, &client).await;
} else {
let fetched_blobs = fetch_blob_file(&client).await;
assert_eq!(
Expand Down
Loading