Skip to content

Commit

Permalink
feat(rpc-testing-utils) : make replay transactions reponses comparais…
Browse files Browse the repository at this point in the history
…on in RpcComparer. (#5407)
  • Loading branch information
DoTheBestToGetTheBest authored Nov 24, 2023
1 parent 2624f46 commit 8100a88
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions crates/rpc/rpc-testing-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ futures.workspace = true
jsonrpsee = { workspace = true, features = ["client", "async-client"] }
serde_json.workspace = true


# assertions
similar-asserts = "1.5.0"


[dev-dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "rt"] }
42 changes: 40 additions & 2 deletions crates/rpc/rpc-testing-util/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,9 @@ where
while let Some((result1, result2)) = zipped_streams.next().await {
match (result1, result2) {
(Ok((ref traces1_data, ref block1)), Ok((ref traces2_data, ref block2))) => {
assert_eq!(
traces1_data, traces2_data,
similar_asserts::assert_eq!(
traces1_data,
traces2_data,
"Mismatch in traces for block: {:?}",
block1
);
Expand All @@ -467,6 +468,43 @@ where
}
}
}

/// Compares the `replay_transactions` responses from the two RPC clients.
pub async fn compare_replay_transaction_responses(
&self,
transaction_hashes: Vec<TxHash>,
trace_types: HashSet<TraceType>,
) {
let stream1 =
self.client1.replay_transactions(transaction_hashes.clone(), trace_types.clone());
let stream2 = self.client2.replay_transactions(transaction_hashes, trace_types);

let mut zipped_streams = stream1.zip(stream2);

while let Some((result1, result2)) = zipped_streams.next().await {
match (result1, result2) {
(Ok((ref trace1_data, ref tx_hash1)), Ok((ref trace2_data, ref tx_hash2))) => {
similar_asserts::assert_eq!(
trace1_data,
trace2_data,
"Mismatch in trace results for transaction: {:?}",
tx_hash1
);
assert_eq!(tx_hash1, tx_hash2, "Mismatch in transaction hashes.");
}
(Err((ref err1, ref tx_hash1)), Err((ref err2, ref tx_hash2))) => {
assert_eq!(
format!("{:?}", err1),
format!("{:?}", err2),
"Different errors for transaction: {:?}",
tx_hash1
);
assert_eq!(tx_hash1, tx_hash2, "Mismatch in transaction hashes.");
}
_ => panic!("One client returned Ok while the other returned Err."),
}
}
}
}
#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 8100a88

Please sign in to comment.