diff --git a/crates/rpc/rpc-testing-util/Cargo.toml b/crates/rpc/rpc-testing-util/Cargo.toml index d2488984bf..53b04c7a0e 100644 --- a/crates/rpc/rpc-testing-util/Cargo.toml +++ b/crates/rpc/rpc-testing-util/Cargo.toml @@ -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"] } diff --git a/crates/rpc/rpc-testing-util/src/trace.rs b/crates/rpc/rpc-testing-util/src/trace.rs index 3b4e28c2c5..c0e594bb2b 100644 --- a/crates/rpc/rpc-testing-util/src/trace.rs +++ b/crates/rpc/rpc-testing-util/src/trace.rs @@ -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 ); @@ -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, + trace_types: HashSet, + ) { + 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 {