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

Minor bugfixes #2563

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ genTxAndLEDGERState = do
txIx <- arbitrary
maxTxExUnits <- arbitrary
Positive maxCollateralInputs <- arbitrary
collateralPercentage <- fromIntegral <$> chooseInt (0, 10000)
collateralPercentage <- fromIntegral <$> chooseInt (1, 10000)
minfeeA <- fromIntegral <$> chooseInt (0, 1000)
minfeeB <- fromIntegral <$> chooseInt (0, 10000)
let genT = do
Expand Down
14 changes: 11 additions & 3 deletions libs/small-steps/src/Control/Iterate/SetAlgebra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
Expand All @@ -17,6 +18,7 @@ module Control.Iterate.SetAlgebra where

import Cardano.Binary
( Decoder,
DecoderError (DecoderErrorCustom),
FromCBOR (..),
ToCBOR (..),
decodeListLen,
Expand All @@ -26,8 +28,8 @@ import Cardano.Binary
import Codec.CBOR.Encoding (encodeListLen)
import Control.DeepSeq (NFData (rnf))
import Control.Iterate.Collect
import Control.Monad (void)
import Data.Coders (invalidKey)
import Control.Monad (unless, void)
import Data.Coders (cborError, invalidKey)
import Data.List (sortBy)
import qualified Data.List as List
import Data.Map.Internal (Map (..), link, link2)
Expand Down Expand Up @@ -179,7 +181,11 @@ instance
decodeMapAsBimap ::
(FromCBOR a, FromCBOR b, Ord a, Ord b) =>
Decoder s (BiMap b a b)
decodeMapAsBimap = decodeMapSkel biMapFromAscDistinctList
decodeMapAsBimap = do
bimap@(MkBiMap mf mb) <- decodeMapSkel biMapFromAscDistinctList
unless (Map.valid mf && Map.valid mb) $
cborError $ DecoderErrorCustom "BiMap" "Expected distinct keys in ascending order"
pure bimap

instance (NoThunks a, NoThunks b) => NoThunks (BiMap v a b) where
showTypeOf _ = "BiMap"
Expand Down Expand Up @@ -236,6 +242,8 @@ biMapFromList comb xs = foldr addEntry biMapEmpty xs
where
newv = comb oldv v

-- | /Warning/ - invariant that keys are distinct and in ascending order is not
-- checked. Make sure it is not violated, otherwise crazy things will happen.
biMapFromAscDistinctList ::
(Ord k, Ord v) => [(k, v)] -> BiMap v k v
biMapFromAscDistinctList xs = MkBiMap bmForward bmBackward
Expand Down