-
Notifications
You must be signed in to change notification settings - Fork 677
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
[Testing] Introduce proptest
property testing library and add type alises for hashbrown
types
#4477
base: next
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not opposed to adding a way to create mocked data structures, but I think this is fundamentally the wrong way to do it.
First, this should not be a dependency at all. It's purely for testing; it should be only a dev-dependency.
Second, it doesn't look like fake
is actually doing that much work for us. You're still creating all these constructors for all these data structures, and populating them with Rng-synthesized data. Why have fake
at all then?
Third, every data type in Clarity has a bound size by design. But, none of these constructors exercise it. For example, it would be very useful to be able to do things like construct data types of maximum size, or maximum depth, in order to e.g. benchmark the code or iron out resource usage overflows, but that doesn't appear to be something fake
does for us.
I'm not convinced that this PR is necessary.
As I wrote in the description, this needs to be included as an optional dependency because of cargo's limitation that it doesn't propagate the
I've provided specific implementations to manage recursion and to handle types which require that i.e. two separate
With a bit more effort this could easily be implemented, very similar to their built-in "locales" support. This isn't a use-case for the moment with basic testing that instances can be serialized, inserted in the database, read from the database, deserialized and be equal. I'd just like to add that this is intended to be a "first introduction" of the crate -- while this happens to be rather complex and recursive types, I don't think there's too many other types in the codebase which have the same recursive nature, so for the majority of remaining types the simple |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #4477 +/- ##
==========================================
- Coverage 83.26% 83.20% -0.07%
==========================================
Files 451 464 +13
Lines 325765 326533 +768
Branches 323 323
==========================================
+ Hits 271240 271678 +438
- Misses 54517 54847 +330
Partials 8 8
... and 30 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
0dcae6d
to
f458050
Compare
You deleted this, but I think it's a valid question:
If I were doing this, I would just create a trait called
Right -- you're doing this with our without
It seems it provides a lot of boilerplate that this PR doesn't use? Also, to contrast this with a hypothetical
With a bit more effort we can also just avoid Circling back to your first (deleted) question, I want to explore the line of questioning from @moodmosaic more. A value-add that |
I deleted it simply because I thought it could come across as unfriendly :)
Just to ensure correct terminology and expectations, this PR introduces faking and not mocking. There's nothing wrong with the approach you suggest - it was the first thing that came to mind and that which I started with -- but very quickly remembered that there are libraries to do most of this for me. So I'm personally of the opinion that it is a waste of cycles to re-implement, both on the development and maintenance fronts, when there are crates which give us that boilerplate. I would understand the scrutiny much more if this were a production crate, but this is a pretty popular crate which in probably 95% of cases can be used as a
At the moment, sure, but this is just an introduction PR with minimalistic examples. My hope would be that it would be used much more broadly. As you say, it's not hard to implement, but do we really want to muddy-up the Stacks code-base with even more macros etc.? I'd much rather version-pin workspace dependencies and carefully upgrade than re-write code that already exists, or even worse.. principally copying it without those oss projects getting credit.
If the idea was that it would be limited to the small number of examples provided here, then I would totally agree. But I think there are a lot of missing tests due to laziness of not wanting to manually fake such types, not at the least the example tests which I added in this PR. And on the other end of the spectrum, probably a lot of unnecessary initialization code which just adds to LoC and maybe could benefit from some randomization for fuzzing/prop-testing. The real power isn't in the ability to implement custom generators for types, it's in the
@moodmosaic and I discussed this briefly prior to this PR -- it would be great if we could get them to integrate, absolutely. It's a giant plus that they both use And last but not least, I used this crate heavily in my #4437 PR draft, and it both saved me a lot of time and increased my confidence in the tests. |
fake
faking library, and wrapper types for hashbrown
's HashMap
and HashSet
proptest
property testing library, and wrapper types for hashbrown
's HashMap
and HashSet
fa78a9b
to
e7eb3d3
Compare
This PR has been repurposed to introduce Note that most touched files are simply replacing @moodmosaic @jcnelson please re-review. |
9697ec5
to
a53aeed
Compare
proptest
property testing library, and wrapper types for hashbrown
's HashMap
and HashSet
proptest
property testing library and add type alises for hashbrown
types
@jcnelson would love a re-review of this so we can clear your requested changes, when you have time. |
a53aeed
to
65b85d2
Compare
This PR introduces the proptest crate with some example property testing tests and wrapper types in
stacks-common
for hashbrown'sHashMap
andHashSet
types.Note: This is a break-out from the larger draft PR #4437.
I have provided a number of
proptest
strategies for common Clarity types, includingContract
,TypeSignature
,SymbolicExpression
andValue
(some courtesy of @Acaccia fromclarity-wasm
).Thehashbrown
wrapper types are needed as we cannot implement external crates for external types and I have provided proptest strategies for these new types as well. To use the new types, simply replacestd::collections::HashMap/Set
orhashbrown::HashMap/Set
withclarity_common::types::StacksHashMap/Set as HashMap/Set
This caused problems in the signerlib which uses a combination of hashbrown and std, so given that this isn't strictly needed for this PR I have removed these new concrete types in favor of type aliases.
Note that I have gone through and replaced
use::hashbrown::xxx
with the above, hence the large number of touched files.I have also added additional tests for
ClarityDatabase
which 1) were missing, and 2) demonstrate the usage ofproptest
.Resolves Issues
[Testing] Introduce thefake
crate for helping to create faked data instead of repeating boilerplate initializations in tests #4446proptest
toclarity
,stackslib
andstacks-common
crates #4501