Skip to content

Commit

Permalink
Replace assert_eq! with similar_asserts::assert_eq! (rpc crates)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xriazaka committed Oct 7, 2024
1 parent b8ae667 commit cc36e25
Show file tree
Hide file tree
Showing 45 changed files with 67 additions and 23 deletions.
1 change: 1 addition & 0 deletions crates/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ alloy-transport-ws.workspace = true
ci_info.workspace = true
tempfile = "3"
futures-util.workspace = true
similar-asserts.workspace = true

[features]
default = ["reqwest"]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-client/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl FromStr for BuiltInConnectionString {
#[cfg(test)]
mod test {
use super::*;
use similar_asserts::assert_eq;
use url::Url;

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ mod pubsub_impl {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn test_client_with_poll_interval() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-client/tests/it/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloy_node_bindings::Anvil;
use alloy_primitives::U64;
use alloy_rpc_client::{ClientBuilder, RpcCall};
use similar_asserts::assert_eq;

#[tokio::test]
async fn it_makes_a_request() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-client/tests/it/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloy_node_bindings::Anvil;
use alloy_primitives::U64;
use alloy_rpc_client::{ClientBuilder, RpcCall};
use alloy_transport_ws::WsConnect;
use similar_asserts::assert_eq;

#[tokio::test]
async fn it_makes_a_request() {
Expand Down
3 changes: 3 additions & 0 deletions crates/rpc-types-admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ alloy-primitives = { workspace = true, features = ["serde", "std"] }

serde.workspace = true
serde_json.workspace = true

[dev-dependencies]
similar-asserts.workspace = true
1 change: 1 addition & 0 deletions crates/rpc-types-admin/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ mod handshake {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn deserialize_peer_info() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ serde.workspace = true

[dev-dependencies]
serde_json.workspace = true
similar-asserts.workspace = true
1 change: 1 addition & 0 deletions crates/rpc-types-anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl Default for MineOptions {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn test_serde_forking_deserialization() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-beacon/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ pub struct PayloadAttributesData {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn serde_payload_attributes_event() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-beacon/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ pub mod beacon_payload {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn serde_get_payload_header_response() {
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc-types-beacon/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ pub mod error {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn serde_validator() {
Expand All @@ -435,7 +436,7 @@ mod tests {
let validators: Vec<Validator> = serde_json::from_str(s).unwrap();
let json: serde_json::Value = serde_json::from_str(s).unwrap();

similar_asserts::assert_eq!(json, serde_json::to_value(validators).unwrap());
assert_eq!(json, serde_json::to_value(validators).unwrap());
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-beacon/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct BlobData {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

/// Should deserialize json containing 6 blobs
#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-engine/src/identification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct ClientVersionV1 {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
#[cfg(feature = "serde")]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-engine/src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ mod tests {
use super::*;
use assert_matches::assert_matches;
use jsonwebtoken::{encode, EncodingKey, Header};
use similar_asserts::assert_eq;
#[cfg(feature = "std")]
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tempfile::tempdir;
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ impl std::error::Error for PayloadValidationError {}
mod tests {
use super::*;
use alloc::vec;
use similar_asserts::assert_eq;

#[test]
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -1325,7 +1326,7 @@ mod tests {
.to_string(),
},
};
similar_asserts::assert_eq!(q, serde_json::from_str(s).unwrap());
assert_eq!(q, serde_json::from_str(s).unwrap());
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ mod tests {
use alloy_primitives::keccak256;
use arbitrary::Arbitrary;
use rand::Rng;
use similar_asserts::assert_eq;

use super::*;

Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl<'de> serde::Deserialize<'de> for TransactionIndex {
mod tests {
use super::*;
use crate::BlockNumberOrTag;
use similar_asserts::assert_eq;

#[test]
#[cfg(feature = "serde")]
Expand Down
7 changes: 4 additions & 3 deletions crates/rpc-types-eth/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ impl<'a> serde::Deserialize<'a> for PendingTransactionFilterKind {
mod tests {
use super::*;
use serde_json::json;
use similar_asserts::assert_eq;

#[cfg(feature = "serde")]
fn serialize<T: serde::Serialize>(t: &T) -> serde_json::Value {
Expand All @@ -1180,7 +1181,7 @@ mod tests {
fn test_empty_filter_topics_list() {
let s = r#"{"fromBlock": "0xfc359e", "toBlock": "0xfc359e", "topics": [["0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"], [], ["0x0000000000000000000000000c17e776cd218252adfca8d4e761d3fe757e9778"]]}"#;
let filter = serde_json::from_str::<Filter>(s).unwrap();
similar_asserts::assert_eq!(
assert_eq!(
filter.topics,
[
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"
Expand Down Expand Up @@ -1228,7 +1229,7 @@ mod tests {
let s =
r#"{"blockHash":"0x58dc57ab582b282c143424bd01e8d923cddfdcda9455bad02a29522f6274a948"}"#;
let filter = serde_json::from_str::<Filter>(s).unwrap();
similar_asserts::assert_eq!(
assert_eq!(
filter.block_option,
FilterBlockOption::AtBlockHash(
"0x58dc57ab582b282c143424bd01e8d923cddfdcda9455bad02a29522f6274a948"
Expand All @@ -1243,7 +1244,7 @@ mod tests {
fn test_filter_topics_middle_wildcard() {
let s = r#"{"fromBlock": "0xfc359e", "toBlock": "0xfc359e", "topics": [["0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"], [], [null, "0x0000000000000000000000000c17e776cd218252adfca8d4e761d3fe757e9778"]]}"#;
let filter = serde_json::from_str::<Filter>(s).unwrap();
similar_asserts::assert_eq!(
assert_eq!(
filter.topics,
[
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mod tests {
use super::*;
use rand::{thread_rng, Rng};
use serde_json::json;
use similar_asserts::assert_eq;

#[test]
#[cfg(feature = "serde")]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ mod tests {
use super::*;
use arbitrary::Arbitrary;
use rand::Rng;
use similar_asserts::assert_eq;

#[test]
fn log_arbitrary() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl<'a> serde::Deserialize<'a> for Params {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
#[cfg(feature = "serde")]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ mod tests {
use super::*;
use alloy_primitives::{Address, TxKind};
use serde_json::json;
use similar_asserts::assert_eq;

#[test]
#[cfg(feature = "serde")]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl EvmOverrides {
mod tests {
use super::*;
use alloy_primitives::address;
use similar_asserts::assert_eq;

#[test]
fn test_default_account_override() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ mod tests {
use arbitrary::Arbitrary;
use core::str::FromStr;
use rand::Rng;
use similar_asserts::assert_eq;

#[test]
fn arbitrary_transaction() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/transaction/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ mod test {
use alloy_primitives::{address, b256, bloom, Bloom};
use arbitrary::Arbitrary;
use rand::Rng;
use similar_asserts::assert_eq;

#[test]
fn transaction_receipt_arbitrary() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ mod tests {
use alloy_primitives::b256;
use alloy_serde::WithOtherFields;
use assert_matches::assert_matches;
use similar_asserts::assert_eq;

// <https://github.com/paradigmxyz/reth/issues/6670>
#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-eth/src/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl From<alloy_primitives::Signature> for Signature {
mod tests {
use super::*;
use core::str::FromStr;
use similar_asserts::assert_eq;

#[test]
#[cfg(feature = "serde")]
Expand Down
3 changes: 3 additions & 0 deletions crates/rpc-types-mev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ alloy-serde.workspace = true
serde.workspace = true
serde_json.workspace = true

[dev-dependencies]
similar-asserts.workspace = true

[lints]
workspace = true
1 change: 1 addition & 0 deletions crates/rpc-types-mev/src/mev_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ mod tests {

use crate::{common::PrivacyHint, RefundConfig};
use alloy_primitives::Bytes;
use similar_asserts::assert_eq;

use super::*;

Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-mev/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub struct UserStats {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

use crate::SealedByBuildersAt;

Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl<Ok, Err> TraceResult<Ok, Err> {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
struct OkResult {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ mod tests {
use super::*;
use alloy_primitives::{Bytes, U256};
use serde_json::json;
use similar_asserts::assert_eq;

#[test]
fn test_parse_filter() {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/geth/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl FlatCallConfig {
mod tests {
use super::*;
use crate::geth::*;
use similar_asserts::assert_eq;

// See <https://github.com/ethereum/go-ethereum/tree/master/eth/tracers/internal/tracetest/testdata>
const DEFAULT: &str = include_str!("../../test_data/call_tracer/default.json");
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/geth/four_byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct FourByteFrame(pub BTreeMap<String, u64>);
mod tests {
use super::*;
use crate::geth::*;
use similar_asserts::assert_eq;

const DEFAULT: &str = r#"{
"0x27dc297e-128": 1,
Expand Down
5 changes: 3 additions & 2 deletions crates/rpc-types-trace/src/geth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ fn serialize_string_storage_map_opt<S: Serializer>(
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn test_tracer_config() {
Expand Down Expand Up @@ -724,7 +725,7 @@ mod tests {
let log: StructLog = serde_json::from_str(s).unwrap();
let val = serde_json::to_value(&log).unwrap();
let input = serde_json::from_str::<serde_json::Value>(s).unwrap();
similar_asserts::assert_eq!(input, val);
assert_eq!(input, val);
}

#[test]
Expand Down Expand Up @@ -752,7 +753,7 @@ mod tests {

let de = serde_json::to_value(&result).unwrap();
let val = serde_json::from_str::<serde_json::Value>(s).unwrap();
similar_asserts::assert_eq!(val, de);
assert_eq!(val, de);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/geth/mux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct MuxFrame(pub HashMap<GethDebugBuiltInTracerType, GethTrace>);
mod tests {
use super::*;
use crate::geth::*;
use similar_asserts::assert_eq;

const FOUR_BYTE_FRAME: &str = r#"{
"0x27dc297e-128": 1,
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/geth/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct NoopFrame(BTreeMap<(), ()>);
mod tests {
use super::*;
use crate::geth::*;
use similar_asserts::assert_eq;

const DEFAULT: &str = r"{}";

Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/geth/pre_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl PreStateConfig {
mod tests {
use super::*;
use crate::geth::*;
use similar_asserts::assert_eq;

// See <https://github.com/ethereum/go-ethereum/tree/master/eth/tracers/internal/tracetest/testdata>
const DEFAULT: &str = include_str!("../../test_data/pre_state_tracer/default.json");
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types-trace/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ pub struct ContractCreator {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn test_otterscan_receipt() {
Expand Down
Loading

0 comments on commit cc36e25

Please sign in to comment.