Skip to content

Commit 1110760

Browse files
committed
WIP
1 parent 95bf46b commit 1110760

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

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

Lines changed: 1 addition & 0 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

eras/alonzo/impl/test/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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)
19+
import qualified Test.Cardano.Ledger.Alonzo.Imp.TxInfoSpec as TxInfoImp
1920

2021
main :: IO ()
2122
main =
@@ -35,3 +36,4 @@ main =
3536
CostModelsSpec.spec @AlonzoEra
3637
describe "TxWits" $ do
3738
TxWitsSpec.spec @AlonzoEra
39+
TxInfoImp.spec

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ silentlyIgnore tx =
9999

100100
spec :: Spec
101101
spec = describe "txInfo translation" $ do
102-
-- TODO: convert to Imp: https://github.com/IntersectMBO/cardano-ledger/issues/5210
103102
describe "Plutus V1" $ do
104103
it "silently ignore byron txout" $
105104
silentlyIgnore (txEx shelleyInput byronOutput)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import Cardano.Ledger.Alonzo.Rules (
1616
AlonzoUtxowPredFailure,
1717
)
1818
import Cardano.Ledger.Shelley.Rules (
19-
ShelleyDelegPredFailure,
2019
ShelleyPoolPredFailure,
2120
ShelleyUtxoPredFailure,
22-
ShelleyUtxowPredFailure,
21+
ShelleyUtxowPredFailure, ShelleyDelegPredFailure,
2322
)
2423
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxoSpec as Utxo
2524
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxosSpec as Utxos
@@ -60,7 +59,7 @@ alonzoEraSpecificSpec ::
6059
SpecWith (ImpInit (LedgerSpec era))
6160
alonzoEraSpecificSpec = do
6261
describe "Alonzo era specific Imp spec" $
63-
describe "Certificates without deposits" $
62+
describe "Certificates without deposits" $ do
6463
Utxow.alonzoEraSpecificSpec
6564

6665
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)