Skip to content

Commit

Permalink
ouroboros-consensus-shelley-test: introduce CanMockPreAlonzo workaround
Browse files Browse the repository at this point in the history
This is a temporary workaround; the AlonzoEra does not satisfy
CanMockPreAlonzo, so we cannot use CanMockPreAlonzo for instances that are
elsewhere required for each element of CardanoEras. Thankfully, only these uses
of CanMockPreAlonzo need the Alonzo-incompatible constraints, and these three
are also not requires of CardanoEras.
  • Loading branch information
nfrisby committed May 13, 2021
1 parent a211491 commit 1f198bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Expand Up @@ -38,7 +38,7 @@ import Test.Util.Serialisation.Roundtrip (Coherent (..),
import Test.Cardano.Ledger.AllegraEraGen ()
import Test.Cardano.Ledger.MaryEraGen ()
import Test.Cardano.Ledger.ShelleyMA.Serialisation.Generators ()
import Test.Consensus.Shelley.MockCrypto (CanMock)
import Test.Consensus.Shelley.MockCrypto (CanMock, CanMockPreAlonzo)
import Test.Shelley.Spec.Ledger.ConcreteCryptoTypes as SL
import Test.Shelley.Spec.Ledger.Generator.ShelleyEraGen ()
import Test.Shelley.Spec.Ledger.Serialisation.EraIndepGenerators
Expand All @@ -54,21 +54,21 @@ import Test.Shelley.Spec.Ledger.Serialisation.Generators ()

-- | The upstream 'Arbitrary' instance for Shelley blocks does not generate
-- coherent blocks, so neither does this.
instance CanMock era => Arbitrary (ShelleyBlock era) where
instance CanMockPreAlonzo era => Arbitrary (ShelleyBlock era) where
arbitrary = mkShelleyBlock <$> arbitrary

-- | This uses a different upstream generator to ensure the header and block
-- body relate as expected.
instance CanMock era => Arbitrary (Coherent (ShelleyBlock era)) where
instance CanMockPreAlonzo era => Arbitrary (Coherent (ShelleyBlock era)) where
arbitrary = Coherent . mkShelleyBlock <$> genCoherentBlock

instance CanMock era => Arbitrary (Header (ShelleyBlock era)) where
instance CanMockPreAlonzo era => Arbitrary (Header (ShelleyBlock era)) where
arbitrary = getHeader <$> arbitrary

instance SL.Mock c => Arbitrary (ShelleyHash c) where
arbitrary = ShelleyHash <$> arbitrary

instance CanMock era => Arbitrary (GenTx (ShelleyBlock era)) where
instance CanMockPreAlonzo era => Arbitrary (GenTx (ShelleyBlock era)) where
arbitrary = mkShelleyTx <$> arbitrary

instance CanMock era => Arbitrary (GenTxId (ShelleyBlock era)) where
Expand Down
Expand Up @@ -8,6 +8,7 @@
module Test.Consensus.Shelley.MockCrypto (
Block
, CanMock
, CanMockPreAlonzo
, MockCrypto
, MockShelley
) where
Expand Down Expand Up @@ -70,5 +71,11 @@ type CanMock era =
, Arbitrary (Core.TxOut era)
, Arbitrary (Core.Value era)
, Arbitrary (PredicateFailure (SL.UTXOW era))
)

-- | A stronger 'CanMock' that is incompatible with Alonzo
type CanMockPreAlonzo era =
( CanMock era
, Core.TxSeq era ~ SL.TxSeq era
, Core.Witnesses era ~ SL.WitnessSet era
)

0 comments on commit 1f198bf

Please sign in to comment.