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

test: use concrete type for arbitrary strategy #3632

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Jul 6, 2023

get rid of boxed strategy

h/t @DaniPopes

@mattsse mattsse added C-perf A change motivated by improving speed, memory usage or disk footprint C-test A change that impacts how or what we test labels Jul 6, 2023
@mattsse
Copy link
Collaborator Author

mattsse commented Jul 6, 2023

ffs the tuple type does not work

pub struct BlockNumberAddress(pub (BlockNumber, Address));

...

@DaniPopes
Copy link
Member

@mattsse the strategy is Vec<u8>'s mapped to Self

diff --git a/crates/storage/db/src/tables/utils.rs b/crates/storage/db/src/tables/utils.rs
index 93705555..7a5e9d5d 100644
--- a/crates/storage/db/src/tables/utils.rs
+++ b/crates/storage/db/src/tables/utils.rs
@@ -1,16 +1,15 @@
-//! Small database table utilities and helper functions
+//! Small database table utilities and helper functions.
+
 use crate::{
     table::{Decode, Decompress, Table},
     DatabaseError,
 };
-
 use std::borrow::Cow;
 
+/// Implements the `Arbitrary` trait for types with fixed array types.
 #[macro_export]
-/// Implements the `Arbitrary` trait for types with fixed array
-/// types.
 macro_rules! impl_fixed_arbitrary {
-    ($name:tt, $size:tt) => {
+    ($name:ident, $size:tt) => {
         #[cfg(any(test, feature = "arbitrary"))]
         use arbitrary::{Arbitrary, Unstructured};
 
@@ -19,22 +18,20 @@ macro_rules! impl_fixed_arbitrary {
             fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self, arbitrary::Error> {
                 let mut buffer = vec![0; $size];
                 u.fill_buffer(buffer.as_mut_slice())?;
-
                 Decode::decode(buffer).map_err(|_| arbitrary::Error::IncorrectFormat)
             }
         }
 
-        #[cfg(any(test, feature = "arbitrary"))]
-        use proptest::strategy::Strategy;
         #[cfg(any(test, feature = "arbitrary"))]
         impl proptest::prelude::Arbitrary for $name {
             type Parameters = ();
             type Strategy = proptest::strategy::Map<
-                proptest::collection::VecStrategy<$name>,
-                fn(<S as Strategy>::Value) -> T,
+                proptest::collection::VecStrategy<<u8 as proptest::arbitrary::Arbitrary>::Strategy>,
+                fn(Vec<u8>) -> Self,
             >;
 
             fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
+                use proptest::strategy::Strategy;
                 proptest::collection::vec(proptest::arbitrary::any_with::<u8>(args), $size)
                     .prop_map(move |vec| Decode::decode(vec).unwrap())
             }

@mattsse
Copy link
Collaborator Author

mattsse commented Jul 6, 2023

sorry but idk what this means, can't follow.

not sure how to interpret the diff

@DaniPopes
Copy link
Member

DaniPopes commented Jul 6, 2023

It means I fixed it for you :)
S in S as Strategy doesn't exist, and VecStrategy<$name> should instead be VecStrategy<u8::Strategy>

@mattsse
Copy link
Collaborator Author

mattsse commented Jul 6, 2023

hehe,

tysm for this champ!

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #3632 (a79d643) into main (73bfb2c) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

Impacted Files Coverage Δ
crates/storage/db/src/tables/utils.rs 81.81% <0.00%> (ø)

... and 14 files with indirect coverage changes

Flag Coverage Δ
integration-tests 15.94% <0.00%> (-0.02%) ⬇️
unit-tests 64.11% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 26.40% <ø> (ø)
blockchain tree 81.25% <ø> (ø)
pipeline 86.69% <ø> (ø)
storage (db) 73.48% <0.00%> (ø)
trie 94.66% <ø> (ø)
txpool 49.11% <ø> (-0.62%) ⬇️
networking 77.87% <ø> (+<0.01%) ⬆️
rpc 58.21% <ø> (+0.13%) ⬆️
consensus 63.35% <ø> (ø)
revm 34.89% <ø> (-0.01%) ⬇️
payload builder 6.83% <ø> (ø)
primitives 88.25% <ø> (-0.02%) ⬇️

@mattsse mattsse added this pull request to the merge queue Jul 6, 2023
Merged via the queue into main with commit 5d904eb Jul 6, 2023
26 checks passed
@mattsse mattsse deleted the matt/use-concrete-strategy-type branch July 6, 2023 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-perf A change motivated by improving speed, memory usage or disk footprint C-test A change that impacts how or what we test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants