-
Notifications
You must be signed in to change notification settings - Fork 176
Fix various issues in Dijkstra CddlSpec to make all the tests pass #5779
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
Open
Soupstraw
wants to merge
9
commits into
master
Choose a base branch
from
jj/constr-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
414421f
Bump cuddle to 1.8.0.0
Soupstraw bc5da9b
improve verification result handling
Soupstraw 76b1ee1
Add custom generator helpers
Soupstraw 5a2a856
Add custom generator to constr
Soupstraw cf26cf0
Add custom validator and generator for sets
Soupstraw 374e1ab
Add subtransactions custom generator
Soupstraw 391d4d2
Fix block_body generator
Soupstraw 872f44e
Scale down tests to make test suites run faster
Soupstraw 779b329
Enable transaction_witness_set
Soupstraw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||
| {-# LANGUAGE FlexibleContexts #-} | ||||||||||||||
| {-# LANGUAGE FlexibleInstances #-} | ||||||||||||||
| {-# LANGUAGE ImportQualifiedPost #-} | ||||||||||||||
| {-# LANGUAGE LambdaCase #-} | ||||||||||||||
| {-# LANGUAGE MonoLocalBinds #-} | ||||||||||||||
| {-# LANGUAGE MultiParamTypeClasses #-} | ||||||||||||||
| {-# LANGUAGE OverloadedLists #-} | ||||||||||||||
|
|
@@ -11,6 +12,7 @@ | |||||||||||||
| {-# LANGUAGE ScopedTypeVariables #-} | ||||||||||||||
| {-# LANGUAGE TypeApplications #-} | ||||||||||||||
| {-# LANGUAGE UndecidableInstances #-} | ||||||||||||||
| {-# LANGUAGE ViewPatterns #-} | ||||||||||||||
| {-# OPTIONS_GHC -Wno-orphans #-} | ||||||||||||||
|
|
||||||||||||||
| module Cardano.Ledger.Conway.HuddleSpec ( | ||||||||||||||
|
|
@@ -65,6 +67,7 @@ module Cardano.Ledger.Conway.HuddleSpec ( | |||||||||||||
| maybeTaggedNonemptySet, | ||||||||||||||
| maybeTaggedNonemptyOset, | ||||||||||||||
| conwayCostModelsGenerator, | ||||||||||||||
| generateMaybeTaggedSet, | ||||||||||||||
| ) where | ||||||||||||||
|
|
||||||||||||||
| import Cardano.Ledger.Babbage.HuddleSpec hiding ( | ||||||||||||||
|
|
@@ -83,21 +86,35 @@ import Cardano.Ledger.Huddle.Gen ( | |||||||||||||
| MonadGen (choose, resize), | ||||||||||||||
| RuleTerm (..), | ||||||||||||||
| Term (..), | ||||||||||||||
| antiChoose, | ||||||||||||||
| antiVectorOfUnique, | ||||||||||||||
| arbitrary, | ||||||||||||||
| faultyNum, | ||||||||||||||
| genArrayTerm, | ||||||||||||||
| genMapTerm, | ||||||||||||||
| genRule, | ||||||||||||||
| generateFromGRef, | ||||||||||||||
| liftAntiGen, | ||||||||||||||
| oneof, | ||||||||||||||
| replicateMNorm, | ||||||||||||||
| shuffle, | ||||||||||||||
| unwrapSingle, | ||||||||||||||
| unwrapSingleOrError, | ||||||||||||||
| validateArrayTerm, | ||||||||||||||
| validateFromGRef, | ||||||||||||||
| withAntiGen, | ||||||||||||||
| (|!), | ||||||||||||||
| ) | ||||||||||||||
| import Cardano.Ledger.Huddle.Gen qualified as Gen | ||||||||||||||
| import Control.Monad (unless) | ||||||||||||||
| import Data.Foldable (traverse_) | ||||||||||||||
| import Data.List (nubBy) | ||||||||||||||
| import Data.Maybe (fromMaybe) | ||||||||||||||
| import Data.Proxy (Proxy (..)) | ||||||||||||||
| import Data.Traversable (forM) | ||||||||||||||
| import Data.Word (Word64) | ||||||||||||||
| import GHC.TypeLits (KnownSymbol) | ||||||||||||||
| import Test.QuickCheck qualified as QC | ||||||||||||||
| import Text.Heredoc | ||||||||||||||
| import Prelude hiding ((/)) | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -706,18 +723,51 @@ conwayRedeemer pname p = | |||||||||||||
| , "ex_units" ==> huddleRule @"ex_units" p | ||||||||||||||
| ] | ||||||||||||||
|
|
||||||||||||||
| generateMaybeTaggedSet :: Int -> CBORGen Term -> CBORGen Term | ||||||||||||||
| generateMaybeTaggedSet nElems gen = do | ||||||||||||||
| elems <- fromMaybe QC.discard <$> withAntiGen (antiVectorOfUnique nElems) gen | ||||||||||||||
| elemsArr <- genArrayTerm elems | ||||||||||||||
| tagged <- arbitrary | ||||||||||||||
| if tagged | ||||||||||||||
| then do | ||||||||||||||
| t <- liftAntiGen $ faultyNum 258 | ||||||||||||||
| pure $ TTagged t elemsArr | ||||||||||||||
| else pure elemsArr | ||||||||||||||
|
|
||||||||||||||
| mkMaybeTaggedSet :: | ||||||||||||||
| forall name a. (KnownSymbol name, IsType0 a) => Proxy name -> Word64 -> a -> GRuleCall | ||||||||||||||
| mkMaybeTaggedSet pname n = binding $ \x -> pname =.= tag 258 (arr [n <+ a x]) / sarr [n <+ a x] | ||||||||||||||
| forall name a. | ||||||||||||||
| (KnownSymbol name, IsType0 a) => Proxy name -> Int -> (Term -> Term -> Bool) -> a -> GRuleCall | ||||||||||||||
| mkMaybeTaggedSet pname n eq = binding $ \x -> | ||||||||||||||
|
Comment on lines
+738
to
+740
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (As discussed on a call)
Suggested change
|
||||||||||||||
| withCBORGen (generator x) | ||||||||||||||
| . withValidator (validator x) | ||||||||||||||
| $ pname =.= tag 258 (arr [fromIntegral n <+ a x]) / sarr [fromIntegral n <+ a x] | ||||||||||||||
| where | ||||||||||||||
| generator :: GRef -> CBORGen RuleTerm | ||||||||||||||
| generator ref = do | ||||||||||||||
| nElems <- liftAntiGen . Gen.sized $ \sz -> | ||||||||||||||
| let sz' = max n sz in antiChoose (n, sz') (0, sz') | ||||||||||||||
| fmap SingleTerm . generateMaybeTaggedSet nElems $ unwrapSingleOrError <$> generateFromGRef ref | ||||||||||||||
| validator ref term = do | ||||||||||||||
| term_ <- unwrapSingle term | ||||||||||||||
| let | ||||||||||||||
| validateInner t = do | ||||||||||||||
| elems <- validateArrayTerm t | ||||||||||||||
| unless (length elems == length (nubBy eq elems)) $ | ||||||||||||||
| fail "not all elements are unique" | ||||||||||||||
| traverse_ (validateFromGRef ref) elems | ||||||||||||||
| case term_ of | ||||||||||||||
| TTagged t x | t == 258 -> validateInner x | ||||||||||||||
| x -> validateInner x | ||||||||||||||
|
|
||||||||||||||
| maybeTaggedSet :: IsType0 a => Proxy "set" -> a -> GRuleCall | ||||||||||||||
| maybeTaggedSet pname = mkMaybeTaggedSet pname 0 | ||||||||||||||
| maybeTaggedSet pname = mkMaybeTaggedSet pname 0 (==) | ||||||||||||||
|
|
||||||||||||||
| maybeTaggedNonemptySet :: IsType0 a => Proxy "nonempty_set" -> a -> GRuleCall | ||||||||||||||
| maybeTaggedNonemptySet pname = mkMaybeTaggedSet pname 1 | ||||||||||||||
| maybeTaggedNonemptySet pname = mkMaybeTaggedSet pname 1 (==) | ||||||||||||||
|
|
||||||||||||||
| maybeTaggedNonemptyOset :: IsType0 a => Proxy "nonempty_oset" -> a -> GRuleCall | ||||||||||||||
|
Soupstraw marked this conversation as resolved.
|
||||||||||||||
| maybeTaggedNonemptyOset pname = mkMaybeTaggedSet pname 1 | ||||||||||||||
| maybeTaggedNonemptyOset :: | ||||||||||||||
| IsType0 a => Proxy "nonempty_oset" -> (Term -> Term -> Bool) -> a -> GRuleCall | ||||||||||||||
| maybeTaggedNonemptyOset pname eq = mkMaybeTaggedSet pname 1 eq | ||||||||||||||
|
|
||||||||||||||
| instance HuddleRule "bounded_bytes" ConwayEra where | ||||||||||||||
| huddleRuleNamed pname _ = boundedBytesRule pname | ||||||||||||||
|
|
@@ -1372,7 +1422,7 @@ instance HuddleRule1 "nonempty_set" ConwayEra where | |||||||||||||
| huddleRule1Named pname _ = maybeTaggedNonemptySet pname | ||||||||||||||
|
|
||||||||||||||
| instance HuddleRule1 "nonempty_oset" ConwayEra where | ||||||||||||||
| huddleRule1Named pname _ = maybeTaggedNonemptyOset pname | ||||||||||||||
| huddleRule1Named pname _ = maybeTaggedNonemptyOset pname (==) | ||||||||||||||
|
|
||||||||||||||
| instance HuddleRule1 "multiasset" ConwayEra where | ||||||||||||||
| huddleRule1Named = conwayMultiasset | ||||||||||||||
|
|
||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.