-
Notifications
You must be signed in to change notification settings - Fork 158
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
Make tests polymorphic over the Value type #1913
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.
Just did a partial review to leave some comments (now stuck in meetings)! Might be good to go through this in a meeting since there's probably some subtleties to it
@@ -33,4 +33,4 @@ type family MAValue (x :: MaryOrAllegra) era :: Type where | |||
MAValue Allegra era = Coin | |||
MAValue Mary era = Value era | |||
|
|||
type instance Core.Value (ShelleyMAEra m c) = MAValue m (ShelleyMAEra m c) |
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.
Why is Value
now in ALLCAPS?
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.
ha! we (Alex, Tim and I) discussed type families being in all caps (there is already some attempt to make this a convention it looks like from before), then wrapped in a newtype.
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.
leaving for this PR
@@ -19,6 +19,7 @@ flag development | |||
library | |||
exposed-modules: | |||
Cardano.Ledger.Core | |||
Cardano.Ledger.Compactible |
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.
👍
-- the genericShrink has something that | ||
-- detects that the immediate subterms of a type are the same as the parent type | ||
-- when there is a type family in that position, the instance resolution fails | ||
newtype Value era = Value {unVl :: VALUE era} |
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.
Ah, I see. Somehow I seem to have got around this issue in #1908, though in honesty I haven't the foggiest how. It seems an unfortunate hack, so I'd hope we could avoid it, but maybe that just causes more trouble...
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 think it is because you have put ShelleyEra c
where it was just era
before, together with the ShelleyBased era
constraint. ShelleyEra
includes Core.Value~Coin
and TxBody
being the Shelley TxBody
, so genericShrink
was not confused any more
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.
maybe rewrite the shrinker to a manual shrinker? to avoid this
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.
leaving shrinker as is for now
shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/Shelley.hs
Outdated
Show resolved
Hide resolved
@@ -14,46 +16,61 @@ module Cardano.Ledger.Core | |||
( -- * Compactible | |||
Compactible (..), |
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'd suggest now that Compactible
is in its own module (which is great!) we avoid re-exporting it from here?
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.
mistake
@@ -146,7 +146,7 @@ deriving stock instance | |||
ShelleyBased era => | |||
Eq (UtxoPredicateFailure era) | |||
|
|||
instance NoThunks (Core.Value era) => NoThunks (UtxoPredicateFailure era) | |||
instance ShelleyBased era => NoThunks (UtxoPredicateFailure era) |
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'd argue that cases like this (where there's only one constraint, so we don't save space by using the bundle) have a strong argument for remaining with the more specific constraint. It's better as documentation (we see exactly what we're relying on) and we have more chance of being able to re-use this in the future.
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.
to remove UndecidableInstances. So I should put it back?
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.
yes
...ley/chain-and-ledger/shelley-spec-ledger-test/src/Test/Shelley/Spec/Ledger/Generator/Core.hs
Show resolved
Hide resolved
b4f9778
to
79afad8
Compare
deltaT8 :: Coin | ||
deltaT8 = Coin 317333333333 | ||
|
||
-- TODO make DeltaCoin? | ||
deltaR8 :: Coin | ||
deltaR8 = Coin (-330026666665) | ||
|
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 hope this not being a delta coin is the reason for the test failure! Coins must always be positive or there will be ghosts..
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.
changed this to +ve value and subtraction at use site for now!
|
||
type TxBodyConstraints era = | ||
class |
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.
put back to type
@@ -88,6 +90,7 @@ instance CryptoClass.Crypto BenchCrypto where | |||
type ADDRHASH BenchCrypto = Blake2b_224 | |||
|
|||
type BenchEra = ShelleyEra BenchCrypto | |||
type instance VALUE BenchEra = Coin | |||
|
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.
consider changing convention for type families (or get rid of newtype)
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.
always use qualified imports for type families
genValList :: (ShelleyTest era) => Integer -> Integer -> Int -> Gen [Core.Value era] | ||
genValList minCoin maxCoin len = do | ||
let addWOCoin c v = c <+> (v <-> (Val.inject $ Val.coin v)) | ||
replicateM len $ liftM2 addWOCoin (Val.inject <$> genCoin minCoin maxCoin) QC.arbitrary | ||
|
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.
pass generator for Val instead of using arbitrary
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.
look at valprop.hs
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.
leaving for now
instance Split Coin where | ||
vsplit (Coin n) 0 = ([], Coin n) | ||
vsplit (Coin n) m -- TODO fix this? | ||
| m Prelude.<= 0 = error "must split coins into positive parts" |
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.
fix what?
Core.Value era ~ Coin, | ||
type ShelleyTest era = (ShelleyBased era, Arbitrary (Core.Value era), | ||
HedGen (Core.Value era), Split (Core.Value era), P.PartialOrd (Core.VALUE era), | ||
Arbitrary (Core.VALUE era), HedGen (Core.VALUE era), Split (Core.VALUE era) ) |
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.
remove partial order and add a a constraint that requires to have pointwise
comparison
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.
removed
instance Arbitrary Coin where | ||
-- Cannot be negative even though it is an 'Integer' | ||
arbitrary = Coin <$> choose (0, 1000) | ||
|
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.
plumbing in our own generators should make us able to remove these
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.
leaving for now
extraCoin sr = Val.coin $ extraTokens sr | ||
-- put all the non-ada tokens in the head of the outputs, append shrunk list | ||
mvExtraTksnToOut1 Empty = empty | ||
mvExtraTksnToOut1 sr = (<|) (TxOut a (vs <+> (extraTokens sr) <-> (Val.inject $ extraCoin sr))) sr |
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.
infix
shrinkTxOut (TxOut addr coin) = | ||
TxOut addr <$> shrinkCoin coin | ||
shrinkTxOut (TxOut addr vl) = | ||
TxOut addr <$> shrink vl | ||
|
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.
pass in our own shrinker here
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.
TODO comment that we dont shrink the value here
@@ -36,9 +36,12 @@ module Test.Shelley.Spec.Ledger.Utils | |||
MultiSigPairs, |
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.
paused review here
79afad8
to
7119510
Compare
PR #1922 may also now be helpful here! |
50dc43a
to
fad5cfe
Compare
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.
LGTM
Remove the constraint
Core.Value era ~ Coin
from the bundleShelleyTest
Add to
ShelleyTest
testing-related constraints on the Value type (Arbitrary, hedgehog, Split)Change
ShelleyBased
from a constraint bundle to a type classRemove
UndecidableInstances
where they're not neededUpdate generators (
genTxOut
) of outputs to generate ones containingValue era
Rename
Value
type family toVALUE
following some (apparently existing) convention for type family names, then wrap VALUE inValue
newtypeSplit out
Compatible
as a moduleLeave testing files where ConcreteCryptoTypes (C) is imported as using the C era