Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Consenus tests for Conway era. Also extended
Test.Cardano.Ledger.Generic.Proof and related modules to the Conway era.
- Loading branch information
Showing
22 changed files
with
579 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
cabal-version: 3.0 | ||
|
||
name: cardano-ledger-conway-test | ||
version: 0.1.0.0 | ||
synopsis: Tests for Cardano ledger conway era | ||
description: | ||
This package builds upon the Alonzo ledger | ||
bug-reports: https://github.com/input-output-hk/cardano-ledger/issues | ||
license: Apache-2.0 | ||
author: IOHK Formal Methods Team | ||
maintainer: formal.methods@iohk.io | ||
copyright: 2020 Input Output (Hong Kong) Ltd. | ||
category: Network | ||
build-type: Simple | ||
|
||
data-files: | ||
cddl-files/conway.cddl | ||
cddl-files/real/crypto.cddl | ||
cddl-files/mock/extras.cddl | ||
|
||
source-repository head | ||
type: git | ||
location: https://github.com/input-output-hk/cardano-ledger | ||
subdir: eras/conway/test-suite | ||
|
||
common base | ||
build-depends: base >= 4.12 && < 4.15 | ||
|
||
common project-config | ||
default-language: Haskell2010 | ||
|
||
ghc-options: -Wall | ||
-Wcompat | ||
-Wincomplete-record-updates | ||
-Wincomplete-uni-patterns | ||
-Wpartial-fields | ||
-Wredundant-constraints | ||
-- -Wunused-packages | ||
|
||
library | ||
import: base, project-config | ||
|
||
exposed-modules: | ||
Test.Cardano.Ledger.Conway.Examples.Consensus, | ||
build-depends: | ||
bytestring, | ||
cardano-binary, | ||
cardano-ledger-alonzo, | ||
cardano-ledger-alonzo-test, | ||
cardano-ledger-babbage, | ||
cardano-ledger-conway, | ||
cardano-ledger-core, | ||
cardano-ledger-pretty, | ||
cardano-ledger-shelley-ma-test, | ||
cardano-ledger-shelley-ma, | ||
cardano-protocol-tpraos, | ||
cardano-slotting, | ||
containers, | ||
data-default-class, | ||
hashable, | ||
plutus-tx, | ||
plutus-ledger-api, | ||
QuickCheck, | ||
cardano-ledger-shelley-test, | ||
cardano-ledger-shelley, | ||
small-steps, | ||
strict-containers, | ||
text, | ||
hs-source-dirs: | ||
src | ||
|
196 changes: 196 additions & 0 deletions
196
eras/conway/test-suite/src/Test/Cardano/Ledger/Conway/Examples/Consensus.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
{-# LANGUAGE AllowAmbiguousTypes #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
module Test.Cardano.Ledger.Conway.Examples.Consensus where | ||
|
||
import Cardano.Ledger.Alonzo.Data | ||
( AlonzoAuxiliaryData (..), | ||
AuxiliaryDataHash (..), | ||
Data (..), | ||
dataToBinaryData, | ||
hashData, | ||
) | ||
import Cardano.Ledger.Alonzo.Language (Language (..)) | ||
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript (..), ExUnits (..)) | ||
import qualified Cardano.Ledger.Alonzo.Scripts as Tag (Tag (..)) | ||
import Cardano.Ledger.Alonzo.Tx (IsValid (..)) | ||
import Cardano.Ledger.Alonzo.TxWitness (RdmrPtr (..), Redeemers (..), TxDats (..)) | ||
import Cardano.Ledger.Babbage.TxBody (Datum (..)) | ||
import Cardano.Ledger.BaseTypes (StrictMaybe (..)) | ||
import Cardano.Ledger.Coin (Coin (..)) | ||
import Cardano.Ledger.Conway (ConwayEra) | ||
import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) | ||
import Cardano.Ledger.Conway.PParams (BabbagePParamsHKD (..), emptyPParams, emptyPParamsUpdate) | ||
import Cardano.Ledger.Conway.Translation () | ||
import Cardano.Ledger.Conway.Tx (AlonzoTx (..)) | ||
import Cardano.Ledger.Conway.TxBody (BabbageTxBody (..), BabbageTxOut (..)) | ||
import Cardano.Ledger.Conway.TxWits (TxWitness (..)) | ||
import Cardano.Ledger.Core (EraScript (hashScript), TxBody) | ||
import Cardano.Ledger.Credential (Credential (KeyHashObj, ScriptHashObj)) | ||
import Cardano.Ledger.Crypto (StandardCrypto) | ||
import Cardano.Ledger.Keys (GenDelegs (..), asWitness) | ||
import Cardano.Ledger.Mary.Value (MaryValue (..)) | ||
import Cardano.Ledger.SafeHash (hashAnnotated) | ||
import Cardano.Ledger.Serialization (mkSized) | ||
import Cardano.Ledger.Shelley.API (ApplyTxError (..), Network (..), NewEpochState (..), ProposedPPUpdates (..), RewardAcnt (..), TxId (..), Update (..), Wdrl (..)) | ||
import Cardano.Ledger.Shelley.Rules.Delegs (DelegsPredicateFailure (..)) | ||
import Cardano.Ledger.Shelley.Rules.Ledger (LedgerPredicateFailure (DelegsFailure)) | ||
import Cardano.Ledger.Shelley.Tx (ShelleyTx (..)) | ||
import Cardano.Ledger.Shelley.UTxO (makeWitnessesVKey) | ||
import Cardano.Ledger.ShelleyMA.Timelocks (Timelock (..), ValidityInterval (..)) | ||
import Cardano.Ledger.TxIn (mkTxInPartial) | ||
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..)) | ||
import Data.Default.Class (Default (def)) | ||
import qualified Data.Map.Strict as Map | ||
import Data.Proxy (Proxy (..)) | ||
import qualified Data.Sequence.Strict as StrictSeq | ||
import qualified Data.Set as Set | ||
import qualified PlutusTx as Plutus | ||
import Test.Cardano.Ledger.Alonzo.Scripts (alwaysFails, alwaysSucceeds) | ||
import qualified Test.Cardano.Ledger.Mary.Examples.Consensus as MarySLE | ||
import qualified Test.Cardano.Ledger.Shelley.Examples.Consensus as SLE | ||
import Test.Cardano.Ledger.Shelley.Orphans () | ||
import Test.Cardano.Ledger.Shelley.Utils (mkAddr) | ||
|
||
-- ============================================================== | ||
|
||
type StandardConway = ConwayEra StandardCrypto | ||
|
||
-- | ShelleyLedgerExamples for Conway era | ||
ledgerExamplesConway :: SLE.ShelleyLedgerExamples StandardConway | ||
ledgerExamplesConway = | ||
SLE.ShelleyLedgerExamples | ||
{ SLE.sleBlock = SLE.exampleShelleyLedgerBlock exampleTransactionInBlock, | ||
SLE.sleHashHeader = SLE.exampleHashHeader (Proxy @StandardConway), | ||
SLE.sleTx = exampleTransactionInBlock, | ||
SLE.sleApplyTxError = | ||
ApplyTxError $ | ||
pure $ | ||
DelegsFailure $ | ||
DelegateeNotRegisteredDELEG @StandardConway (SLE.mkKeyHash 1), | ||
SLE.sleRewardsCredentials = | ||
Set.fromList | ||
[ Left (Coin 100), | ||
Right (ScriptHashObj (SLE.mkScriptHash 1)), | ||
Right (KeyHashObj (SLE.mkKeyHash 2)) | ||
], | ||
SLE.sleResultExamples = resultExamples, | ||
SLE.sleNewEpochState = exampleConwayNewEpochState, | ||
SLE.sleChainDepState = SLE.exampleLedgerChainDepState 1, | ||
SLE.sleTranslationContext = exampleConwayGenesis | ||
} | ||
where | ||
resultExamples = | ||
SLE.ShelleyResultExamples | ||
{ SLE.srePParams = def, | ||
SLE.sreProposedPPUpdates = examplePPPU, | ||
SLE.srePoolDistr = SLE.examplePoolDistr, | ||
SLE.sreNonMyopicRewards = SLE.exampleNonMyopicRewards, | ||
SLE.sreShelleyGenesis = SLE.testShelleyGenesis | ||
} | ||
examplePPPU = | ||
ProposedPPUpdates $ | ||
Map.singleton | ||
(SLE.mkKeyHash 0) | ||
(emptyPParamsUpdate {_collateralPercentage = SJust 150}) | ||
|
||
collateralOutput :: BabbageTxOut StandardConway | ||
collateralOutput = | ||
BabbageTxOut | ||
(mkAddr (SLE.examplePayKey, SLE.exampleStakeKey)) | ||
(MaryValue 8675309 mempty) | ||
NoDatum | ||
SNothing | ||
|
||
exampleTxBodyConway :: TxBody StandardConway | ||
exampleTxBodyConway = | ||
BabbageTxBody | ||
(Set.fromList [mkTxInPartial (TxId (SLE.mkDummySafeHash Proxy 1)) 0]) -- spending inputs | ||
(Set.fromList [mkTxInPartial (TxId (SLE.mkDummySafeHash Proxy 2)) 1]) -- collateral inputs | ||
(Set.fromList [mkTxInPartial (TxId (SLE.mkDummySafeHash Proxy 1)) 3]) -- reference inputs | ||
( StrictSeq.fromList | ||
[ mkSized $ | ||
BabbageTxOut | ||
(mkAddr (SLE.examplePayKey, SLE.exampleStakeKey)) | ||
(MarySLE.exampleMultiAssetValue 2) | ||
(Datum $ dataToBinaryData datumExample) -- inline datum | ||
(SJust $ alwaysSucceeds PlutusV2 3) -- reference script | ||
] | ||
) | ||
(SJust $ mkSized collateralOutput) -- collateral return | ||
(SJust $ Coin 8675309) -- collateral tot | ||
SLE.exampleCerts -- txcerts | ||
( Wdrl $ | ||
Map.singleton | ||
(RewardAcnt Testnet (SLE.keyToCredential SLE.exampleStakeKey)) | ||
(Coin 100) -- txwdrls | ||
) | ||
(Coin 999) -- txfee | ||
(ValidityInterval (SJust (SlotNo 2)) (SJust (SlotNo 4))) -- txvldt | ||
( SJust $ | ||
Update | ||
( ProposedPPUpdates $ | ||
Map.singleton | ||
(SLE.mkKeyHash 1) | ||
(emptyPParamsUpdate {_maxBHSize = SJust 4000}) | ||
) | ||
(EpochNo 0) | ||
) -- txUpdates | ||
(Set.singleton $ SLE.mkKeyHash 212) -- reqSignerHashes | ||
(MarySLE.exampleMultiAssetValue 3) -- mint | ||
(SJust $ SLE.mkDummySafeHash (Proxy @StandardCrypto) 42) -- scriptIntegrityHash | ||
(SJust . AuxiliaryDataHash $ SLE.mkDummySafeHash (Proxy @StandardCrypto) 42) -- adHash | ||
(SJust Mainnet) -- txnetworkid | ||
|
||
datumExample :: Data StandardConway | ||
datumExample = Data (Plutus.I 191) | ||
|
||
redeemerExample :: Data StandardConway | ||
redeemerExample = Data (Plutus.I 919) | ||
|
||
exampleTx :: ShelleyTx StandardConway | ||
exampleTx = | ||
ShelleyTx | ||
exampleTxBodyConway | ||
( TxWitness | ||
(makeWitnessesVKey (hashAnnotated exampleTxBodyConway) [asWitness SLE.examplePayKey]) -- vkey | ||
mempty -- bootstrap | ||
( Map.singleton | ||
(hashScript @StandardConway $ alwaysSucceeds PlutusV1 3) | ||
(alwaysSucceeds PlutusV1 3) -- txscripts | ||
) | ||
(TxDats $ Map.singleton (hashData datumExample) datumExample) | ||
( Redeemers $ | ||
Map.singleton (RdmrPtr Tag.Spend 0) (redeemerExample, ExUnits 5000 5000) | ||
) -- redeemers | ||
) | ||
( SJust $ | ||
AlonzoAuxiliaryData | ||
SLE.exampleMetadataMap -- metadata | ||
( StrictSeq.fromList | ||
[alwaysFails PlutusV1 2, TimelockScript $ RequireAllOf mempty] -- Scripts | ||
) | ||
) | ||
|
||
exampleTransactionInBlock :: AlonzoTx StandardConway | ||
exampleTransactionInBlock = AlonzoTx b w (IsValid True) a | ||
where | ||
(ShelleyTx b w a) = exampleTx | ||
|
||
exampleConwayNewEpochState :: NewEpochState StandardConway | ||
exampleConwayNewEpochState = | ||
SLE.exampleNewEpochState | ||
(MarySLE.exampleMultiAssetValue 1) | ||
emptyPParams | ||
(emptyPParams {_coinsPerUTxOByte = Coin 1}) | ||
|
||
exampleConwayGenesis :: ConwayGenesis crypto | ||
exampleConwayGenesis = | ||
ConwayGenesis (GenDelegs Map.empty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.