diff --git a/crates/apollo_batcher/src/cende_client_types.rs b/crates/apollo_batcher/src/cende_client_types.rs index 0a0c35ce608..e0a7b8e04e0 100644 --- a/crates/apollo_batcher/src/cende_client_types.rs +++ b/crates/apollo_batcher/src/cende_client_types.rs @@ -642,3 +642,22 @@ impl From for StarknetClientStateDiff { }) } } + +#[cfg(any(test, feature = "testing"))] +impl StarknetClientStateDiff { + pub fn sort(&mut self) { + // Storage diffs also need inner sorting: sort each address diffs, then sort the addresses. + self.0.storage_diffs.sort_by_key(|address, _| *address); + for (_, address_diffs) in self.0.storage_diffs.iter_mut() { + address_diffs.sort(); + } + self.0.deployed_contracts.sort_by_key(|deployed_contract| deployed_contract.address); + self.0.declared_classes.sort_by_key(|declared_class| declared_class.class_hash); + self.0.old_declared_contracts.sort(); + self.0.nonces.sort_by_key(|address, _nonce| *address); + self.0.replaced_classes.sort_by_key(|replaced_class| replaced_class.address); + self.0 + .migrated_compiled_classes + .sort_by_key(|migrated_compiled_class| migrated_compiled_class.class_hash); + } +} diff --git a/crates/central_systest_blobs/Cargo.toml b/crates/central_systest_blobs/Cargo.toml index 40c30382302..393033131d2 100644 --- a/crates/central_systest_blobs/Cargo.toml +++ b/crates/central_systest_blobs/Cargo.toml @@ -7,7 +7,7 @@ license-file.workspace = true description = "Keeps blob JSONs for centralized system test, and tests for regression" [dev-dependencies] -apollo_batcher.workspace = true +apollo_batcher = { workspace = true, features = ["testing"] } apollo_batcher_types.workspace = true apollo_class_manager_types = { workspace = true, features = ["testing"] } apollo_consensus.workspace = true diff --git a/crates/central_systest_blobs/src/cende_blob_regression_test.rs b/crates/central_systest_blobs/src/cende_blob_regression_test.rs index bc7d1f9c96c..c714d36566c 100644 --- a/crates/central_systest_blobs/src/cende_blob_regression_test.rs +++ b/crates/central_systest_blobs/src/cende_blob_regression_test.rs @@ -536,11 +536,13 @@ impl BlobFactory { &execution_info, None, )); - let tx_state_diff = StarknetClientStateDiff::from(state_changes.state_maps).0; + let mut tx_state_diff = StarknetClientStateDiff::from(state_changes.state_maps); + // To keep the output deterministic, sort the state diff. + tx_state_diff.sort(); transactions.push(CendePreconfirmedTransaction::from(internal)); transaction_receipts.push(Some(receipt)); - transaction_state_diffs.push(Some(tx_state_diff)); + transaction_state_diffs.push(Some(tx_state_diff.0)); // Update the state for the next tx. state = tx_state.state;