Skip to content

Commit

Permalink
Resolved conflicts and compiler errors after rebasing on master
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSheard committed May 6, 2021
1 parent 2088835 commit e00216f
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 16 deletions.
1 change: 0 additions & 1 deletion alonzo/impl/src/Cardano/Ledger/Alonzo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import Control.Monad (join)
import Control.Monad.Except (liftEither, runExcept)
import Control.Monad.Reader (runReader)
import Control.State.Transition.Extended (TRC (TRC))
import qualified Data.Set as Set
import qualified Shelley.Spec.Ledger.API as API
import qualified Shelley.Spec.Ledger.BaseTypes as Shelley
import Shelley.Spec.Ledger.LedgerState
Expand Down
6 changes: 3 additions & 3 deletions alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Era (Crypto, Era)
import Cardano.Ledger.Mary.Value (Value)
import Cardano.Ledger.Rules.ValidationMode ((?!#))
import Cardano.Ledger.Shelley.Constraints (PParamsDelta)
-- import Cardano.Ledger.Shelley.Constraints (PParamsDelta)
import qualified Cardano.Ledger.Val as Val
import Control.Iterate.SetAlgebra (eval, (∪), (⋪), (◁))
import Control.Monad.Except (MonadError (throwError))
Expand Down Expand Up @@ -279,8 +279,8 @@ constructValidated ::
Era era,
Eq (Core.PParams era),
Show (Core.PParams era),
Show (PParamsDelta era),
Eq (PParamsDelta era),
Show (Core.PParamsDelta era),
Eq (Core.PParamsDelta era),
ToCBOR (Core.AuxiliaryData era),
Environment (Core.EraRule "PPUP" era) ~ PPUPEnv era,
State (Core.EraRule "PPUP" era) ~ PPUPState era,
Expand Down
8 changes: 8 additions & 0 deletions alonzo/test/cardano-ledger-alonzo-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ library

exposed-modules:
Test.Cardano.Ledger.Alonzo.Serialisation.Generators
Test.Cardano.Ledger.Alonzo.EraGenInstance
build-depends:
cardano-binary,
cardano-ledger-alonzo,
cardano-ledger-core,
cardano-ledger-shelley-ma-test,
cardano-ledger-shelley-ma,
cardano-slotting,
containers,
hashable,
plutus-tx,
QuickCheck,
shelley-spec-ledger-test,
shelley-spec-ledger,
strict-containers,
text,
hs-source-dirs:
lib
Expand All @@ -59,6 +65,7 @@ test-suite cardano-ledger-alonzo-test
hs-source-dirs:
test
other-modules:
Test.Cardano.Ledger.Alonzo.Trials
Test.Cardano.Ledger.Alonzo.Golden
Test.Cardano.Ledger.Alonzo.Serialisation.Tripping
Test.Cardano.Ledger.Alonzo.Examples.Bbody
Expand All @@ -75,6 +82,7 @@ test-suite cardano-ledger-alonzo-test
cardano-ledger-shelley-ma,
cardano-ledger-core,
cardano-ledger-shelley-ma-test,
cardano-slotting,
containers,
data-default-class,
plutus-core,
Expand Down
253 changes: 253 additions & 0 deletions alonzo/test/test/Test/Cardano/Ledger/Alonzo/Trials.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}

module Test.Cardano.Ledger.Alonzo.Trials where

-- NO
-- NO
-- NO
-- NO
-- NO
-- NO
-- NO

-- Crypto era only

--

-- import Test.Shelley.Spec.Ledger.Shrinkers (shrinkBlock) -- TODO FIX ME

-- Test.Shelley.Spec.Ledger.Generator.Utxo(genTx)

-- TestPoolReap

-- TestNewEpoch

-- Test Pool

-- Test Delegation

import Cardano.Ledger.Allegra (AllegraEra)
import Cardano.Ledger.Alonzo (AlonzoEra)
import Cardano.Ledger.Alonzo.PParams (PParams, PParams' (..), PParamsUpdate)
import Cardano.Ledger.Alonzo.Rules.Bbody (AlonzoBBODY)
import Cardano.Ledger.Alonzo.Rules.Utxow (AlonzoUTXOW)
import Cardano.Ledger.Alonzo.Scripts (Script (..), ppScript)
import Cardano.Ledger.Coin (Coin (..))
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as CC (Crypto)
import Cardano.Ledger.Era (Era (Crypto))
import Cardano.Ledger.Mary (MaryEra)
import Cardano.Ledger.Pretty (PDoc, PrettyA (prettyA))
import Cardano.Ledger.Shelley (ShelleyEra)
import Cardano.Ledger.Shelley.Constraints (UsesTxBody, UsesTxOut)
import Cardano.Slotting.Slot (SlotNo (..))
import Control.State.Transition.Extended (Embed (..), IRC (..), STS (..))
import Control.State.Transition.Trace.Generator.QuickCheck (HasTrace, forAllTraceFromInitState)
import Data.Default.Class (Default (def))
import qualified Data.Map as Map
import Data.Proxy (Proxy (..))
import Shelley.Spec.Ledger.API (ApplyBlock)
import Shelley.Spec.Ledger.API.Protocol (GetLedgerView)
import Shelley.Spec.Ledger.API.Validation (ApplyBlock)
import Shelley.Spec.Ledger.LedgerState (AccountState (..), DPState (..), DState, EpochState (..), LedgerState (..), NewEpochState (..), PState, UTxOState)
import Shelley.Spec.Ledger.PParams (PParams' (..))
import Shelley.Spec.Ledger.STS.Chain (CHAIN, ChainPredicateFailure (..), ChainState (..), initialShelleyState)
import Shelley.Spec.Ledger.STS.Ledger (LEDGER, LedgerEnv (..), LedgerPredicateFailure (UtxowFailure))
import Test.Cardano.Ledger.Alonzo.EraGenInstance ()
import Test.Cardano.Ledger.Alonzo.Examples.Utxow (plutusScriptExamples, utxowExamples)
import Test.Cardano.Ledger.Alonzo.Golden as Golden
import qualified Test.Cardano.Ledger.Alonzo.Serialisation.CDDL as CDDL
import qualified Test.Cardano.Ledger.Alonzo.Serialisation.Tripping as Tripping
import qualified Test.Cardano.Ledger.Alonzo.Translation as Translation
import Test.Cardano.Ledger.EraBuffet (TestCrypto)
import Test.QuickCheck
import Test.Shelley.Spec.Ledger.ConcreteCryptoTypes (Mock)
import Test.Shelley.Spec.Ledger.Generator.Block (genBlock)
import Test.Shelley.Spec.Ledger.Generator.Constants (Constants (..))
import Test.Shelley.Spec.Ledger.Generator.Core (GenEnv (..), KeySpace (..), mkBlock)
import Test.Shelley.Spec.Ledger.Generator.EraGen
( EraGen (..),
genEraAuxiliaryData,
genEraPParamsDelta,
genEraTxBody,
genGenesisValue,
genUtxo0,
updateEraTxBody,
)
import Test.Shelley.Spec.Ledger.Generator.Presets (genEnv, genesisDelegs0)
import Test.Shelley.Spec.Ledger.Generator.ScriptClass (ScriptClass (..), baseScripts, keyPairs, mkScriptsFromKeyPair, someScripts)
import Test.Shelley.Spec.Ledger.Generator.ShelleyEraGen ()
import Test.Shelley.Spec.Ledger.Generator.Trace.Chain (mkGenesisChainState, registerGenesisStaking)
import Test.Shelley.Spec.Ledger.Generator.Trace.Ledger (genAccountState, mkGenesisLedgerState)
import Test.Shelley.Spec.Ledger.Generator.Utxo (genTx)
import Test.Shelley.Spec.Ledger.PropertyTests
( adaPreservationChain,
collisionFreeComplete,
delegProperties,
minimalPropertyTests,
onlyValidChainSignalsAreGenerated,
onlyValidLedgerSignalsAreGenerated,
poolProperties,
propCompactAddrRoundTrip,
propCompactSerializationAgree,
propDecompactAddrLazy,
propDecompactShelleyLazyAddr,
propertyTests,
relevantCasesAreCovered,
removedAfterPoolreap,
)
import Test.Shelley.Spec.Ledger.Rules.TestChain
( adaPreservationChain,
collisionFreeComplete,
delegProperties,
forAllChainTrace,
poolProperties,
removedAfterPoolreap,
)
import Test.Shelley.Spec.Ledger.Utils
( ChainProperty,
maxLLSupply,
mkHash,
testGlobals,
)
import Test.Tasty

kps = take 10 $ keyPairs @TestCrypto (geConstants ag)

pretty :: PrettyA x => x -> PDoc
pretty = prettyA

ppS = ppScript

ledgerEnv :: forall era. (Default (Core.PParams era)) => LedgerEnv era
ledgerEnv = LedgerEnv (SlotNo 0) 0 def (AccountState (Coin 0) (Coin 0))

baz = genTx ag ledgerEnv

ap :: Proxy (AlonzoEra TestCrypto)
ap = Proxy @(AlonzoEra TestCrypto)

ag :: GenEnv (AlonzoEra TestCrypto)
ag = genEnv ap

genstuff ::
(EraGen era, Default (State (Core.EraRule "PPUP" era))) =>
proxy era ->
( GenEnv era ->
ChainState era ->
NewEpochState era ->
EpochState era ->
LedgerState era ->
Core.PParams era ->
Shelley.Spec.Ledger.LedgerState.UTxOState era ->
DPState (Crypto era) ->
DState (Crypto era) ->
PState (Crypto era) ->
Gen b
) ->
Gen b
genstuff proxy f =
do
let genenv = (genEnv proxy)
either' <- mkGenesisChainState genenv (IRC ())
case either' of
Left _z -> error ("OOPS")
Right chainstate ->
let newepochstate = chainNes chainstate
epochstate = nesEs newepochstate
ledgerstate = esLState epochstate
pparams = esPp epochstate
utxostate = _utxoState ledgerstate
dpstate = _delegationState ledgerstate
dstate = _dstate dpstate
pstate = _pstate dpstate
in (f genenv chainstate newepochstate epochstate ledgerstate pparams utxostate dpstate dstate pstate)

genAlonzoTx = genstuff ap (\genv _cs _nep _ep _ls _pp utxo dp _d _p -> genTx genv ledgerEnv (utxo, dp))

genShelleyTx =
genstuff
(Proxy @(ShelleyEra TestCrypto))
(\genv _cs _nep _ep _ls _pp utxo dp _d _p -> genTx genv ledgerEnv (utxo, dp))

genAlonzoBlock = genstuff ap (\genv cs _nep _ep _ls _pp _utxo _dp _d _p -> genBlock genv cs)

genShelleyBlock = genstuff (Proxy @(ShelleyEra TestCrypto)) (\genv cs _nep _ep _ls _pp _utxo _dp _d _p -> genBlock genv cs)

foo = do
either' <- mkGenesisChainState (genEnv ap) (IRC ())
case either' of
Left _z -> error ("OOPS")
Right chainstate ->
let newepochstate = chainNes chainstate
epochstate = nesEs newepochstate
ledgerstate = esLState epochstate
pparams = esPp epochstate
utxostate = _utxoState ledgerstate
dpstate = _delegationState ledgerstate
dstate = _dstate dpstate
pstate = _pstate dpstate
in pure chainstate

chain = generate foo

env@(GenEnv keys constants) = genEnv (Proxy @(AlonzoEra TestCrypto))

-- in scripts n ranges over [0..149]
scripts n = (\(x, y) -> (ppS x, ppS y)) ((ksMSigScripts keys) !! n)

-- in payscript and stakescript n ranges over [0..29]
payscript n = (\(x, (y, _z)) -> (show x, ppS y)) ((Map.toList (ksIndexedPayScripts keys)) !! n)

stakescript n = (\(x, (y, _z)) -> (show x, ppS y)) ((Map.toList (ksIndexedStakeScripts keys)) !! n)

test = defaultMain (minimalPropertyTests @AT)

bar = do cs <- foo; genBlock ag cs

acs = mkGenesisChainState ag

als = mkGenesisLedgerState ag

instance Embed (AlonzoBBODY (AlonzoEra TestCrypto)) (CHAIN (AlonzoEra TestCrypto)) where
wrapFailed = BbodyFailure

instance Embed (AlonzoUTXOW (AlonzoEra TestCrypto)) (LEDGER (AlonzoEra TestCrypto)) where
wrapFailed = UtxowFailure

-- ====================================================================================

tests :: TestTree
tests =
testGroup
"Alonzo tests"
[ Tripping.tests,
Translation.tests,
CDDL.tests 5,
Golden.goldenUTxOEntryMinAda,
plutusScriptExamples,
utxowExamples
]

{-
alonzoProperty = testGroup
"Alonzo minimal property tests"
[ minimalPropertyTests @(AlonzoEra TestCrypto)
]
-}

type AT = AlonzoEra TestCrypto

type T = TestCrypto

main :: IO ()
main = defaultMain tests
10 changes: 1 addition & 9 deletions alonzo/test/test/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@

module Main where



import Test.Cardano.Ledger.Alonzo.Examples.Bbody (bbodyExamples)
import Test.Cardano.Ledger.Alonzo.Examples.Utxow (plutusScriptExamples, utxowExamples)
import Test.Cardano.Ledger.Alonzo.Golden as Golden
import qualified Test.Cardano.Ledger.Alonzo.Serialisation.CDDL as CDDL
import qualified Test.Cardano.Ledger.Alonzo.Serialisation.Tripping as Tripping
import qualified Test.Cardano.Ledger.Alonzo.Translation as Translation

-- Crypto era only

--
Expand All @@ -38,6 +29,7 @@ import qualified Test.Cardano.Ledger.Alonzo.Translation as Translation

import Cardano.Ledger.Allegra (AllegraEra)
import Cardano.Ledger.Alonzo (AlonzoEra)
import Test.Cardano.Ledger.Alonzo.Examples.Bbody (bbodyExamples)
import Test.Cardano.Ledger.Alonzo.Examples.Utxow (plutusScriptExamples, utxowExamples)
import Test.Cardano.Ledger.Alonzo.Golden as Golden
import qualified Test.Cardano.Ledger.Alonzo.Serialisation.CDDL as CDDL
Expand Down
1 change: 1 addition & 0 deletions cardano-ledger-core/src/Cardano/Ledger/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pattern Tx {body, wits, auxiliaryData} <-
}
_
)
where
Tx b w a = TxConstr $ memoBytes (encodeTxRaw $ TxRaw b w a)

{-# COMPLETE Tx #-}
Expand Down
2 changes: 2 additions & 0 deletions example-shelley/src/Cardano/Ledger/Example.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as CryptoClass
import Cardano.Ledger.Era (Era (Crypto), SupportsSegWit (..), ValidateScript (..))
import Cardano.Ledger.Hashes (EraIndependentAuxiliaryData)
import Shelley.Spec.Ledger.PParams()
import Cardano.Ledger.SafeHash (makeHashWithExplicitProxys)
import Cardano.Ledger.Shelley.Constraints (UsesPParams (..), UsesTxOut (..), UsesValue, UsesTxBody)
import Cardano.Ledger.Val (Val ((<->)))
Expand Down Expand Up @@ -149,6 +150,7 @@ instance CryptoClass.Crypto c => SupportsSegWit (ExampleEra c) where
fromTxSeq = Shelley.txSeqTxns
toTxSeq = Shelley.TxSeq
hashTxSeq = Shelley.bbHash
unsafeApplyTx x = x

instance CryptoClass.Crypto c => ValidateAuxiliaryData (ExampleEra c) c where
hashAuxiliaryData metadata = AuxiliaryDataHash (makeHashWithExplicitProxys (Proxy @c) index metadata)
Expand Down
1 change: 1 addition & 0 deletions example-shelley/src/Cardano/Ledger/Example/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Data.Coerce (coerce)
import qualified Data.Map.Strict as Map
import Shelley.Spec.Ledger.API
import Shelley.Spec.Ledger.Tx (decodeWits)
import Shelley.Spec.Ledger.PParams()

--------------------------------------------------------------------------------
-- Translation from Shelley to Example
Expand Down
Loading

0 comments on commit e00216f

Please sign in to comment.