Skip to content

Commit dcd75a0

Browse files
authored
Merge pull request #5278 from IntersectMBO/jj/alonzo-txinfo-imptest
Re-implement `TxInfoSpec` as an `ImpTest`
2 parents bd92745 + 72508a8 commit dcd75a0

File tree

6 files changed

+87
-118
lines changed

6 files changed

+87
-118
lines changed

eras/alonzo/impl/cardano-ledger-alonzo.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ test-suite tests
223223
Test.Cardano.Ledger.Alonzo.BinarySpec
224224
Test.Cardano.Ledger.Alonzo.GoldenSpec
225225
Test.Cardano.Ledger.Alonzo.GoldenTranslation
226-
Test.Cardano.Ledger.Alonzo.TxInfoSpec
226+
Test.Cardano.Ledger.Alonzo.Imp.TxInfoSpec
227227

228228
default-language: Haskell2010
229229
ghc-options:
@@ -249,8 +249,8 @@ test-suite tests
249249
cardano-ledger-binary:{cardano-ledger-binary, testlib},
250250
cardano-ledger-core:{cardano-ledger-core, testlib},
251251
cardano-ledger-shelley:testlib,
252-
cardano-slotting,
253252
cardano-strict-containers,
254253
containers,
254+
microlens,
255+
microlens-mtl,
255256
testlib,
256-
time,

eras/alonzo/impl/test/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import qualified Test.Cardano.Ledger.Alonzo.BinarySpec as BinarySpec
1111
import qualified Test.Cardano.Ledger.Alonzo.GoldenSpec as Golden
1212
import qualified Test.Cardano.Ledger.Alonzo.GoldenTranslation as GoldenTranslation
1313
import qualified Test.Cardano.Ledger.Alonzo.Imp as Imp
14+
import qualified Test.Cardano.Ledger.Alonzo.Imp.TxInfoSpec as TxInfoImp
1415
import Test.Cardano.Ledger.Alonzo.ImpTest ()
15-
import qualified Test.Cardano.Ledger.Alonzo.TxInfoSpec as TxInfo
1616
import Test.Cardano.Ledger.Common
1717
import Test.Cardano.Ledger.Core.JSON (roundTripJsonEraSpec)
1818
import Test.Cardano.Ledger.Shelley.JSON (roundTripJsonShelleyEraSpec)
@@ -26,7 +26,6 @@ main =
2626
CddlSpec.spec
2727
roundTripJsonEraSpec @AlonzoEra
2828
roundTripJsonShelleyEraSpec @AlonzoEra
29-
TxInfo.spec
3029
GoldenTranslation.tests
3130
Golden.spec
3231
describe "Imp" $ do
@@ -35,3 +34,4 @@ main =
3534
CostModelsSpec.spec @AlonzoEra
3635
describe "TxWits" $ do
3736
TxWitsSpec.spec @AlonzoEra
37+
TxInfoImp.spec
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{-# LANGUAGE NamedFieldPuns #-}
2+
{-# LANGUAGE TypeApplications #-}
3+
4+
module Test.Cardano.Ledger.Alonzo.Imp.TxInfoSpec (spec) where
5+
6+
import Cardano.Ledger.Address (Addr (..))
7+
import Cardano.Ledger.Alonzo (AlonzoEra)
8+
import Cardano.Ledger.Alonzo.Core (
9+
EraTx (..),
10+
EraTxBody (..),
11+
EraTxOut (..),
12+
)
13+
import Cardano.Ledger.Alonzo.Plutus.Context (EraPlutusTxInfo (..), LedgerTxInfo (..))
14+
import Cardano.Ledger.BaseTypes
15+
import Cardano.Ledger.Coin (Coin (..))
16+
import Cardano.Ledger.Plutus (SLanguage (..))
17+
import qualified Data.Sequence.Strict as SSeq
18+
import qualified Data.Set as Set
19+
import Lens.Micro ((&), (.~))
20+
import Lens.Micro.Mtl (use)
21+
import Test.Cardano.Ledger.Alonzo.ImpTest
22+
import Test.Cardano.Ledger.Imp.Common
23+
24+
spec :: Spec
25+
spec = withImpInit @(LedgerSpec AlonzoEra) $ describe "TxInfo" $ do
26+
describe "PlutusV1" $ do
27+
it "toPlutusTxInfo does not fail when Byron scripts are present in TxOuts" $ do
28+
pv <- getProtVer
29+
Globals {epochInfo, systemStart} <- use impGlobalsL
30+
(_, shelleyAddr) <- freshKeyAddr
31+
byronAddr <- AddrBootstrap <$> freshBootstapAddress
32+
shelleyTxIn <- sendCoinTo shelleyAddr mempty
33+
utxo <- getUTxO
34+
let
35+
byronTxOut = mkBasicTxOut byronAddr . inject $ Coin 1
36+
tx =
37+
mkBasicTx @AlonzoEra mkBasicTxBody
38+
& bodyTxL
39+
. inputsTxBodyL
40+
.~ Set.singleton shelleyTxIn
41+
& bodyTxL
42+
. outputsTxBodyL
43+
.~ SSeq.singleton byronTxOut
44+
lti =
45+
LedgerTxInfo
46+
{ ltiProtVer = pv
47+
, ltiEpochInfo = epochInfo
48+
, ltiSystemStart = systemStart
49+
, ltiUTxO = utxo
50+
, ltiTx = tx
51+
}
52+
void $ expectRight $ toPlutusTxInfo SPlutusV1 lti
53+
it "toPlutusTxInfo does not fail when Byron scripts are present in TxIns" $ do
54+
pv <- getProtVer
55+
Globals {epochInfo, systemStart} <- use impGlobalsL
56+
(_, shelleyAddr) <- freshKeyAddr
57+
byronAddr <- AddrBootstrap <$> freshBootstapAddress
58+
byronTxIn <- sendCoinTo byronAddr mempty
59+
utxo <- getUTxO
60+
let
61+
shelleyTxOut = mkBasicTxOut shelleyAddr . inject $ Coin 1
62+
tx =
63+
mkBasicTx @AlonzoEra mkBasicTxBody
64+
& bodyTxL
65+
. inputsTxBodyL
66+
.~ Set.singleton byronTxIn
67+
& bodyTxL
68+
. outputsTxBodyL
69+
.~ SSeq.singleton shelleyTxOut
70+
lti =
71+
LedgerTxInfo
72+
{ ltiProtVer = pv
73+
, ltiEpochInfo = epochInfo
74+
, ltiSystemStart = systemStart
75+
, ltiUTxO = utxo
76+
, ltiTx = tx
77+
}
78+
void $ expectRight $ toPlutusTxInfo SPlutusV1 lti

eras/alonzo/impl/test/Test/Cardano/Ledger/Alonzo/TxInfoSpec.hs

Lines changed: 0 additions & 110 deletions
This file was deleted.

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ alonzoEraSpecificSpec ::
6060
SpecWith (ImpInit (LedgerSpec era))
6161
alonzoEraSpecificSpec = do
6262
describe "Alonzo era specific Imp spec" $
63-
describe "Certificates without deposits" $
63+
describe "Certificates without deposits" $ do
6464
Utxow.alonzoEraSpecificSpec
6565

6666
instance EraSpecificSpec AlonzoEra where

eras/dijkstra/impl/test/Test/Cardano/Ledger/Dijkstra/Binary/CddlSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec = do
6363
cddlRoundTripCborSpec @CostModels v "cost_models"
6464
cddlRoundTripAnnCborSpec @(Redeemers DijkstraEra) v "redeemers"
6565
cddlRoundTripCborSpec @(Redeemers DijkstraEra) v "redeemers"
66-
xdescribe "fix TxBody" $ do
66+
xdescribe "fix Tx" $ do
6767
cddlRoundTripAnnCborSpec @(Tx DijkstraEra) v "transaction"
6868
cddlRoundTripCborSpec @(Tx DijkstraEra) v "transaction"
6969
cddlRoundTripCborSpec @(VotingProcedure DijkstraEra) v "voting_procedure"
@@ -159,4 +159,5 @@ spec = do
159159
huddleDecoderEquivalenceSpec @(Script DijkstraEra) v "script"
160160
huddleDecoderEquivalenceSpec @(TxWits DijkstraEra) v "transaction_witness_set"
161161
huddleDecoderEquivalenceSpec @(Redeemers DijkstraEra) v "redeemers"
162-
huddleDecoderEquivalenceSpec @(Tx DijkstraEra) v "transaction"
162+
xdescribe "Fix decoder equivalence of Tx" $ do
163+
huddleDecoderEquivalenceSpec @(Tx DijkstraEra) v "transaction"

0 commit comments

Comments
 (0)