Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filling in missing babbage unit tests #3326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/core/src/Cardano/Api/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

]

-- TODO: Generate txs with no inputs
Expand Down
1 change: 1 addition & 0 deletions lib/core/test/unit/Cardano/Api/GenSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,4 +1738,5 @@ forAllShelleyBasedEras f =
, AnyCardanoEra AllegraEra
, AnyCardanoEra MaryEra
, AnyCardanoEra AlonzoEra
, AnyCardanoEra BabbageEra
]
1 change: 1 addition & 0 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module Cardano.Wallet.Shelley.Transaction
, TxSkeleton (..)
, TxWitnessTag (..)
, TxWitnessTagFor (..)
, EraConstraints
, _decodeSealedTx
, _estimateMaxNumberOfInputs
, _maxScriptExecutionCost
Expand Down
43 changes: 26 additions & 17 deletions lib/shelley/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{- HLINT ignore "Use null" -}

Expand Down Expand Up @@ -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
Expand All @@ -221,6 +223,7 @@ import Cardano.Wallet.Shelley.Transaction
, estimateTxCost
, estimateTxSize
, maximumCostOfIncreasingCoin
, mkByronWitness
, mkDelegationCertificates
, mkShelleyWitness
, mkTxSkeleton
Expand Down Expand Up @@ -318,7 +321,6 @@ import System.FilePath
import Test.Hspec
( Spec
, SpecWith
, before_
, describe
, expectationFailure
, it
Expand Down Expand Up @@ -982,6 +984,7 @@ forAllShelleyBasedEras eraSpec = do
eraSpec (AnyCardanoEra AllegraEra)
eraSpec (AnyCardanoEra MaryEra)
eraSpec (AnyCardanoEra AlonzoEra)
eraSpec (AnyCardanoEra BabbageEra)

allEras :: [(Int, AnyCardanoEra)]
allEras =
Expand All @@ -990,6 +993,7 @@ allEras =
, (3, AnyCardanoEra AllegraEra)
, (4, AnyCardanoEra MaryEra)
, (5, AnyCardanoEra AlonzoEra)
, (6, AnyCardanoEra BabbageEra)
]

eraNum :: AnyCardanoEra -> Int
Expand All @@ -998,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
Expand Down Expand Up @@ -1399,13 +1398,23 @@ 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 ->
pure () -- TO_DO when ledger's PR 2863 is included in node bump
--binaryCalculationsSpec' @Cardano.AlonzoEra shelleyEra
ShelleyBasedEraBabbage ->
pure () -- TO_DO when ledger's PR 2863 is included in node bump
--binaryCalculationsSpec' @Cardano.BabbageEra shelleyEra
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌


binaryCalculationsSpec'
:: forall era. EraConstraints era
=> ShelleyBasedEra era -> Spec
binaryCalculationsSpec' era = describe ("calculateBinary - "+||era||+"") $ do
describe "Byron witnesses - mainnet" $ do
let net = Cardano.Mainnet
Expand Down Expand Up @@ -1558,12 +1567,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 =
Expand Down