From d14f995e1a94c0e205a409610d84ddcb068cfb65 Mon Sep 17 00:00:00 2001 From: Bjerg Date: Sun, 2 Jul 2023 12:46:16 +0200 Subject: [PATCH] test: improve slow tests (#3487) Co-authored-by: Matthias Seitz --- crates/net/eth-wire/src/types/blocks.rs | 8 +++++++- crates/net/eth-wire/src/types/receipts.rs | 8 +++++++- crates/primitives/src/block.rs | 18 ++++++++++++++++++ crates/primitives/src/log.rs | 6 ++++++ crates/primitives/src/receipt.rs | 6 ++++++ .../primitives/src/transaction/access_list.rs | 19 ++++++++++++++++--- crates/trie/src/trie.rs | 5 +++-- 7 files changed, 63 insertions(+), 7 deletions(-) diff --git a/crates/net/eth-wire/src/types/blocks.rs b/crates/net/eth-wire/src/types/blocks.rs index c0db52f2d5..47777cd71b 100644 --- a/crates/net/eth-wire/src/types/blocks.rs +++ b/crates/net/eth-wire/src/types/blocks.rs @@ -68,11 +68,17 @@ impl From> for GetBlockBodies { /// The response to [`GetBlockBodies`], containing the block bodies that the peer knows about if /// any were found. -#[derive_arbitrary(rlp, 1)] +#[derive_arbitrary(rlp, 16)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BlockBodies( /// The requested block bodies, each of which should correspond to a hash in the request. + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::arbitrary::any::(), 0..=20)" + ) + )] pub Vec, ); diff --git a/crates/net/eth-wire/src/types/receipts.rs b/crates/net/eth-wire/src/types/receipts.rs index 87190aa688..f1bb3bc120 100644 --- a/crates/net/eth-wire/src/types/receipts.rs +++ b/crates/net/eth-wire/src/types/receipts.rs @@ -17,11 +17,17 @@ pub struct GetReceipts( /// The response to [`GetReceipts`], containing receipt lists that correspond to each block /// requested. -#[derive_arbitrary(rlp, 1)] +#[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Receipts( /// Each receipt hash should correspond to a block hash in the request. + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::collection::vec(proptest::arbitrary::any::(), 0..=50), 0..=5)" + ) + )] pub Vec>, ); diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index f5a2b10b20..22bf8e71a1 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -739,10 +739,28 @@ impl From<(BlockHash, BlockNumber)> for BlockNumHash { #[rlp(trailing)] pub struct BlockBody { /// Transactions in the block + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::arbitrary::any::(), 0..=100)" + ) + )] pub transactions: Vec, /// Uncle headers for the given block + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::arbitrary::any::
(), 0..=2)" + ) + )] pub ommers: Vec
, /// Withdrawals in the block. + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::option::of(proptest::collection::vec(proptest::arbitrary::any::(), 0..=16))" + ) + )] pub withdrawals: Option>, } diff --git a/crates/primitives/src/log.rs b/crates/primitives/src/log.rs index 2521428fd7..3b72967b68 100644 --- a/crates/primitives/src/log.rs +++ b/crates/primitives/src/log.rs @@ -9,6 +9,12 @@ pub struct Log { /// Contract that emitted this log. pub address: Address, /// Topics of the log. The number of logs depend on what `LOG` opcode is used. + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::arbitrary::any::(), 0..=5)" + ) + )] pub topics: Vec, /// Arbitrary length data. pub data: Bytes, diff --git a/crates/primitives/src/receipt.rs b/crates/primitives/src/receipt.rs index 75f8e6eb44..15a5a2308d 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -21,6 +21,12 @@ pub struct Receipt { /// Gas used pub cumulative_gas_used: u64, /// Log send from contracts. + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::arbitrary::any::(), 0..=20)" + ) + )] pub logs: Vec, } diff --git a/crates/primitives/src/transaction/access_list.rs b/crates/primitives/src/transaction/access_list.rs index 0964e0be45..eaa60b2603 100644 --- a/crates/primitives/src/transaction/access_list.rs +++ b/crates/primitives/src/transaction/access_list.rs @@ -1,8 +1,7 @@ use crate::{Address, H256}; -use revm_primitives::U256; - use reth_codecs::{main_codec, Compact}; use reth_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; +use revm_primitives::U256; use serde::{Deserialize, Serialize}; /// A list of addresses and storage keys that the transaction plans to access. @@ -14,13 +13,27 @@ pub struct AccessListItem { /// Account addresses that would be loaded at the start of execution pub address: Address, /// Keys of storage that would be loaded at the start of execution + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::arbitrary::any::(), 0..=20)" + ) + )] pub storage_keys: Vec, } /// AccessList as defined in EIP-2930 #[main_codec(rlp)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodableWrapper, RlpEncodableWrapper)] -pub struct AccessList(pub Vec); +pub struct AccessList( + #[cfg_attr( + any(test, feature = "arbitrary"), + proptest( + strategy = "proptest::collection::vec(proptest::arbitrary::any::(), 0..=20)" + ) + )] + pub Vec, +); impl AccessList { /// Converts the list into a vec, expected by revm diff --git a/crates/trie/src/trie.rs b/crates/trie/src/trie.rs index 9ec5ff4cfd..5359f09497 100644 --- a/crates/trie/src/trie.rs +++ b/crates/trie/src/trie.rs @@ -1212,12 +1212,13 @@ mod tests { assert_trie_updates(&account_updates); } - // TODO: limit the thumber of test cases? proptest! { + #![proptest_config(ProptestConfig { + cases: 128, ..ProptestConfig::default() + })] #[test] fn fuzz_state_root_incremental(account_changes: [BTreeMap; 5]) { tokio::runtime::Runtime::new().unwrap().block_on(async { - let db = create_test_rw_db(); let factory = ProviderFactory::new(db.as_ref(), MAINNET.clone()); let tx = factory.provider_rw().unwrap();