Skip to content

Commit

Permalink
shelley-test: introduce Byron-compatible mock crypto for cardano tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrisby committed Aug 4, 2020
1 parent 4355581 commit a56ebb7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
6 changes: 4 additions & 2 deletions ouroboros-consensus-cardano/test/Test/ThreadNet/Cardano.hs
Expand Up @@ -63,7 +63,7 @@ import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Cardano.Condense ()
import Ouroboros.Consensus.Cardano.Node

import Test.Consensus.Shelley.MockCrypto (TPraosMockCrypto)
import Test.Consensus.Shelley.MockCrypto (TPraosMockCryptoCompatByron)
import Test.ThreadNet.General
import qualified Test.ThreadNet.Infra.Byron as Byron
import qualified Test.ThreadNet.Infra.Shelley as Shelley
Expand All @@ -81,7 +81,9 @@ import Test.Util.HardFork.Future
import Test.Util.Orphans.Arbitrary ()
import Test.Util.Slots (NumSlots (..))

type Crypto = TPraosMockCrypto Blake2b_256
-- | Use 'TPraosMockCryptoCompatByron' so that bootstrap addresses and
-- bootstrap witnesses are supported.
type Crypto = TPraosMockCryptoCompatByron Blake2b_256

-- | When and for how long the nodes are partitioned
--
Expand Down
Expand Up @@ -8,8 +8,8 @@ import Ouroboros.Consensus.Cardano

import Test.ThreadNet.TxGen

import Test.Consensus.Shelley.MockCrypto (TPraosMockCrypto)
import Test.Consensus.Shelley.MockCrypto (TPraosMockCryptoCompatByron)

instance TxGen (CardanoBlock (TPraosMockCrypto h)) where
instance TxGen (CardanoBlock (TPraosMockCryptoCompatByron h)) where
-- TODO
testGenTxs _ _ _ _ _ = return []
Expand Up @@ -3,12 +3,16 @@
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Test.Consensus.Shelley.MockCrypto (
-- * Mock
TPraosMockCrypto
, Block
-- * Byron-compatible Mock
, TPraosMockCryptoCompatByron
, BlockCompatByron
) where

import Cardano.Crypto.DSIGN (MockDSIGN)
import Cardano.Crypto.Hash (HashAlgorithm)
import Cardano.Crypto.DSIGN (Ed25519DSIGN, MockDSIGN)
import Cardano.Crypto.Hash (Blake2b_224, HashAlgorithm)
import Cardano.Crypto.KES (MockKES)

import Test.Cardano.Crypto.VRF.Fake (FakeVRF)
Expand Down Expand Up @@ -36,3 +40,29 @@ instance HashAlgorithm h => Crypto (TPraosMockCrypto h) where
instance HashAlgorithm h => TPraosCrypto (TPraosMockCrypto h)

type Block h = ShelleyBlock (TPraosMockCrypto h)

-- | Like 'TPraosMockCrypto' except mocks fewer components in order to be
-- compatible with bootstrapping from Byron
--
-- Note that mocking less components does prevent the @cardano-ledger-specs@
-- generators from being used. Currently, this is not an obstacle for example
-- in the Cardano ThreadNet tests.
--
-- NOTE: The "Ouroboros.Consensus.Cardano.CanHardFork" translation currently
-- assumes that @ADDRHASH@ has the same bit size as Byron address hashes (ie
-- 224); that's why we use 'Black25_224' here.
--
-- NOTE: The @shelley-spec-ledger@ package currently requires that @'DSIGN' ~
-- 'Ed25519DSIGN'.
data TPraosMockCryptoCompatByron h

instance HashAlgorithm h => Crypto (TPraosMockCryptoCompatByron h) where
type ADDRHASH (TPraosMockCryptoCompatByron h) = Blake2b_224
type DSIGN (TPraosMockCryptoCompatByron h) = Ed25519DSIGN
type HASH (TPraosMockCryptoCompatByron h) = h
type KES (TPraosMockCryptoCompatByron h) = MockKES 10
type VRF (TPraosMockCryptoCompatByron h) = FakeVRF

instance HashAlgorithm h => TPraosCrypto (TPraosMockCryptoCompatByron h)

type BlockCompatByron h = ShelleyBlock (TPraosMockCryptoCompatByron h)

0 comments on commit a56ebb7

Please sign in to comment.