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