From 4e014760f9cbcdc1fb1dd221c3174bba90442012 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Thu, 9 Jun 2022 15:25:03 +0200 Subject: [PATCH 1/5] deal with BabbageEra missing tests in core unit tests --- lib/core/test/unit/Cardano/Api/GenSpec.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/core/test/unit/Cardano/Api/GenSpec.hs b/lib/core/test/unit/Cardano/Api/GenSpec.hs index 9bb7145bdeb..9d7f1908fd1 100644 --- a/lib/core/test/unit/Cardano/Api/GenSpec.hs +++ b/lib/core/test/unit/Cardano/Api/GenSpec.hs @@ -1738,4 +1738,5 @@ forAllShelleyBasedEras f = , AnyCardanoEra AllegraEra , AnyCardanoEra MaryEra , AnyCardanoEra AlonzoEra + , AnyCardanoEra BabbageEra ] From e9d227886f34d714600a494dbc5bb271e64b2c6a Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Mon, 13 Jun 2022 12:19:02 +0200 Subject: [PATCH 2/5] extend forAllEras to babbage in shelley unit tests --- lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs index 5fadfdae446..b85737713b7 100644 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs +++ b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs @@ -982,6 +982,7 @@ forAllShelleyBasedEras eraSpec = do eraSpec (AnyCardanoEra AllegraEra) eraSpec (AnyCardanoEra MaryEra) eraSpec (AnyCardanoEra AlonzoEra) + eraSpec (AnyCardanoEra BabbageEra) allEras :: [(Int, AnyCardanoEra)] allEras = @@ -990,6 +991,7 @@ allEras = , (3, AnyCardanoEra AllegraEra) , (4, AnyCardanoEra MaryEra) , (5, AnyCardanoEra AlonzoEra) + , (6, AnyCardanoEra BabbageEra) ] eraNum :: AnyCardanoEra -> Int From a530d983c4ee664748a8c8850db35e95ed3b1eb2 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Mon, 13 Jun 2022 13:28:58 +0200 Subject: [PATCH 3/5] extend genTxInEra --- lib/core/src/Cardano/Api/Gen.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/core/src/Cardano/Api/Gen.hs b/lib/core/src/Cardano/Api/Gen.hs index d9914e7cc67..e4217013955 100644 --- a/lib/core/src/Cardano/Api/Gen.hs +++ b/lib/core/src/Cardano/Api/Gen.hs @@ -1462,11 +1462,12 @@ genTxInEra era = do genTx :: Gen (InAnyCardanoEra Tx) genTx = - oneof [ InAnyCardanoEra ByronEra <$> genTxInEra ByronEra - , InAnyCardanoEra ShelleyEra <$> genTxInEra ShelleyEra - , InAnyCardanoEra MaryEra <$> genTxInEra MaryEra - , InAnyCardanoEra AllegraEra <$> genTxInEra AllegraEra - , InAnyCardanoEra AlonzoEra <$> genTxInEra AlonzoEra + oneof [ InAnyCardanoEra ByronEra <$> genTxInEra ByronEra + , InAnyCardanoEra ShelleyEra <$> genTxInEra ShelleyEra + , InAnyCardanoEra MaryEra <$> genTxInEra MaryEra + , InAnyCardanoEra AllegraEra <$> genTxInEra AllegraEra + , InAnyCardanoEra AlonzoEra <$> genTxInEra AlonzoEra + , InAnyCardanoEra BabbageEra <$> genTxInEra BabbageEra ] -- TODO: Generate txs with no inputs From 4f97338707db5d825b222419d6921061cc7e1eb3 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Mon, 13 Jun 2022 14:35:21 +0200 Subject: [PATCH 4/5] unpend byron witnesses tests in shelley core unit tests --- .../src/Cardano/Wallet/Shelley/Transaction.hs | 1 + .../Cardano/Wallet/Shelley/TransactionSpec.hs | 39 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs index 132bca221ad..74d55fb485c 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs @@ -42,6 +42,7 @@ module Cardano.Wallet.Shelley.Transaction , TxSkeleton (..) , TxWitnessTag (..) , TxWitnessTagFor (..) + , EraConstraints , _decodeSealedTx , _estimateMaxNumberOfInputs , _maxScriptExecutionCost diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs index b85737713b7..92f6efd8734 100644 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs +++ b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs @@ -17,6 +17,7 @@ {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {- HLINT ignore "Use null" -} @@ -212,7 +213,8 @@ import Cardano.Wallet.Shelley.Compatibility import Cardano.Wallet.Shelley.Compatibility.Ledger ( toAlonzoTxOut ) import Cardano.Wallet.Shelley.Transaction - ( TxSkeleton (..) + ( EraConstraints + , TxSkeleton (..) , TxUpdate (..) , TxWitnessTag (..) , TxWitnessTagFor @@ -221,6 +223,7 @@ import Cardano.Wallet.Shelley.Transaction , estimateTxCost , estimateTxSize , maximumCostOfIncreasingCoin + , mkByronWitness , mkDelegationCertificates , mkShelleyWitness , mkTxSkeleton @@ -318,7 +321,6 @@ import System.FilePath import Test.Hspec ( Spec , SpecWith - , before_ , describe , expectationFailure , it @@ -1000,11 +1002,6 @@ eraNum e = fst $ head $ filter ((== e) . snd) allEras shelleyEraNum :: AnyShelleyBasedEra -> Int shelleyEraNum = eraNum . shelleyToCardanoEra -pendingOnAlonzo :: String -> ShelleyBasedEra era -> SpecWith a -> SpecWith a -pendingOnAlonzo msg era = before_ $ case era of - Cardano.ShelleyBasedEraAlonzo -> pendingWith ("AlonzoEra: " ++ msg) - _ -> pure () - instance Arbitrary AnyCardanoEra where arbitrary = frequency $ zip [1..] $ map (pure . snd) allEras -- Shrink by choosing a *later* era @@ -1401,13 +1398,21 @@ binaryCalculationsSpec :: AnyCardanoEra -> Spec binaryCalculationsSpec (AnyCardanoEra era) = case cardanoEraStyle era of LegacyByronEra -> pure () - ShelleyBasedEra shelleyEra -> - -- TODO: [ADP-919] tests for byron witnesses - pendingOnAlonzo "Golden transactions not yet updated" shelleyEra $ - before_ (pendingWith ("Will return with signTx PR")) $ - binaryCalculationsSpec' shelleyEra - -binaryCalculationsSpec' :: IsShelleyBasedEra era => ShelleyBasedEra era -> Spec + ShelleyBasedEra shelleyEra -> case shelleyEra of + ShelleyBasedEraShelley -> + binaryCalculationsSpec' @Cardano.ShelleyEra shelleyEra + ShelleyBasedEraAllegra -> + binaryCalculationsSpec' @Cardano.AllegraEra shelleyEra + ShelleyBasedEraMary -> + binaryCalculationsSpec' @Cardano.MaryEra shelleyEra + ShelleyBasedEraAlonzo -> + binaryCalculationsSpec' @Cardano.AlonzoEra shelleyEra + ShelleyBasedEraBabbage -> + binaryCalculationsSpec' @Cardano.BabbageEra shelleyEra + +binaryCalculationsSpec' + :: forall era. EraConstraints era + => ShelleyBasedEra era -> Spec binaryCalculationsSpec' era = describe ("calculateBinary - "+||era||+"") $ do describe "Byron witnesses - mainnet" $ do let net = Cardano.Mainnet @@ -1560,12 +1565,12 @@ binaryCalculationsSpec' era = describe ("calculateBinary - "+||era||+"") $ do where slotNo = SlotNo 7750 md = Nothing - calculateBinary _net utxo outs chgs pairs = + calculateBinary net utxo outs chgs pairs = hex (Cardano.serialiseToCBOR ledgerTx) where ledgerTx = Cardano.makeSignedTransaction addrWits unsigned - mkByronWitness' _unsignedTx (_, (TxOut _addr _)) = - error "mkByronWitness'" -- TODO: [ADP-919] + mkByronWitness' unsignedTx (_, (TxOut addr _)) = + mkByronWitness @era unsignedTx net addr addrWits = zipWith (mkByronWitness' unsigned) inps pairs fee = toCardanoLovelace $ selectionDelta txOutCoin cs Right unsigned = From f5cff1c23260c6985f9007b0b5ac8fb29be631ae Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Wed, 15 Jun 2022 13:40:17 +0200 Subject: [PATCH 5/5] pospone calculateBinary testing for Alonzo/Babbage until ledger fix --- .../test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs index 92f6efd8734..36c5399995b 100644 --- a/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs +++ b/lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs @@ -1406,9 +1406,11 @@ binaryCalculationsSpec (AnyCardanoEra era) = ShelleyBasedEraMary -> binaryCalculationsSpec' @Cardano.MaryEra shelleyEra ShelleyBasedEraAlonzo -> - binaryCalculationsSpec' @Cardano.AlonzoEra shelleyEra + pure () -- TO_DO when ledger's PR 2863 is included in node bump + --binaryCalculationsSpec' @Cardano.AlonzoEra shelleyEra ShelleyBasedEraBabbage -> - binaryCalculationsSpec' @Cardano.BabbageEra shelleyEra + pure () -- TO_DO when ledger's PR 2863 is included in node bump + --binaryCalculationsSpec' @Cardano.BabbageEra shelleyEra binaryCalculationsSpec' :: forall era. EraConstraints era