Skip to content

Commit

Permalink
Update downstream dependencies in ouroboros-consensus-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisdral authored and jasagredo committed Dec 2, 2022
1 parent 9e9f4bb commit 21cedcf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
Expand Up @@ -120,7 +120,7 @@ import Test.Tasty.QuickCheck (Positive (getPositive), Property,
Small (getSmall), conjoin, counterexample, forAll,
generate, once, testProperty, (.&&.), (===))

import qualified Ouroboros.Consensus.Block.Abstract as Block (SlotNo)
import Ouroboros.Consensus.Block (SlotNo (..))
import qualified Ouroboros.Consensus.Storage.LedgerDB.HD as HD
import qualified Ouroboros.Consensus.Storage.LedgerDB.HD.DiffSeq as DS

Expand Down Expand Up @@ -221,10 +221,10 @@ benchComparative name boundsMay benchEnv =
Commands
-------------------------------------------------------------------------------}

type Pushes (ds :: DiffSeqKind) k v = [(SlotNo ds, Diff ds k v)]
type Pushes (ds :: DiffSeqKind) k v = [(SlotNo, Diff ds k v)]

data Cmd (ds :: DiffSeqKind) k v =
Push (SlotNo ds) (Diff ds k v)
Push SlotNo (Diff ds k v)
| Flush Int
| Switch Int (Pushes ds k v)
| Forward (Values ds k v) (Keys ds k v)
Expand All @@ -234,32 +234,28 @@ deriving anyclass instance ( NFData (ds k v)
, NFData (Diff ds k v)
, NFData (Values ds k v)
, NFData (Keys ds k v)
, NFData (SlotNo ds)
) => NFData (Cmd ds k v)

deriving stock instance ( Show (ds k v)
, Show (Diff ds k v)
, Show (Values ds k v)
, Show (Keys ds k v)
, Show (SlotNo ds)
) => Show (Cmd ds k v)

deriving stock instance ( Eq (ds k v)
, Eq (Diff ds k v)
, Eq (Values ds k v)
, Eq (Keys ds k v)
, Eq (SlotNo ds)
) => Eq (Cmd ds k v)

instance ( Ord k, Eq v
, Isomorphism (ds k v) (ds' k v)
, Isomorphism (Diff ds k v) (Diff ds' k v)
, Isomorphism (Values ds k v) (Values ds' k v)
, Isomorphism (Keys ds k v) (Keys ds' k v)
, Isomorphism (SlotNo ds) (SlotNo ds')
, Isomorphism (Pushes ds k v) (Pushes ds' k v)
) => Isomorphism (Cmd ds k v) (Cmd ds' k v) where
to (Push sl d) = Push (to sl) (to d)
to (Push sl d) = Push sl (to d)
to (Flush n) = Flush n
to (Switch n ps) = Switch n (to ps)
to (Forward vs ks) = Forward (to vs) (to ks)
Expand Down Expand Up @@ -318,10 +314,9 @@ class IsDiffSeq (ds :: DiffSeqKind) k v where
type Diff ds k v = r | r -> ds k v
type Values ds k v = r | r -> ds k v
type Keys ds k v = r | r -> ds k v
type SlotNo ds = r | r -> ds

-- | Mimicks @'Ouroboros.Consensus.Ledger.Basics.extendDbChangelog.ext'@
push :: ds k v -> SlotNo ds -> Diff ds k v -> ds k v
push :: ds k v -> SlotNo -> Diff ds k v -> ds k v

-- | Mimicks @'Ouroboros.Consensus.Ledger.Basics.flushDbChangelog.split'@
flush :: Int -> ds k v -> (ds k v, ds k v)
Expand Down Expand Up @@ -360,9 +355,8 @@ instance (Ord k, Eq v) => IsDiffSeq DS.DiffSeq k v where
type Diff DS.DiffSeq k v = DS.Diff k v
type Values DS.DiffSeq k v = DS.Values k v
type Keys DS.DiffSeq k v = DS.Keys k v
type SlotNo DS.DiffSeq = DS.SlotNo

push ds sl d = DS.extend' ds $ DS.Element sl d
push = DS.extend
flush = DS.splitlAt
rollback = DS.splitrAtFromEnd
forwardValuesAndKeys = DS.forwardValuesAndKeys
Expand All @@ -372,7 +366,6 @@ instance Ord k => IsDiffSeq HD.SeqUtxoDiff k v where
type Diff HD.SeqUtxoDiff k v = HD.UtxoDiff k v
type Values HD.SeqUtxoDiff k v = HD.UtxoValues k v
type Keys HD.SeqUtxoDiff k v = HD.UtxoKeys k v
type SlotNo HD.SeqUtxoDiff = Block.SlotNo

push = HD.extendSeqUtxoDiff
flush = HD.splitAtSeqUtxoDiff
Expand Down Expand Up @@ -548,7 +541,7 @@ genInitialModel ::
-> Gen (Model k v)
genInitialModel GenConfig{nrInitialValues} = do
kvs <- replicateM nrInitialValues arbitrary
pure $ Model mempty 0 (DS.valuesFromList kvs) 0
pure $ Model DS.empty 0 (DS.valuesFromList kvs) 0

newtype Key = Key ShortByteString
deriving stock (Show, Eq, Ord, Generic)
Expand Down Expand Up @@ -748,8 +741,8 @@ warmup = do
-- | Generate a @'Push'@ command.
--
-- > data Cmd (ds :: DiffSeqKind) k v =
-- > Push (SlotNo i) (Diff i k v)
-- > -- ...
-- Push SlotNo (Diff ds k v)
-- -- ...
--
-- Steps to generate a @'Push'@ command:
-- * Forward flushed values.
Expand Down Expand Up @@ -889,7 +882,7 @@ genSwitch = do

Exn.assert invariant $ pure $ Switch n ps
where
fromPushCmd :: Cmd i k v -> (SlotNo i, Diff i k v)
fromPushCmd :: Cmd ds k v -> (SlotNo, Diff ds k v)
fromPushCmd = \case
Push sl d -> (sl, d)
_ -> error "fromPushCmd"
Expand All @@ -898,7 +891,7 @@ genSwitch = do
--
-- > data Cmd (ds :: DiffSeqKind) k v =
-- > -- ...
-- > | Forward (Values i k v) (Keys i k v)
-- > | Forward (Values ds k v) (Keys ds k v)
--
-- Steps to generate a @'Forward'@ command:
-- * Determine which keys to forward.
Expand Down
Expand Up @@ -16,7 +16,7 @@ import Data.Sequence.NonEmpty (NESeq (..))
import Ouroboros.Consensus.Storage.LedgerDB.HD.DiffSeq
(InternalMeasure (..), RootMeasure (..))
import qualified Ouroboros.Consensus.Storage.LedgerDB.HD.DiffSeq as DS
(Length (..), SlotNo (..))
(Length (..), SlotNoLB (..), SlotNoUB (..))

import Test.Util.Orphans.Slotting.Arbitrary ()

Expand Down Expand Up @@ -52,7 +52,8 @@ instance (Ord k, Arbitrary k, Arbitrary v)
arbitrary = RootMeasure <$> arbitrary <*> arbitrary

instance Arbitrary (InternalMeasure k v) where
arbitrary = InternalMeasure <$> arbitrary <*> arbitrary
arbitrary = InternalMeasure <$> arbitrary <*> arbitrary <*> arbitrary

deriving newtype instance Arbitrary DS.Length
deriving newtype instance Arbitrary DS.SlotNo
deriving newtype instance Arbitrary DS.SlotNoUB
deriving newtype instance Arbitrary DS.SlotNoLB
27 changes: 19 additions & 8 deletions ouroboros-consensus-test/src/Test/Util/Orphans/Isomorphism.hs
Expand Up @@ -74,15 +74,17 @@ instance (Isomorphism a c, Isomorphism b d) => Isomorphism (a, b) (c, d) where

instance (Ord k, Eq v)
=> Isomorphism (DS.DiffSeq k v) (HD.SeqUtxoDiff k v) where
to (DS.DiffSeq ft) = HD.SeqUtxoDiff . FT.fromList . map to' . toList $ ft
to (DS.UnsafeDiffSeq ft) =
HD.SeqUtxoDiff . FT.fromList . map to' . toList $ ft
where
to' (DS.Element slot d)= HD.SudElement (to slot) (to d)
to' (DS.Element slot d)= HD.SudElement slot (to d)

instance (Ord k, Eq v)
=> Isomorphism (HD.SeqUtxoDiff k v) (DS.DiffSeq k v) where
to (HD.SeqUtxoDiff ft) = DS.DiffSeq . RMFT.fromList . map to' . toList $ ft
to (HD.SeqUtxoDiff ft) =
DS.UnsafeDiffSeq . RMFT.fromList . map to' . toList $ ft
where
to' (HD.SudElement slot d) = DS.Element (to slot) (to d)
to' (HD.SudElement slot d) = DS.Element slot (to d)

instance Eq v => Isomorphism (MapDiff.Diff k v) (HD.UtxoDiff k v) where
to (MapDiff.Diff m) = HD.UtxoDiff (fmap to' m)
Expand Down Expand Up @@ -123,8 +125,17 @@ instance Isomorphism (MapDiff.Keys k v) (HD.UtxoKeys k v) where
instance Isomorphism (HD.UtxoKeys k v) (MapDiff.Keys k v) where
to (HD.UtxoKeys m) = MapDiff.Keys m

instance Isomorphism DS.SlotNo Block.SlotNo where
to (DS.SlotNo slot) = slot
instance Isomorphism Block.SlotNo Block.SlotNo where
to = id

instance Isomorphism Block.SlotNo DS.SlotNo where
to = DS.SlotNo
instance Isomorphism DS.SlotNoUB Block.SlotNo where
to = DS.unSlotNoUB

instance Isomorphism DS.SlotNoLB Block.SlotNo where
to = DS.unSlotNoLB

instance Isomorphism Block.SlotNo DS.SlotNoUB where
to = DS.SlotNoUB

instance Isomorphism Block.SlotNo DS.SlotNoLB where
to = DS.SlotNoLB
5 changes: 3 additions & 2 deletions ouroboros-consensus-test/src/Test/Util/Orphans/NFData.hs
Expand Up @@ -24,7 +24,7 @@ import Ouroboros.Consensus.Storage.LedgerDB.HD (SeqUtxoDiff (..),
UtxoValues (..))
import Ouroboros.Consensus.Storage.LedgerDB.HD.DiffSeq (DiffSeq (..),
Element (..), InternalMeasure (..), Length (..),
RootMeasure (..), SlotNo (..))
RootMeasure (..), SlotNoLB (..), SlotNoUB (..))

{------------------------------------------------------------------------------
StrictFingerTree
Expand Down Expand Up @@ -69,7 +69,8 @@ deriving newtype instance NFData k => NFData (Keys k v)
deriving newtype instance (NFData k, NFData v) => NFData (Values k v)

deriving newtype instance NFData Length
deriving newtype instance NFData SlotNo
deriving newtype instance NFData SlotNoUB
deriving newtype instance NFData SlotNoLB

deriving anyclass instance (NFData k, NFData v) => NFData (RootMeasure k v)
deriving anyclass instance (NFData k, NFData v) => NFData (InternalMeasure k v)
Expand Down

0 comments on commit 21cedcf

Please sign in to comment.