feat(rpc-testing-utils) : make replay transactions reponses comparaison in RpcComparer. (#5407)

This commit is contained in:
DoTheBestToGetTheBest
2023-11-24 04:07:23 -08:00
committed by GitHub
parent 2624f46675
commit 8100a88f9a
2 changed files with 45 additions and 2 deletions

View File

@ -22,5 +22,10 @@ futures.workspace = true
jsonrpsee = { workspace = true, features = ["client", "async-client"] } jsonrpsee = { workspace = true, features = ["client", "async-client"] }
serde_json.workspace = true serde_json.workspace = true
# assertions
similar-asserts = "1.5.0"
[dev-dependencies] [dev-dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "rt"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros", "rt"] }

View File

@ -447,8 +447,9 @@ where
while let Some((result1, result2)) = zipped_streams.next().await { while let Some((result1, result2)) = zipped_streams.next().await {
match (result1, result2) { match (result1, result2) {
(Ok((ref traces1_data, ref block1)), Ok((ref traces2_data, ref block2))) => { (Ok((ref traces1_data, ref block1)), Ok((ref traces2_data, ref block2))) => {
assert_eq!( similar_asserts::assert_eq!(
traces1_data, traces2_data, traces1_data,
traces2_data,
"Mismatch in traces for block: {:?}", "Mismatch in traces for block: {:?}",
block1 block1
); );
@ -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)] #[cfg(test)]
mod tests { mod tests {