-
Notifications
You must be signed in to change notification settings - Fork 479
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
QuickCheck Arbitrary
instances for Ledger types
#6210
Comments
That would be great to have indeed. I've brought it to the team and the team agreed. I'm going to mark this issue as "low priority" though, since it's not a bug or similar. PR would be very welcome. |
Property Testing! cool, It looks like something I could implement. My questions are:
Thanks! |
@aleeusgr thank you for volunteering! How about you take the work done by MLabs and upstream it into our repo? While improving everything that you can think of along the way.
We have a generator for |
It would be great if you guys can get our instances upstreamed. That was our original plan, but given we have to complete Plutus Ledger API V3 in time, we had to vendor it temporarily. Most instances come with all necessary parts with some degree of assurance over invariants(e.g. value's entries being sorted): generator, shrinker, and utilities for function generators. Some of the more tricky ones like Rest should be good in terms of quality, documentation, and code structure. We've actually used this to check data encoding for Plutarch ledger API and already caught handful of bugs. Property testing rocks! |
This one is pretty good when it comes to the distribution of generated trees, but it doesn't attempt to satisfy various invariants like the one by MLabs does. It would be ideal to preserve the current generation of trees and add the invariants logic.
Thank you for doing this! |
Hello! Sadly I report that I am still stuck with this issue. My first hunch was to automate reasoning about "Type X has an Arbitrary", at which I partially succeeded. I wrote a test that fails to build if a Type has no RNG. But then I failed to find a way to list all the exported types. Then I decided to not bother with high level and try to copy and paste an RNG from plutarch. Here I don't understand what my acceptance criteria would look like. To illustrate, lets look at first I load the module to repl ghci> :info PlutusLedgerApi.V1.Value.Value
type Value :: *
newtype Value
= Value {getValue :: PlutusTx.AssocMap.Map
CurrencySymbol (PlutusTx.AssocMap.Map TokenName Integer)}
-- Defined at src/PlutusLedgerApi/V1/Value.hs:278:1
instance Eq Value
-- Defined at src/PlutusLedgerApi/V1/Value.hs:307:10
instance Monoid Value
-- Defined at src/PlutusLedgerApi/V1/Value.hs:321:10
instance Semigroup Value
-- Defined at src/PlutusLedgerApi/V1/Value.hs:314:10
instance Show Value
-- Defined at src/PlutusLedgerApi/V1/Value.hs:279:46 as you can see there is no ghci> :info PlutusLedgerApi.Test.V1.Value.
PlutusLedgerApi.Test.V1.Value.FaceValue PlutusLedgerApi.Test.V1.Value.unFaceValue
PlutusLedgerApi.Test.V1.Value.NoArbitrary PlutusLedgerApi.Test.V1.Value.unNoArbitrary
PlutusLedgerApi.Test.V1.Value.genShortHex PlutusLedgerApi.Test.V1.Value.uniqueNames
PlutusLedgerApi.Test.V1.Value.listsToValue PlutusLedgerApi.Test.V1.Value.valueToLists
PlutusLedgerApi.Test.V1.Value.toCellCandidatesNumber There is no Arbitrary there! I am really confused! Should I not user For example the PR defines instance Arbitrary PLA.Credential where
{-# INLINEABLE arbitrary #-}
arbitrary =
oneof
[ PLA.PubKeyCredential <$> arbitrary
, PLA.ScriptCredential <$> arbitrary
]
-- | @since 1.0.0
instance CoArbitrary PLA.Credential where
{-# INLINEABLE coarbitrary #-}
coarbitrary = \case
PLA.PubKeyCredential pkh -> variant (0 :: Int) . coarbitrary pkh
PLA.ScriptCredential sh -> variant (1 :: Int) . coarbitrary sh Let me implement it! But how do I know if it needs to be done and when I do it how do I know I am successful? Thank you! In case you are open to a pair programming session, lets discuss it! We can schedule a transcribed call and I'll use the transcript to write a docpage or an article about testing in plutus. |
Surprised about that as well, I'd expect GHCi to pick up the instance.
As for the first part of the question, The second part of the question is harder though. If you want to make this as painless as possible, just add some very simple yet still helpful test requiring some straightforward |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@coot says:
Thanks coot, I will look into that. |
Hey! Looks like I'll be moving the instances that we have in Plutarch upstream. Is that fine with you to put |
There are some in |
Describe the feature you'd like
Currently, each projects need to write some property testing generator and shrinker on per-project biases, making testing not only more difficult but possibly more inconsistent and un-standardized. Quickcheck
Arbirary
instances for each types thatPlutusLedgerApi
exports would immensely help when testing scripts, generating some place-holder values, or even maintaining eDSL equivalent for ledger api--for example, Plutarch.The text was updated successfully, but these errors were encountered: