Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove proptest arbitrary from codec derive and tests #8968

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ jsonrpsee-http-client = "0.23"
http = "1.0"
http-body = "1.0"
jsonwebtoken = "9"
proptest-arbitrary-interop = "0.1.0"

# crypto
secp256k1 = { version = "0.29", default-features = false, features = [
Expand Down
2 changes: 2 additions & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ metrics-process.workspace = true

# test vectors generation
proptest.workspace = true
arbitrary.workspace = true
proptest-arbitrary-interop.workspace = true
rand.workspace = true

# tui
Expand Down
37 changes: 12 additions & 25 deletions bin/reth/src/commands/test_vectors/tables.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::collections::HashSet;

use arbitrary::Arbitrary;
use eyre::Result;
use proptest::{
arbitrary::Arbitrary,
prelude::{any_with, ProptestConfig},
prelude::ProptestConfig,
strategy::{Strategy, ValueTree},
test_runner::TestRunner,
};
use proptest_arbitrary_interop::arb;
use reth_db::tables;
use reth_db_api::table::{DupSort, Table, TableRow};
use reth_fs_util as fs;
use std::collections::HashSet;
use tracing::error;

const VECTORS_FOLDER: &str = "testdata/micro/db";
Expand Down Expand Up @@ -73,21 +73,14 @@ pub(crate) fn generate_vectors(mut tables: Vec<String>) -> Result<()> {
/// Generates test-vectors for normal tables. Keys are sorted and not repeated.
fn generate_table_vector<T>(runner: &mut TestRunner, per_table: usize) -> Result<()>
where
T::Key: Arbitrary + serde::Serialize + Ord + std::hash::Hash,
T::Value: Arbitrary + serde::Serialize,
T: Table,
T::Key: for<'a> Arbitrary<'a> + serde::Serialize + Ord + std::hash::Hash + Clone,
T::Value: for<'a> Arbitrary<'a> + serde::Serialize + Clone,
{
let mut rows = vec![];
let mut seen_keys = HashSet::new();
let strategy = proptest::collection::vec(
any_with::<TableRow<T>>((
<T::Key as Arbitrary>::Parameters::default(),
<T::Value as Arbitrary>::Parameters::default(),
)),
per_table - rows.len(),
)
.no_shrink()
.boxed();
let strategy =
proptest::collection::vec(arb::<TableRow<T>>(), per_table - rows.len()).no_shrink().boxed();

while rows.len() < per_table {
// Generate all `per_table` rows: (Key, Value)
Expand All @@ -111,23 +104,17 @@ where
fn generate_dupsort_vector<T>(runner: &mut TestRunner, per_table: usize) -> Result<()>
where
T: Table + DupSort,
T::Key: Arbitrary + serde::Serialize + Ord + std::hash::Hash,
T::Value: Arbitrary + serde::Serialize + Ord,
T::Key: for<'a> Arbitrary<'a> + serde::Serialize + Ord + std::hash::Hash + Clone,
T::Value: for<'a> Arbitrary<'a> + serde::Serialize + Ord + Clone,
{
let mut rows = vec![];

// We want to control our repeated keys
let mut seen_keys = HashSet::new();

let strat_values = proptest::collection::vec(
any_with::<T::Value>(<T::Value as Arbitrary>::Parameters::default()),
100..300,
)
.no_shrink()
.boxed();
let strat_values = proptest::collection::vec(arb::<T::Value>(), 100..300).no_shrink().boxed();

let strat_keys =
any_with::<T::Key>(<T::Key as Arbitrary>::Parameters::default()).no_shrink().boxed();
let strat_keys = arb::<T::Key>().no_shrink().boxed();

while rows.len() < per_table {
let key: T::Key = strat_keys.new_tree(runner).map_err(|e| eyre::eyre!("{e}"))?.current();
Expand Down
5 changes: 3 additions & 2 deletions crates/net/eth-wire-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde = { workspace = true, optional = true }
# arbitrary utils
arbitrary = { workspace = true, features = ["derive"], optional = true }
proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
proptest-arbitrary-interop = { workspace = true, optional = true }

[dev-dependencies]
reth-net-common.workspace = true
Expand All @@ -40,6 +40,7 @@ rand.workspace = true

arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
proptest-arbitrary-interop.workspace = true
proptest-derive.workspace = true
async-stream.workspace = true

Expand All @@ -49,7 +50,7 @@ arbitrary = [
"reth-primitives/arbitrary",
"dep:arbitrary",
"dep:proptest",
"dep:proptest-derive",
"dep:proptest-arbitrary-interop",
]
serde = ["dep:serde"]

25 changes: 2 additions & 23 deletions crates/net/eth-wire-types/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary};
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256};

#[cfg(any(test, feature = "arbitrary"))]
use proptest::{collection::vec, prelude::*};
#[cfg(any(test, feature = "arbitrary"))]
use reth_primitives::{generate_valid_header, valid_header_strategy};
use reth_primitives::generate_valid_header;
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -51,18 +48,6 @@ pub struct BlockHeaders(
pub Vec<Header>,
);

#[cfg(any(test, feature = "arbitrary"))]
impl proptest::arbitrary::Arbitrary for BlockHeaders {
type Parameters = ();
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
let headers_strategy = vec(valid_header_strategy(), 0..10); // Adjust the range as needed

headers_strategy.prop_map(BlockHeaders).boxed()
}

type Strategy = proptest::prelude::BoxedStrategy<Self>;
}

#[cfg(any(test, feature = "arbitrary"))]
impl<'a> arbitrary::Arbitrary<'a> for BlockHeaders {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Expand Down Expand Up @@ -111,12 +96,6 @@ impl From<Vec<B256>> for GetBlockBodies {
#[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::<BlockBody>(), 0..=20)"
)
)]
pub Vec<BlockBody>,
);

Expand Down
4 changes: 3 additions & 1 deletion crates/net/eth-wire-types/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::{

#[cfg(feature = "arbitrary")]
use proptest::{collection::vec, prelude::*};
#[cfg(feature = "arbitrary")]
use proptest_arbitrary_interop::arb;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -351,7 +353,7 @@ impl Arbitrary for NewPooledTransactionHashes68 {
.prop_flat_map(|len| {
// Use the generated length to create vectors of TxType, usize, and B256
let types_vec =
vec(any::<reth_primitives::TxType>().prop_map(|ty| ty as u8), len..=len);
vec(arb::<reth_primitives::TxType>().prop_map(|ty| ty as u8), len..=len);

// Map the usize values to the range 0..131072(0x20000)
let sizes_vec = vec(proptest::num::usize::ANY.prop_map(|x| x % 131072), len..=len);
Expand Down
6 changes: 0 additions & 6 deletions crates/net/eth-wire-types/src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ pub struct GetReceipts(
#[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::<ReceiptWithBloom>(), 0..=50), 0..=5)"
)
)]
pub Vec<Vec<ReceiptWithBloom>>,
);

Expand Down
5 changes: 1 addition & 4 deletions crates/net/eth-wire/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ snap = "1.0.5"

# arbitrary utils
arbitrary = { workspace = true, features = ["derive"], optional = true }
proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }

[dev-dependencies]
reth-net-common.workspace = true
Expand All @@ -58,6 +56,7 @@ secp256k1 = { workspace = true, features = [

arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
proptest-arbitrary-interop.workspace = true
proptest-derive.workspace = true
async-stream.workspace = true

Expand All @@ -66,8 +65,6 @@ default = ["serde"]
arbitrary = [
"reth-primitives/arbitrary",
"dep:arbitrary",
"dep:proptest",
"dep:proptest-derive",
]
optimism = ["reth-primitives/optimism"]
serde = ["dep:serde"]
Expand Down
16 changes: 0 additions & 16 deletions crates/net/eth-wire/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,6 @@ impl<'a> arbitrary::Arbitrary<'a> for Capability {
}
}

#[cfg(any(test, feature = "arbitrary"))]
impl proptest::arbitrary::Arbitrary for Capability {
type Parameters = proptest::arbitrary::ParamsFor<String>;
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
use proptest::strategy::Strategy;
proptest::arbitrary::any_with::<String>(args) // TODO: what possible values?
.prop_flat_map(move |name| {
proptest::arbitrary::any_with::<usize>(()) // TODO: What's the max?
.prop_map(move |version| Self::new(name.clone(), version))
})
.boxed()
}

type Strategy = proptest::strategy::BoxedStrategy<Self>;
}

/// Represents all capabilities of a node.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Capabilities {
Expand Down
Loading
Loading