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
This commit is contained in:
joshieDo
2022-10-25 16:23:10 +08:00
committed by GitHub
parent 0998fc3eb7
commit 2a8189d7c9
22 changed files with 141 additions and 87 deletions

1
Cargo.lock generated
View File

@ -2585,6 +2585,7 @@ dependencies = [
name = "reth-interfaces" name = "reth-interfaces"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"arbitrary",
"async-trait", "async-trait",
"auto_impl", "auto_impl",
"bytes", "bytes",

View File

@ -39,7 +39,7 @@ impl Command {
} }
Err(error) => { Err(error) => {
num_of_failed += 1; num_of_failed += 1;
println!("Test {:?} failed:\n {error}\n", file); println!("Test {file:?} failed:\n {error}\n");
} }
} }
} }

View File

@ -335,7 +335,7 @@ mod test {
}"#; }"#;
let res = serde_json::from_str::<Test>(test); let res = serde_json::from_str::<Test>(test);
assert!(res.is_ok(), "Failed to deserialize BlockchainTestData with error: {:?}", res); assert!(res.is_ok(), "Failed to deserialize BlockchainTestData with error: {res:?}");
} }
#[test] #[test]
@ -360,7 +360,7 @@ mod test {
"uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" "uncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
}"#; }"#;
let res = serde_json::from_str::<Header>(test); let res = serde_json::from_str::<Header>(test);
assert!(res.is_ok(), "Failed to deserialize Header with error: {:?}", res); assert!(res.is_ok(), "Failed to deserialize Header with error: {res:?}");
} }
#[test] #[test]
@ -386,6 +386,6 @@ mod test {
]"#; ]"#;
let res = serde_json::from_str::<Vec<Transaction>>(test); let res = serde_json::from_str::<Vec<Transaction>>(test);
assert!(res.is_ok(), "Failed to deserialize transactin with error: {:?}", res); assert!(res.is_ok(), "Failed to deserialize transactin with error: {res:?}");
} }
} }

View File

@ -18,7 +18,7 @@ fn bench_encode(c: &mut Criterion) {
c.bench_function("encode_u64", |b| { c.bench_function("encode_u64", |b| {
b.iter(|| { b.iter(|| {
let mut out = BytesMut::new(); 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| { c.bench_function("encode_u256", |b| {

View File

@ -392,9 +392,9 @@ mod tests {
#[test] #[test]
fn rlp_strings() { fn rlp_strings() {
check_decode::<Bytes, _>(vec![ check_decode::<Bytes, _>(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")[..], &hex!("8D6F62636465666768696A6B6C6D")[..],
), ),
(Err(DecodeError::UnexpectedList), &hex!("C0")[..]), (Err(DecodeError::UnexpectedList), &hex!("C0")[..]),

View File

@ -65,7 +65,7 @@ fn test_encode_item() {
let decoded = Decodable::decode(&mut &*expected).unwrap(); let decoded = Decodable::decode(&mut &*expected).unwrap();
assert_eq!(item, decoded); 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.a));
assert_eq!(rlp_view.get_next().unwrap(), Some(item.b)); assert_eq!(rlp_view.get_next().unwrap(), Some(item.b));
assert_eq!(rlp_view.get_next().unwrap(), Some(item.c)); assert_eq!(rlp_view.get_next().unwrap(), Some(item.c));

View File

@ -240,17 +240,17 @@ mod tests {
// PUT (0,0) // PUT (0,0)
let value00 = StorageEntry::default(); let value00 = StorageEntry::default();
env.update(|tx| tx.put::<PlainStorageState>(key.into(), value00.clone()).expect(ERROR_PUT)) env.update(|tx| tx.put::<PlainStorageState>(key, value00.clone()).expect(ERROR_PUT))
.unwrap(); .unwrap();
// PUT (2,2) // PUT (2,2)
let value22 = StorageEntry { key: H256::from_low_u64_be(2), value: U256::from(2) }; let value22 = StorageEntry { key: H256::from_low_u64_be(2), value: U256::from(2) };
env.update(|tx| tx.put::<PlainStorageState>(key.into(), value22.clone()).expect(ERROR_PUT)) env.update(|tx| tx.put::<PlainStorageState>(key, value22.clone()).expect(ERROR_PUT))
.unwrap(); .unwrap();
// PUT (1,1) // PUT (1,1)
let value11 = StorageEntry { key: H256::from_low_u64_be(1), value: U256::from(1) }; let value11 = StorageEntry { key: H256::from_low_u64_be(1), value: U256::from(1) };
env.update(|tx| tx.put::<PlainStorageState>(key.into(), value11.clone()).expect(ERROR_PUT)) env.update(|tx| tx.put::<PlainStorageState>(key, value11.clone()).expect(ERROR_PUT))
.unwrap(); .unwrap();
// GET DUPSORT // GET DUPSORT
@ -283,7 +283,6 @@ mod gat_tests {
impl<'c, DB: Database> Stage<DB> for MyStage<'c, DB> { impl<'c, DB: Database> Stage<DB> for MyStage<'c, DB> {
async fn run(&mut self, db: &mut DBContainer<'_, DB>) -> () { async fn run(&mut self, db: &mut DBContainer<'_, DB>) -> () {
let _tx = db.commit().unwrap(); let _tx = db.commit().unwrap();
()
} }
} }

View File

@ -24,11 +24,13 @@ parity-scale-codec = { version = "3.2.1", features = ["bytes"] }
futures = "0.3.25" futures = "0.3.25"
tokio-stream = "0.1.11" tokio-stream = "0.1.11"
rand = "0.8.5" rand = "0.8.5"
arbitrary = { version = "1.1.7", features = ["derive"], optional = true}
[dev-dependencies] [dev-dependencies]
test-fuzz = "3.0.4" test-fuzz = "3.0.4"
tokio = { version = "1.21.2", features = ["full"] } tokio = { version = "1.21.2", features = ["full"] }
tokio-stream = { version = "0.1.11", features = ["sync"] } tokio-stream = { version = "0.1.11", features = ["sync"] }
arbitrary = { version = "1.1.7", features = ["derive"]}
[features] [features]
bench = [] bench = []

View File

@ -14,19 +14,26 @@ macro_rules! impl_fuzzer_with_input {
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[cfg(any(test, feature = "bench"))] #[cfg(any(test, feature = "bench"))]
pub mod $name { pub mod $name {
use reth_primitives::$name;
use crate::db::table; use crate::db::table;
#[allow(unused_imports)]
use reth_primitives::*;
#[allow(unused_imports)] #[allow(unused_imports)]
use super::inputs::*; use super::inputs::*;
#[allow(unused_imports)]
use crate::db::models::*;
/// Encodes and decodes table types returning its encoded size and the decoded object. /// 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. /// 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) pub fn encode_and_decode(obj: $name) -> (usize, $name)
{ {
let data = table::Encode::encode(obj); let data = table::Encode::encode(obj);
let size = data.len(); 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)] #[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)); impl_fuzzer_with_input!((IntegerList, IntegerListInput));

View File

@ -84,7 +84,6 @@ mod tests {
impl<'a, DB: Database> Stage<DB> for MyStage<'a, DB> { impl<'a, DB: Database> Stage<DB> for MyStage<'a, DB> {
async fn run(&mut self, db: &mut DBContainer<'_, DB>) -> () { async fn run(&mut self, db: &mut DBContainer<'_, DB>) -> () {
let _tx = db.commit().unwrap(); let _tx = db.commit().unwrap();
()
} }
} }

View File

@ -7,6 +7,7 @@ use crate::db::{
use bytes::Bytes; use bytes::Bytes;
use eyre::eyre; use eyre::eyre;
use reth_primitives::{BlockHash, BlockNumber, H256}; use reth_primitives::{BlockHash, BlockNumber, H256};
use serde::{Deserialize, Serialize};
/// Total chain number of transactions. Key for [`CumulativeTxCount`]. /// Total chain number of transactions. Key for [`CumulativeTxCount`].
pub type NumTransactions = u64; pub type NumTransactions = u64;
@ -21,8 +22,7 @@ pub type HeaderHash = H256;
/// element as BlockNumber, helps out with querying/sorting. /// element as BlockNumber, helps out with querying/sorting.
/// ///
/// Since it's used as a key, the `BlockNumber` is not compressed when encoding it. /// Since it's used as a key, the `BlockNumber` is not compressed when encoding it.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[allow(non_camel_case_types)]
pub struct BlockNumHash((BlockNumber, BlockHash)); pub struct BlockNumHash((BlockNumber, BlockHash));
impl BlockNumHash { impl BlockNumHash {
@ -67,3 +67,47 @@ impl Decode for BlockNumHash {
Ok(BlockNumHash((num, hash))) 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<Self, arbitrary::Error> {
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));
}
}

View File

@ -2,3 +2,5 @@
pub mod blocks; pub mod blocks;
pub mod integer_list; pub mod integer_list;
pub use blocks::*;

View File

@ -489,7 +489,7 @@ impl ECIES {
if body_size > MAX_BODY_SIZE { if body_size > MAX_BODY_SIZE {
return Err(ECIESError::IO(io::Error::new( return Err(ECIESError::IO(io::Error::new(
io::ErrorKind::InvalidInput, 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 // Test server to client 1
let mut header = server_ecies.create_header(server_to_client_data.len()); let mut header = server_ecies.create_header(server_to_client_data.len());
assert_eq!(header.len(), ECIES::header_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); let mut body = server_ecies.create_body(&server_to_client_data);
assert_eq!(body.len(), client_ecies.body_len()); 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); assert_eq!(ret, server_to_client_data);
// Test client to server 1 // Test client to server 1
server_ecies 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(); .unwrap();
let mut b = client_ecies.create_body(&client_to_server_data); let mut b = client_ecies.create_body(&client_to_server_data);
let ret = server_ecies.read_body(&mut b).unwrap(); let ret = server_ecies.read_body(&mut b).unwrap();
@ -603,7 +603,7 @@ mod tests {
// Test server to client 2 // Test server to client 2
client_ecies 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(); .unwrap();
let mut b = server_ecies.create_body(&server_to_client_data); let mut b = server_ecies.create_body(&server_to_client_data);
let ret = client_ecies.read_body(&mut b).unwrap(); let ret = client_ecies.read_body(&mut b).unwrap();
@ -611,7 +611,7 @@ mod tests {
// Test server to client 3 // Test server to client 3
client_ecies 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(); .unwrap();
let mut b = server_ecies.create_body(&server_to_client_data); let mut b = server_ecies.create_body(&server_to_client_data);
let ret = client_ecies.read_body(&mut b).unwrap(); let ret = client_ecies.read_body(&mut b).unwrap();
@ -619,7 +619,7 @@ mod tests {
// Test client to server 2 // Test client to server 2
server_ecies 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(); .unwrap();
let mut b = client_ecies.create_body(&client_to_server_data); let mut b = client_ecies.create_body(&client_to_server_data);
let ret = server_ecies.read_body(&mut b).unwrap(); let ret = server_ecies.read_body(&mut b).unwrap();
@ -627,7 +627,7 @@ mod tests {
// Test client to server 3 // Test client to server 3
server_ecies 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(); .unwrap();
let mut b = client_ecies.create_body(&client_to_server_data); let mut b = client_ecies.create_body(&client_to_server_data);
let ret = server_ecies.read_body(&mut b).unwrap(); let ret = server_ecies.read_body(&mut b).unwrap();

View File

@ -111,7 +111,7 @@ where
Some(Ok(IngressECIESValue::Message(body))) => Poll::Ready(Some(Ok(body))), Some(Ok(IngressECIESValue::Message(body))) => Poll::Ready(Some(Ok(body))),
Some(other) => Poll::Ready(Some(Err(io::Error::new( Some(other) => Poll::Ready(Some(Err(io::Error::new(
io::ErrorKind::Other, 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), None => Poll::Ready(None),
} }

View File

@ -353,7 +353,7 @@ mod test {
// 05: 5 (message) // 05: 5 (message)
let expected = hex!("c5820539c105"); let expected = hex!("c5820539c105");
let got = encode(request_pair); 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] #[test]

View File

@ -144,9 +144,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(1), chain_id: Some(1),
nonce: 0x8u64.into(), nonce: 0x8u64,
gas_price: 0x4a817c808u64.into(), gas_price: 0x4a817c808u64,
gas_limit: 0x2e248u64.into(), gas_limit: 0x2e248u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(), hex!("3535353535353535353535353535353535353535").into(),
), ),
@ -168,9 +168,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(1), chain_id: Some(1),
nonce: 0x09u64.into(), nonce: 0x09u64,
gas_price: 0x4a817c809u64.into(), gas_price: 0x4a817c809u64,
gas_limit: 0x33450u64.into(), gas_limit: 0x33450u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(), hex!("3535353535353535353535353535353535353535").into(),
), ),
@ -206,9 +206,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(1), chain_id: Some(1),
nonce: 0x8u64.into(), nonce: 0x8u64,
gas_price: 0x4a817c808u64.into(), gas_price: 0x4a817c808u64,
gas_limit: 0x2e248u64.into(), gas_limit: 0x2e248u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(), hex!("3535353535353535353535353535353535353535").into(),
), ),
@ -230,9 +230,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(1), chain_id: Some(1),
nonce: 0x09u64.into(), nonce: 0x09u64,
gas_price: 0x4a817c809u64.into(), gas_price: 0x4a817c809u64,
gas_limit: 0x33450u64.into(), gas_limit: 0x33450u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("3535353535353535353535353535353535353535").into(), hex!("3535353535353535353535353535353535353535").into(),
), ),
@ -271,9 +271,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 15u64.into(), nonce: 15u64,
gas_price: 2200000000u64.into(), gas_price: 2200000000u64,
gas_limit: 34811u64.into(), gas_limit: 34811u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(), hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
), ),
@ -295,10 +295,10 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Eip1559 { Transaction::Eip1559 {
chain_id: 4, chain_id: 4,
nonce: 26u64.into(), nonce: 26u64,
max_priority_fee_per_gas: 1500000000u64.into(), max_priority_fee_per_gas: 1500000000u64,
max_fee_per_gas: 1500000013u64.into(), max_fee_per_gas: 1500000013u64,
gas_limit: 21000u64.into(), gas_limit: 21000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(), hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
), ),
@ -321,9 +321,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 3u64.into(), nonce: 3u64,
gas_price: 2000000000u64.into(), gas_price: 2000000000u64,
gas_limit: 10000000u64.into(), gas_limit: 10000000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
), ),
@ -345,9 +345,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 1u64.into(), nonce: 1u64,
gas_price: 1000000000u64.into(), gas_price: 1000000000u64,
gas_limit: 100000u64.into(), gas_limit: 100000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
), ),
@ -369,9 +369,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 2u64.into(), nonce: 2u64,
gas_price: 1000000000u64.into(), gas_price: 1000000000u64,
gas_limit: 100000u64.into(), gas_limit: 100000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
), ),
@ -414,9 +414,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 15u64.into(), nonce: 15u64,
gas_price: 2200000000u64.into(), gas_price: 2200000000u64,
gas_limit: 34811u64.into(), gas_limit: 34811u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(), hex!("cf7f9e66af820a19257a2108375b180b0ec49167").into(),
), ),
@ -438,10 +438,10 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Eip1559 { Transaction::Eip1559 {
chain_id: 4, chain_id: 4,
nonce: 26u64.into(), nonce: 26u64,
max_priority_fee_per_gas: 1500000000u64.into(), max_priority_fee_per_gas: 1500000000u64,
max_fee_per_gas: 1500000013u64.into(), max_fee_per_gas: 1500000013u64,
gas_limit: 21000u64.into(), gas_limit: 21000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("61815774383099e24810ab832a5b2a5425c154d5").into(), hex!("61815774383099e24810ab832a5b2a5425c154d5").into(),
), ),
@ -464,9 +464,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 3u64.into(), nonce: 3u64,
gas_price: 2000000000u64.into(), gas_price: 2000000000u64,
gas_limit: 10000000u64.into(), gas_limit: 10000000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
), ),
@ -488,9 +488,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 1u64.into(), nonce: 1u64,
gas_price: 1000000000u64.into(), gas_price: 1000000000u64,
gas_limit: 100000u64.into(), gas_limit: 100000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
), ),
@ -512,9 +512,9 @@ mod test {
TransactionSigned::from_transaction_and_signature( TransactionSigned::from_transaction_and_signature(
Transaction::Legacy { Transaction::Legacy {
chain_id: Some(4), chain_id: Some(4),
nonce: 2u64.into(), nonce: 2u64,
gas_price: 1000000000u64.into(), gas_price: 1000000000u64,
gas_limit: 100000u64.into(), gas_limit: 100000u64,
to: TransactionKind::Call( to: TransactionKind::Call(
hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(), hex!("d3e8763675e4c425df46cc3b5c0f6cbdac396046").into(),
), ),

View File

@ -50,13 +50,13 @@ impl<'a> Deserialize<'a> for Index {
{ {
if let Some(val) = value.strip_prefix("0x") { if let Some(val) = value.strip_prefix("0x") {
usize::from_str_radix(val, 16).map(Index).map_err(|e| { 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 { } else {
value value
.parse::<usize>() .parse::<usize>()
.map(Index) .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}")))
} }
} }

View File

@ -104,6 +104,6 @@ impl<'a> Deserialize<'a> for Params {
serde_json::from_value(v) serde_json::from_value(v)
.map(|f| Params::Logs(Box::new(f))) .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}")))
} }
} }

View File

@ -78,7 +78,7 @@ impl<Ok> ToRpcResult<Ok, reth_interfaces::Error> for reth_interfaces::Result<Ok>
match self { match self {
Ok(t) => Ok(t), Ok(t) => Ok(t),
Err(err) => { Err(err) => {
let msg = format!("{}: {:?}", msg, err); let msg = format!("{msg}: {err:?}");
Err(internal_rpc_err(msg)) Err(internal_rpc_err(msg))
} }
} }

View File

@ -261,14 +261,14 @@ mod tests {
receipts_root: H256::from_str("29b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9").unwrap(), receipts_root: H256::from_str("29b0562f7140574dd0d50dee8a271b22e1a0a7b78fca58f7c60370d8317ba2a9").unwrap(),
logs_bloom: <[u8; 256]>::from_hex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap().into(), logs_bloom: <[u8; 256]>::from_hex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap().into(),
difficulty: 0x020000.into(), difficulty: 0x020000.into(),
number: 0x01_u64.into(), number: 0x01_u64,
gas_limit: 0x016345785d8a0000_u64.into(), gas_limit: 0x016345785d8a0000_u64,
gas_used: 0x015534_u64.into(), gas_used: 0x015534_u64,
timestamp: 0x079e, timestamp: 0x079e,
extra_data: Bytes::from_str("42").unwrap().0, extra_data: Bytes::from_str("42").unwrap().0,
mix_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(), mix_hash: H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
nonce: 0, nonce: 0,
base_fee_per_gas: Some(0x036b_u64.into()), base_fee_per_gas: Some(0x036b_u64),
}; };
assert_eq!(header.hash_slow(), expected_hash); assert_eq!(header.hash_slow(), expected_hash);
} }
@ -279,9 +279,9 @@ mod tests {
let data = hex::decode("f901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000").unwrap(); let data = hex::decode("f901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000").unwrap();
let expected = Header { let expected = Header {
difficulty: 0x8aeu64.into(), difficulty: 0x8aeu64.into(),
number: 0xd05u64.into(), number: 0xd05u64,
gas_limit: 0x115cu64.into(), gas_limit: 0x115cu64,
gas_used: 0x15b3u64.into(), gas_used: 0x15b3u64,
timestamp: 0x1a0au64, timestamp: 0x1a0au64,
extra_data: Bytes::from_str("7788").unwrap().0, extra_data: Bytes::from_str("7788").unwrap().0,
..Default::default() ..Default::default()

View File

@ -111,7 +111,7 @@ mod test {
fn test_integer_list() { fn test_integer_list() {
let original_list = [1, 2, 3]; 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::<Vec<usize>>() == original_list); assert!(ef_list.iter(0).collect::<Vec<usize>>() == original_list);
} }
@ -119,7 +119,7 @@ mod test {
#[test] #[test]
fn test_integer_list_serialization() { fn test_integer_list_serialization() {
let original_list = [1, 2, 3]; 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(); let blist = ef_list.to_bytes();
assert!(IntegerList::from_bytes(&blist).unwrap() == ef_list) assert!(IntegerList::from_bytes(&blist).unwrap() == ef_list)

View File

@ -51,10 +51,10 @@ impl<'a> Visitor<'a> for JsonU256Visitor {
0 => U256::from(0), 0 => U256::from(0),
2 if value.starts_with("0x") => U256::zero(), 2 if value.starts_with("0x") => U256::zero(),
_ if value.starts_with("0x") => U256::from_str(&value[2..]).map_err(|e| { _ 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| { _ => 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:?}"))
})?, })?,
}; };