Skip to content

Commit

Permalink
Merge pull request #2563 from input-output-hk/lehins/minor-bugfixes
Browse files Browse the repository at this point in the history
Minor bugfixes
  • Loading branch information
nc6 committed Nov 24, 2021
2 parents 60e820d + 7ef96a6 commit 93c3dec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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
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

0 comments on commit 93c3dec

Please sign in to comment.