Skip to content

Commit dde3349

Browse files
committed
Implement TxInfoSpec as an imptest
1 parent 2c4b0dc commit dde3349

File tree

5 files changed

+77
-117
lines changed

5 files changed

+77
-117
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ library testlib
118118
Test.Cardano.Ledger.Alonzo.Era
119119
Test.Cardano.Ledger.Alonzo.Examples
120120
Test.Cardano.Ledger.Alonzo.Imp
121+
Test.Cardano.Ledger.Alonzo.Imp.TxInfoSpec
121122
Test.Cardano.Ledger.Alonzo.Imp.UtxoSpec
122123
Test.Cardano.Ledger.Alonzo.Imp.UtxosSpec
123124
Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec
@@ -223,7 +224,6 @@ test-suite tests
223224
Test.Cardano.Ledger.Alonzo.BinarySpec
224225
Test.Cardano.Ledger.Alonzo.GoldenSpec
225226
Test.Cardano.Ledger.Alonzo.GoldenTranslation
226-
Test.Cardano.Ledger.Alonzo.TxInfoSpec
227227

228228
default-language: Haskell2010
229229
ghc-options:
@@ -249,8 +249,5 @@ 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,
253-
cardano-strict-containers,
254252
containers,
255253
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

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
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{-# LANGUAGE TypeApplications #-}
2+
3+
module Test.Cardano.Ledger.Alonzo.Imp.TxInfoSpec (spec) where
4+
5+
import Cardano.Ledger.Address (Addr (..))
6+
import Cardano.Ledger.Alonzo (AlonzoEra)
7+
import Cardano.Ledger.Alonzo.Core (
8+
EraTx (..),
9+
EraTxBody (..),
10+
EraTxOut (..),
11+
)
12+
import Cardano.Ledger.Alonzo.Plutus.Context (EraPlutusTxInfo (..), LedgerTxInfo (..))
13+
import Cardano.Ledger.Alonzo.TxBody (AlonzoTxOut (..))
14+
import Cardano.Ledger.BaseTypes (EpochSize (..), Inject (..), StrictMaybe (..))
15+
import Cardano.Ledger.Coin (Coin (..))
16+
import Cardano.Ledger.Plutus (SLanguage (..))
17+
import Cardano.Ledger.State (UTxO (..))
18+
import Cardano.Slotting.EpochInfo (fixedEpochInfo)
19+
import Cardano.Slotting.Time (SystemStart (..), mkSlotLength)
20+
import Data.Either (isRight)
21+
import qualified Data.Map.Strict as Map
22+
import qualified Data.Sequence.Strict as SSeq
23+
import qualified Data.Set as Set
24+
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
25+
import Lens.Micro ((&), (.~))
26+
import Test.Cardano.Ledger.Alonzo.ImpTest
27+
import Test.Cardano.Ledger.Imp.Common
28+
29+
spec :: Spec
30+
spec = withImpInit @(LedgerSpec AlonzoEra) $ describe "TxInfoSpec" $ do
31+
describe "PlutusV1" $ do
32+
it "toPlutusTxInfo does not fail when Byron scripts are present in TxOuts" $ do
33+
pv <- getProtVer
34+
(_, shelleyAddr) <- freshKeyAddr
35+
byronAddr <- AddrBootstrap <$> freshBootstapAddress
36+
shelleyTxIn <- arbitrary
37+
let
38+
byronTxOut = mkBasicTxOut byronAddr . inject $ Coin 1
39+
tx =
40+
mkBasicTx @AlonzoEra mkBasicTxBody
41+
& bodyTxL . inputsTxBodyL .~ Set.singleton shelleyTxIn
42+
& bodyTxL . outputsTxBodyL .~ SSeq.singleton byronTxOut
43+
lti =
44+
LedgerTxInfo
45+
{ ltiProtVer = pv
46+
, ltiEpochInfo = fixedEpochInfo (EpochSize 100) (mkSlotLength 1)
47+
, ltiSystemStart = SystemStart $ posixSecondsToUTCTime 0
48+
, ltiUTxO = UTxO . Map.singleton shelleyTxIn $ AlonzoTxOut shelleyAddr (inject $ Coin 2) SNothing
49+
, ltiTx = tx
50+
}
51+
toPlutusTxInfo SPlutusV1 lti `shouldSatisfy` isRight
52+
it "toPlutusTxInfo does not fail when Byron scripts are present in TxIns" $ do
53+
pv <- getProtVer
54+
(_, shelleyAddr) <- freshKeyAddr
55+
byronAddr <- AddrBootstrap <$> freshBootstapAddress
56+
byronTxIn <- arbitrary
57+
let
58+
shelleyTxOut = mkBasicTxOut shelleyAddr . inject $ Coin 1
59+
tx =
60+
mkBasicTx @AlonzoEra mkBasicTxBody
61+
& bodyTxL . inputsTxBodyL .~ Set.singleton byronTxIn
62+
& bodyTxL . outputsTxBodyL .~ SSeq.singleton shelleyTxOut
63+
lti =
64+
LedgerTxInfo
65+
{ ltiProtVer = pv
66+
, ltiEpochInfo = fixedEpochInfo (EpochSize 100) (mkSlotLength 1)
67+
, ltiSystemStart = SystemStart $ posixSecondsToUTCTime 0
68+
, ltiUTxO =
69+
UTxO . Map.singleton byronTxIn $
70+
AlonzoTxOut byronAddr (inject $ Coin 2) SNothing
71+
, ltiTx = tx
72+
}
73+
toPlutusTxInfo SPlutusV1 lti `shouldSatisfy` isRight

0 commit comments

Comments
 (0)