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

This commit is contained in:
Dan Cline
2024-06-20 19:02:07 -04:00
committed by GitHub
parent 6b2c3af8b9
commit 8492ab3d52
41 changed files with 205 additions and 312 deletions

View File

@ -15,7 +15,7 @@ workspace = true
reth-codecs-derive = { path = "./derive", default-features = false }
# eth
alloy-consensus = { workspace = true, optional = true }
alloy-consensus = { workspace = true, optional = true, features = ["arbitrary"] }
alloy-eips = { workspace = true, optional = true }
alloy-genesis = { workspace = true, optional = true }
alloy-primitives.workspace = true
@ -37,6 +37,7 @@ serde_json.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
proptest-derive.workspace = true
proptest-arbitrary-interop.workspace = true
[features]
default = ["std", "alloy"]

View File

@ -87,12 +87,13 @@ pub fn maybe_generate_tests(args: TokenStream, ast: &DeriveInput) -> TokenStream
#[cfg(test)]
mod #mod_tests {
#(#traits)*
use proptest_arbitrary_interop::arb;
#[test]
fn proptest() {
let mut config = proptest::prelude::ProptestConfig::with_cases(#default_cases as u32);
proptest::proptest!(config, |(field: super::#type_ident)| {
proptest::proptest!(config, |(field in arb::<super::#type_ident>())| {
#(#roundtrips)*
});
}

View File

@ -69,7 +69,7 @@ pub fn main_codec(args: TokenStream, input: TokenStream) -> TokenStream {
derive_arbitrary(TokenStream::from_iter(args), compact)
}
/// Adds `Arbitrary` and `proptest::Arbitrary` imports into scope and derives the struct/enum.
/// Adds `Arbitrary` imports into scope and derives the struct/enum.
///
/// If `compact` or `rlp` is passed to `derive_arbitrary`, there will be proptest roundtrip tests
/// generated. An integer value passed will limit the number of proptest cases generated (default:
@ -89,17 +89,13 @@ pub fn derive_arbitrary(args: TokenStream, input: TokenStream) -> TokenStream {
let tests = arbitrary::maybe_generate_tests(args, &ast);
// Avoid duplicate names
let prop_import = format_ident!("{}PropTestArbitrary", ast.ident);
let arb_import = format_ident!("{}Arbitrary", ast.ident);
quote! {
#[cfg(any(test, feature = "arbitrary"))]
use proptest_derive::Arbitrary as #prop_import;
#[cfg(any(test, feature = "arbitrary"))]
use arbitrary::Arbitrary as #arb_import;
#[cfg_attr(any(test, feature = "arbitrary"), derive(#prop_import, #arb_import))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(#arb_import))]
#ast
#tests

View File

@ -26,10 +26,11 @@ impl Compact for Request {
mod tests {
use super::*;
use proptest::proptest;
use proptest_arbitrary_interop::arb;
proptest! {
#[test]
fn roundtrip(request: Request) {
fn roundtrip(request in arb::<Request>()) {
let mut buf = Vec::<u8>::new();
request.to_compact(&mut buf);
let (decoded, _) = Request::from_compact(&buf, buf.len());

View File

@ -36,7 +36,6 @@ bytes.workspace = true
# arbitrary utils
arbitrary = { workspace = true, features = ["derive"], optional = true }
proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
[dev-dependencies]
# reth libs with arbitrary
@ -58,6 +57,7 @@ iai-callgrind.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
proptest-arbitrary-interop.workspace = true
proptest-derive.workspace = true
paste.workspace = true
@ -70,6 +70,5 @@ arbitrary = [
"reth-primitives/arbitrary",
"dep:arbitrary",
"dep:proptest",
"dep:proptest-derive",
]
optimism = []