From 2a8189d7c9efe8d6e78e133280fa6440f5c4c1c7 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 25 Oct 2022 16:23:10 +0800 Subject: [PATCH] chore(db): Add tests and fuzz target to `BlockNumHash` (#130) * add tests and fuzz target for BlockNumHash * use block 1 for test_block_num_hash * new clippy stds * fmt --- Cargo.lock | 1 + bin/reth/src/test_eth_chain/mod.rs | 2 +- bin/reth/src/test_eth_chain/models.rs | 6 +- crates/common/rlp/benches/bench.rs | 2 +- crates/common/rlp/src/decode.rs | 4 +- crates/common/rlp/tests/rlp.rs | 2 +- crates/db/src/kv/mod.rs | 7 +- crates/interfaces/Cargo.toml | 2 + crates/interfaces/src/db/codecs/fuzz/mod.rs | 13 ++- crates/interfaces/src/db/container.rs | 1 - crates/interfaces/src/db/models/blocks.rs | 48 +++++++++- crates/interfaces/src/db/models/mod.rs | 2 + crates/net/ecies/src/algorithm.rs | 16 ++-- crates/net/ecies/src/stream.rs | 2 +- crates/net/eth-wire/src/types/message.rs | 2 +- crates/net/eth-wire/src/types/transactions.rs | 88 +++++++++---------- crates/net/rpc-types/src/eth/index.rs | 4 +- crates/net/rpc-types/src/eth/pubsub.rs | 2 +- crates/net/rpc/src/result.rs | 2 +- crates/primitives/src/header.rs | 14 +-- crates/primitives/src/integer_list.rs | 4 +- crates/primitives/src/jsonu256.rs | 4 +- 22 files changed, 141 insertions(+), 87 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d54ca2bd4..57464690e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2585,6 +2585,7 @@ dependencies = [ name = "reth-interfaces" version = "0.1.0" dependencies = [ + "arbitrary", "async-trait", "auto_impl", "bytes", diff --git a/bin/reth/src/test_eth_chain/mod.rs b/bin/reth/src/test_eth_chain/mod.rs index 41a21b129..0f70c211a 100644 --- a/bin/reth/src/test_eth_chain/mod.rs +++ b/bin/reth/src/test_eth_chain/mod.rs @@ -39,7 +39,7 @@ impl Command { } Err(error) => { num_of_failed += 1; - println!("Test {:?} failed:\n {error}\n", file); + println!("Test {file:?} failed:\n {error}\n"); } } } diff --git a/bin/reth/src/test_eth_chain/models.rs b/bin/reth/src/test_eth_chain/models.rs index 016b6b0dd..d0bd2503e 100644 --- a/bin/reth/src/test_eth_chain/models.rs +++ b/bin/reth/src/test_eth_chain/models.rs @@ -335,7 +335,7 @@ mod test { }"#; let res = serde_json::from_str::(test); - assert!(res.is_ok(), "Failed to deserialize BlockchainTestData with error: {:?}", res); + assert!(res.is_ok(), "Failed to deserialize BlockchainTestData with error: {res:?}"); } #[test] @@ -360,7 +360,7 @@ mod test { "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" }"#; let res = serde_json::from_str::
(test); - assert!(res.is_ok(), "Failed to deserialize Header with error: {:?}", res); + assert!(res.is_ok(), "Failed to deserialize Header with error: {res:?}"); } #[test] @@ -386,6 +386,6 @@ mod test { ]"#; let res = serde_json::from_str::>(test); - assert!(res.is_ok(), "Failed to deserialize transactin with error: {:?}", res); + assert!(res.is_ok(), "Failed to deserialize transactin with error: {res:?}"); } } diff --git a/crates/common/rlp/benches/bench.rs b/crates/common/rlp/benches/bench.rs index d29d7dfd7..34cb9c994 100644 --- a/crates/common/rlp/benches/bench.rs +++ b/crates/common/rlp/benches/bench.rs @@ -18,7 +18,7 @@ fn bench_encode(c: &mut Criterion) { c.bench_function("encode_u64", |b| { b.iter(|| { let mut out = BytesMut::new(); - let _ = 0x1023_4567_89ab_cdefu64.encode(&mut out); + 0x1023_4567_89ab_cdefu64.encode(&mut out); }) }); c.bench_function("encode_u256", |b| { diff --git a/crates/common/rlp/src/decode.rs b/crates/common/rlp/src/decode.rs index ca79616ce..068ce6a54 100644 --- a/crates/common/rlp/src/decode.rs +++ b/crates/common/rlp/src/decode.rs @@ -392,9 +392,9 @@ mod tests { #[test] fn rlp_strings() { check_decode::(vec![ - (Ok((&hex!("00")[..]).to_vec().into()), &hex!("00")[..]), + (Ok(hex!("00")[..].to_vec().into()), &hex!("00")[..]), ( - Ok((&hex!("6f62636465666768696a6b6c6d")[..]).to_vec().into()), + Ok(hex!("6f62636465666768696a6b6c6d")[..].to_vec().into()), &hex!("8D6F62636465666768696A6B6C6D")[..], ), (Err(DecodeError::UnexpectedList), &hex!("C0")[..]), diff --git a/crates/common/rlp/tests/rlp.rs b/crates/common/rlp/tests/rlp.rs index aa029c5a0..62a073ece 100644 --- a/crates/common/rlp/tests/rlp.rs +++ b/crates/common/rlp/tests/rlp.rs @@ -65,7 +65,7 @@ fn test_encode_item() { let decoded = Decodable::decode(&mut &*expected).unwrap(); assert_eq!(item, decoded); - let mut rlp_view = Rlp::new(&*expected).unwrap(); + let mut rlp_view = Rlp::new(&expected).unwrap(); assert_eq!(rlp_view.get_next().unwrap(), Some(item.a)); assert_eq!(rlp_view.get_next().unwrap(), Some(item.b)); assert_eq!(rlp_view.get_next().unwrap(), Some(item.c)); diff --git a/crates/db/src/kv/mod.rs b/crates/db/src/kv/mod.rs index 05dcfadfd..e8d55616c 100644 --- a/crates/db/src/kv/mod.rs +++ b/crates/db/src/kv/mod.rs @@ -240,17 +240,17 @@ mod tests { // PUT (0,0) let value00 = StorageEntry::default(); - env.update(|tx| tx.put::(key.into(), value00.clone()).expect(ERROR_PUT)) + env.update(|tx| tx.put::(key, value00.clone()).expect(ERROR_PUT)) .unwrap(); // PUT (2,2) let value22 = StorageEntry { key: H256::from_low_u64_be(2), value: U256::from(2) }; - env.update(|tx| tx.put::(key.into(), value22.clone()).expect(ERROR_PUT)) + env.update(|tx| tx.put::(key, value22.clone()).expect(ERROR_PUT)) .unwrap(); // PUT (1,1) let value11 = StorageEntry { key: H256::from_low_u64_be(1), value: U256::from(1) }; - env.update(|tx| tx.put::(key.into(), value11.clone()).expect(ERROR_PUT)) + env.update(|tx| tx.put::(key, value11.clone()).expect(ERROR_PUT)) .unwrap(); // GET DUPSORT @@ -283,7 +283,6 @@ mod gat_tests { impl<'c, DB: Database> Stage for MyStage<'c, DB> { async fn run(&mut self, db: &mut DBContainer<'_, DB>) -> () { let _tx = db.commit().unwrap(); - () } } diff --git a/crates/interfaces/Cargo.toml b/crates/interfaces/Cargo.toml index 5360495fb..1e6f8a915 100644 --- a/crates/interfaces/Cargo.toml +++ b/crates/interfaces/Cargo.toml @@ -24,11 +24,13 @@ parity-scale-codec = { version = "3.2.1", features = ["bytes"] } futures = "0.3.25" tokio-stream = "0.1.11" rand = "0.8.5" +arbitrary = { version = "1.1.7", features = ["derive"], optional = true} [dev-dependencies] test-fuzz = "3.0.4" tokio = { version = "1.21.2", features = ["full"] } tokio-stream = { version = "0.1.11", features = ["sync"] } +arbitrary = { version = "1.1.7", features = ["derive"]} [features] bench = [] diff --git a/crates/interfaces/src/db/codecs/fuzz/mod.rs b/crates/interfaces/src/db/codecs/fuzz/mod.rs index 15b24dbaf..72f88244e 100644 --- a/crates/interfaces/src/db/codecs/fuzz/mod.rs +++ b/crates/interfaces/src/db/codecs/fuzz/mod.rs @@ -14,19 +14,26 @@ macro_rules! impl_fuzzer_with_input { #[allow(non_snake_case)] #[cfg(any(test, feature = "bench"))] pub mod $name { - use reth_primitives::$name; use crate::db::table; + #[allow(unused_imports)] + use reth_primitives::*; + #[allow(unused_imports)] use super::inputs::*; + #[allow(unused_imports)] + use crate::db::models::*; + /// Encodes and decodes table types returning its encoded size and the decoded object. /// This method is used for benchmarking, so its parameter should be the actual type that is being tested. pub fn encode_and_decode(obj: $name) -> (usize, $name) { let data = table::Encode::encode(obj); let size = data.len(); - (size, table::Decode::decode(data).expect("failed to decode")) + + // Some `data` might be a fixed array. + (size, table::Decode::decode(data.to_vec()).expect("failed to decode")) } #[cfg(test)] @@ -57,6 +64,6 @@ macro_rules! impl_fuzzer { }; } -impl_fuzzer!(Header, Account); +impl_fuzzer!(Header, Account, BlockNumHash); impl_fuzzer_with_input!((IntegerList, IntegerListInput)); diff --git a/crates/interfaces/src/db/container.rs b/crates/interfaces/src/db/container.rs index 3f0f57fe2..f3a55b34a 100644 --- a/crates/interfaces/src/db/container.rs +++ b/crates/interfaces/src/db/container.rs @@ -84,7 +84,6 @@ mod tests { impl<'a, DB: Database> Stage for MyStage<'a, DB> { async fn run(&mut self, db: &mut DBContainer<'_, DB>) -> () { let _tx = db.commit().unwrap(); - () } } diff --git a/crates/interfaces/src/db/models/blocks.rs b/crates/interfaces/src/db/models/blocks.rs index d17f2f7ff..4502fa041 100644 --- a/crates/interfaces/src/db/models/blocks.rs +++ b/crates/interfaces/src/db/models/blocks.rs @@ -7,6 +7,7 @@ use crate::db::{ use bytes::Bytes; use eyre::eyre; use reth_primitives::{BlockHash, BlockNumber, H256}; +use serde::{Deserialize, Serialize}; /// Total chain number of transactions. Key for [`CumulativeTxCount`]. pub type NumTransactions = u64; @@ -21,8 +22,7 @@ pub type HeaderHash = H256; /// element as BlockNumber, helps out with querying/sorting. /// /// Since it's used as a key, the `BlockNumber` is not compressed when encoding it. -#[derive(Debug, Clone, PartialEq, Eq)] -#[allow(non_camel_case_types)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] pub struct BlockNumHash((BlockNumber, BlockHash)); impl BlockNumHash { @@ -67,3 +67,47 @@ impl Decode for BlockNumHash { Ok(BlockNumHash((num, hash))) } } + +#[cfg(any(test, feature = "arbitrary"))] +use arbitrary::{Arbitrary, Unstructured}; + +#[cfg(any(test, feature = "arbitrary"))] +impl<'a> Arbitrary<'a> for BlockNumHash { + fn arbitrary(u: &mut Unstructured<'a>) -> Result { + let mut buffer = vec![0; 40]; + u.fill_buffer(buffer.as_mut_slice())?; + + Decode::decode(buffer).map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + +#[cfg(test)] +mod test { + use super::*; + use rand::{thread_rng, Rng}; + + #[test] + fn test_block_num_hash() { + let num = 1u64; + let hash = H256::from_low_u64_be(2); + let key = BlockNumHash((num, hash)); + + let mut bytes = [0u8; 40]; + bytes[..8].copy_from_slice(&num.to_be_bytes()); + bytes[8..].copy_from_slice(&hash.0); + + let encoded = Encode::encode(key.clone()); + assert!(encoded == bytes); + + let decoded: BlockNumHash = Decode::decode(encoded.to_vec()).unwrap(); + assert!(decoded == key); + } + + #[test] + fn test_block_num_hash_rand() { + let mut bytes = [0u8; 40]; + thread_rng().fill(bytes.as_mut_slice()); + let key = BlockNumHash::arbitrary(&mut Unstructured::new(&bytes)).unwrap(); + assert!(bytes == Encode::encode(key)); + } +} diff --git a/crates/interfaces/src/db/models/mod.rs b/crates/interfaces/src/db/models/mod.rs index 4c0933f9f..8dffa195a 100644 --- a/crates/interfaces/src/db/models/mod.rs +++ b/crates/interfaces/src/db/models/mod.rs @@ -2,3 +2,5 @@ pub mod blocks; pub mod integer_list; + +pub use blocks::*; diff --git a/crates/net/ecies/src/algorithm.rs b/crates/net/ecies/src/algorithm.rs index e1b15915d..f28b3bec4 100644 --- a/crates/net/ecies/src/algorithm.rs +++ b/crates/net/ecies/src/algorithm.rs @@ -489,7 +489,7 @@ impl ECIES { if body_size > MAX_BODY_SIZE { return Err(ECIESError::IO(io::Error::new( io::ErrorKind::InvalidInput, - format!("body size ({}) exceeds limit ({} bytes)", body_size, MAX_BODY_SIZE), + format!("body size ({body_size}) exceeds limit ({MAX_BODY_SIZE} bytes)"), ))) } @@ -587,15 +587,15 @@ mod tests { // Test server to client 1 let mut header = server_ecies.create_header(server_to_client_data.len()); assert_eq!(header.len(), ECIES::header_len()); - client_ecies.read_header(&mut *header).unwrap(); + client_ecies.read_header(&mut header).unwrap(); let mut body = server_ecies.create_body(&server_to_client_data); assert_eq!(body.len(), client_ecies.body_len()); - let ret = client_ecies.read_body(&mut *body).unwrap(); + let ret = client_ecies.read_body(&mut body).unwrap(); assert_eq!(ret, server_to_client_data); // Test client to server 1 server_ecies - .read_header(&mut *client_ecies.create_header(client_to_server_data.len())) + .read_header(&mut client_ecies.create_header(client_to_server_data.len())) .unwrap(); let mut b = client_ecies.create_body(&client_to_server_data); let ret = server_ecies.read_body(&mut b).unwrap(); @@ -603,7 +603,7 @@ mod tests { // Test server to client 2 client_ecies - .read_header(&mut *server_ecies.create_header(server_to_client_data.len())) + .read_header(&mut server_ecies.create_header(server_to_client_data.len())) .unwrap(); let mut b = server_ecies.create_body(&server_to_client_data); let ret = client_ecies.read_body(&mut b).unwrap(); @@ -611,7 +611,7 @@ mod tests { // Test server to client 3 client_ecies - .read_header(&mut *server_ecies.create_header(server_to_client_data.len())) + .read_header(&mut server_ecies.create_header(server_to_client_data.len())) .unwrap(); let mut b = server_ecies.create_body(&server_to_client_data); let ret = client_ecies.read_body(&mut b).unwrap(); @@ -619,7 +619,7 @@ mod tests { // Test client to server 2 server_ecies - .read_header(&mut *client_ecies.create_header(client_to_server_data.len())) + .read_header(&mut client_ecies.create_header(client_to_server_data.len())) .unwrap(); let mut b = client_ecies.create_body(&client_to_server_data); let ret = server_ecies.read_body(&mut b).unwrap(); @@ -627,7 +627,7 @@ mod tests { // Test client to server 3 server_ecies - .read_header(&mut *client_ecies.create_header(client_to_server_data.len())) + .read_header(&mut client_ecies.create_header(client_to_server_data.len())) .unwrap(); let mut b = client_ecies.create_body(&client_to_server_data); let ret = server_ecies.read_body(&mut b).unwrap(); diff --git a/crates/net/ecies/src/stream.rs b/crates/net/ecies/src/stream.rs index 10aa457a3..f9738f4aa 100644 --- a/crates/net/ecies/src/stream.rs +++ b/crates/net/ecies/src/stream.rs @@ -111,7 +111,7 @@ where Some(Ok(IngressECIESValue::Message(body))) => Poll::Ready(Some(Ok(body))), Some(other) => Poll::Ready(Some(Err(io::Error::new( io::ErrorKind::Other, - format!("ECIES stream protocol error: expected message, received {:?}", other), + format!("ECIES stream protocol error: expected message, received {other:?}"), )))), None => Poll::Ready(None), } diff --git a/crates/net/eth-wire/src/types/message.rs b/crates/net/eth-wire/src/types/message.rs index 573d482b6..3fbcc0863 100644 --- a/crates/net/eth-wire/src/types/message.rs +++ b/crates/net/eth-wire/src/types/message.rs @@ -353,7 +353,7 @@ mod test { // 05: 5 (message) let expected = hex!("c5820539c105"); let got = encode(request_pair); - assert_eq!(expected[..], got, "expected: {:X?}, got: {:X?}", expected, got,); + assert_eq!(expected[..], got, "expected: {expected:X?}, got: {got:X?}",); } #[test] diff --git a/crates/net/eth-wire/src/types/transactions.rs b/crates/net/eth-wire/src/types/transactions.rs index 69adf36a0..d99b38ea0 100644 --- a/crates/net/eth-wire/src/types/transactions.rs +++ b/crates/net/eth-wire/src/types/transactions.rs @@ -144,9 +144,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(1), - nonce: 0x8u64.into(), - gas_price: 0x4a817c808u64.into(), - gas_limit: 0x2e248u64.into(), + nonce: 0x8u64, + gas_price: 0x4a817c808u64, + gas_limit: 0x2e248u64, to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), @@ -168,9 +168,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(1), - nonce: 0x09u64.into(), - gas_price: 0x4a817c809u64.into(), - gas_limit: 0x33450u64.into(), + nonce: 0x09u64, + gas_price: 0x4a817c809u64, + gas_limit: 0x33450u64, to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), @@ -206,9 +206,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(1), - nonce: 0x8u64.into(), - gas_price: 0x4a817c808u64.into(), - gas_limit: 0x2e248u64.into(), + nonce: 0x8u64, + gas_price: 0x4a817c808u64, + gas_limit: 0x2e248u64, to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), @@ -230,9 +230,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(1), - nonce: 0x09u64.into(), - gas_price: 0x4a817c809u64.into(), - gas_limit: 0x33450u64.into(), + nonce: 0x09u64, + gas_price: 0x4a817c809u64, + gas_limit: 0x33450u64, to: TransactionKind::Call( hex!("3535353535353535353535353535353535353535").into(), ), @@ -271,9 +271,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 15u64.into(), - gas_price: 2200000000u64.into(), - gas_limit: 34811u64.into(), + nonce: 15u64, + gas_price: 2200000000u64, + gas_limit: 34811u64, to: TransactionKind::Call( hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(), ), @@ -295,10 +295,10 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Eip1559 { chain_id: 4, - nonce: 26u64.into(), - max_priority_fee_per_gas: 1500000000u64.into(), - max_fee_per_gas: 1500000013u64.into(), - gas_limit: 21000u64.into(), + nonce: 26u64, + max_priority_fee_per_gas: 1500000000u64, + max_fee_per_gas: 1500000013u64, + gas_limit: 21000u64, to: TransactionKind::Call( hex!("61815774383099e24810ab832a5b2a5425c154d5").into(), ), @@ -321,9 +321,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 3u64.into(), - gas_price: 2000000000u64.into(), - gas_limit: 10000000u64.into(), + nonce: 3u64, + gas_price: 2000000000u64, + gas_limit: 10000000u64, to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), @@ -345,9 +345,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 1u64.into(), - gas_price: 1000000000u64.into(), - gas_limit: 100000u64.into(), + nonce: 1u64, + gas_price: 1000000000u64, + gas_limit: 100000u64, to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), @@ -369,9 +369,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 2u64.into(), - gas_price: 1000000000u64.into(), - gas_limit: 100000u64.into(), + nonce: 2u64, + gas_price: 1000000000u64, + gas_limit: 100000u64, to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), @@ -414,9 +414,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 15u64.into(), - gas_price: 2200000000u64.into(), - gas_limit: 34811u64.into(), + nonce: 15u64, + gas_price: 2200000000u64, + gas_limit: 34811u64, to: TransactionKind::Call( hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(), ), @@ -438,10 +438,10 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Eip1559 { chain_id: 4, - nonce: 26u64.into(), - max_priority_fee_per_gas: 1500000000u64.into(), - max_fee_per_gas: 1500000013u64.into(), - gas_limit: 21000u64.into(), + nonce: 26u64, + max_priority_fee_per_gas: 1500000000u64, + max_fee_per_gas: 1500000013u64, + gas_limit: 21000u64, to: TransactionKind::Call( hex!("61815774383099e24810ab832a5b2a5425c154d5").into(), ), @@ -464,9 +464,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 3u64.into(), - gas_price: 2000000000u64.into(), - gas_limit: 10000000u64.into(), + nonce: 3u64, + gas_price: 2000000000u64, + gas_limit: 10000000u64, to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), @@ -488,9 +488,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 1u64.into(), - gas_price: 1000000000u64.into(), - gas_limit: 100000u64.into(), + nonce: 1u64, + gas_price: 1000000000u64, + gas_limit: 100000u64, to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), @@ -512,9 +512,9 @@ mod test { TransactionSigned::from_transaction_and_signature( Transaction::Legacy { chain_id: Some(4), - nonce: 2u64.into(), - gas_price: 1000000000u64.into(), - gas_limit: 100000u64.into(), + nonce: 2u64, + gas_price: 1000000000u64, + gas_limit: 100000u64, to: TransactionKind::Call( hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), ), diff --git a/crates/net/rpc-types/src/eth/index.rs b/crates/net/rpc-types/src/eth/index.rs index 81a83f58d..8e889e6c5 100644 --- a/crates/net/rpc-types/src/eth/index.rs +++ b/crates/net/rpc-types/src/eth/index.rs @@ -50,13 +50,13 @@ impl<'a> Deserialize<'a> for Index { { if let Some(val) = value.strip_prefix("0x") { usize::from_str_radix(val, 16).map(Index).map_err(|e| { - Error::custom(format!("Failed to parse hex encoded index value: {}", e)) + Error::custom(format!("Failed to parse hex encoded index value: {e}")) }) } else { value .parse::() .map(Index) - .map_err(|e| Error::custom(format!("Failed to parse numeric index: {}", e))) + .map_err(|e| Error::custom(format!("Failed to parse numeric index: {e}"))) } } diff --git a/crates/net/rpc-types/src/eth/pubsub.rs b/crates/net/rpc-types/src/eth/pubsub.rs index 8b237b49d..29605bf0a 100644 --- a/crates/net/rpc-types/src/eth/pubsub.rs +++ b/crates/net/rpc-types/src/eth/pubsub.rs @@ -104,6 +104,6 @@ impl<'a> Deserialize<'a> for Params { serde_json::from_value(v) .map(|f| Params::Logs(Box::new(f))) - .map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {}", e))) + .map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {e}"))) } } diff --git a/crates/net/rpc/src/result.rs b/crates/net/rpc/src/result.rs index b41b6c0c2..aec3af029 100644 --- a/crates/net/rpc/src/result.rs +++ b/crates/net/rpc/src/result.rs @@ -78,7 +78,7 @@ impl ToRpcResult for reth_interfaces::Result match self { Ok(t) => Ok(t), Err(err) => { - let msg = format!("{}: {:?}", msg, err); + let msg = format!("{msg}: {err:?}"); Err(internal_rpc_err(msg)) } } diff --git a/crates/primitives/src/header.rs b/crates/primitives/src/header.rs index 8ed4a185d..28c26a7b0 100644 --- a/crates/primitives/src/header.rs +++ b/crates/primitives/src/header.rs @@ -261,14 +261,14 @@ mod tests { receipts_root: H256::from_str("29b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9").unwrap(), logs_bloom: <[u8; 256]>::from_hex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap().into(), difficulty: 0x020000.into(), - number: 0x01_u64.into(), - gas_limit: 0x016345785d8a0000_u64.into(), - gas_used: 0x015534_u64.into(), + number: 0x01_u64, + gas_limit: 0x016345785d8a0000_u64, + gas_used: 0x015534_u64, timestamp: 0x079e, extra_data: Bytes::from_str("42").unwrap().0, mix_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(), nonce: 0, - base_fee_per_gas: Some(0x036b_u64.into()), + base_fee_per_gas: Some(0x036b_u64), }; assert_eq!(header.hash_slow(), expected_hash); } @@ -279,9 +279,9 @@ mod tests { let data = hex::decode("f901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000").unwrap(); let expected = Header { difficulty: 0x8aeu64.into(), - number: 0xd05u64.into(), - gas_limit: 0x115cu64.into(), - gas_used: 0x15b3u64.into(), + number: 0xd05u64, + gas_limit: 0x115cu64, + gas_used: 0x15b3u64, timestamp: 0x1a0au64, extra_data: Bytes::from_str("7788").unwrap().0, ..Default::default() diff --git a/crates/primitives/src/integer_list.rs b/crates/primitives/src/integer_list.rs index 880c0e2e3..332df4343 100644 --- a/crates/primitives/src/integer_list.rs +++ b/crates/primitives/src/integer_list.rs @@ -111,7 +111,7 @@ mod test { fn test_integer_list() { let original_list = [1, 2, 3]; - let ef_list = IntegerList::new(&original_list).unwrap(); + let ef_list = IntegerList::new(original_list).unwrap(); assert!(ef_list.iter(0).collect::>() == original_list); } @@ -119,7 +119,7 @@ mod test { #[test] fn test_integer_list_serialization() { let original_list = [1, 2, 3]; - let ef_list = IntegerList::new(&original_list).unwrap(); + let ef_list = IntegerList::new(original_list).unwrap(); let blist = ef_list.to_bytes(); assert!(IntegerList::from_bytes(&blist).unwrap() == ef_list) diff --git a/crates/primitives/src/jsonu256.rs b/crates/primitives/src/jsonu256.rs index 70d2f57a5..e88e7faca 100644 --- a/crates/primitives/src/jsonu256.rs +++ b/crates/primitives/src/jsonu256.rs @@ -51,10 +51,10 @@ impl<'a> Visitor<'a> for JsonU256Visitor { 0 => U256::from(0), 2 if value.starts_with("0x") => U256::zero(), _ if value.starts_with("0x") => U256::from_str(&value[2..]).map_err(|e| { - Error::custom(format!("Parsin JsonU256 as hex failed {}: {}", value, e)) + Error::custom(format!("Parsin JsonU256 as hex failed {value}: {e}")) })?, _ => U256::from_dec_str(value).map_err(|e| { - Error::custom(format!("Parsin JsonU256 as decimal failed {}: {:?}", value, e)) + Error::custom(format!("Parsin JsonU256 as decimal failed {value}: {e:?}")) })?, };