Skip to content

Commit

Permalink
Add more scripts to alonzo utxosspec
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketd committed Jun 20, 2024
1 parent de33cee commit bd58778
Showing 1 changed file with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
Expand All @@ -17,7 +18,7 @@ import Cardano.Ledger.Alonzo.Core (
)
import Cardano.Ledger.Alonzo.Tx (IsValid (..))
import Cardano.Ledger.Alonzo.TxWits (Redeemers (..))
import Cardano.Ledger.Core (EraTx (..), EraTxBody (..))
import Cardano.Ledger.Core
import Cardano.Ledger.Plutus.Data (Data (..))
import Cardano.Ledger.Plutus.Language (Language, hashPlutusScript, withSLanguage)
import Cardano.Ledger.Shelley.LedgerState (curPParamsEpochStateL, nesEsL)
Expand All @@ -30,12 +31,13 @@ import Test.Cardano.Ledger.Alonzo.ImpTest (
ShelleyEraImp,
getsNES,
impAnn,
passEpoch,
produceScript,
submitTxAnn_,
submitTx_,
)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Plutus.Examples (redeemerSameAsDatum)
import Test.Cardano.Ledger.Plutus.Examples

spec ::
forall era.
Expand All @@ -47,14 +49,24 @@ spec = describe "UTXOS" $
forM_ ([minBound .. eraMaxLanguage @era] :: [Language]) $ \lang ->
withSLanguage lang $ \slang ->
describe (show lang) $ do
let scriptHash = hashPlutusScript (redeemerSameAsDatum slang)
it "Spending script with a Datum" $ do
txIn0 <- produceScript scriptHash
submitTxAnn_ "Submit a transaction that consumes the script output" $
mkBasicTx mkBasicTxBody
& bodyTxL . inputsTxBodyL
.~ Set.singleton txIn0
let scripts =
[ ("redeermerSameAsDatum", redeemerSameAsDatum)
, ("purposeIsWellformedWithDatum", purposeIsWellformedWithDatum)
, ("datumIsWellformed", datumIsWellformed)
, ("inputsOutputsAreNotEmptyWithDatum", inputsOutputsAreNotEmptyWithDatum)
]
describe "Spending scripts with a Datum" $ do
forM_ scripts $ \(name, script) -> do
it name $ do
let sHash = hashPlutusScript (script slang)
txIn0 <- produceScript sHash
submitTxAnn_ "Submit a transaction that consumes the script output" $
mkBasicTx mkBasicTxBody
& bodyTxL . inputsTxBodyL
.~ Set.singleton txIn0
passEpoch
it "Invalid plutus script fails in phase 2" $ do
let scriptHash = hashPlutusScript (redeemerSameAsDatum slang)
txIn0 <- produceScript scriptHash
exUnits <- getsNES $ nesEsL . curPParamsEpochStateL . ppMaxTxExUnitsL
impAnn "Submitting consuming transaction" $
Expand All @@ -69,3 +81,14 @@ spec = describe "UTXOS" $
(Data $ P.I 32, exUnits)
)
)
describe "Scripts pass in phase 2" $ do
let scripts' = drop 1 scripts
forM_ scripts' $ \(name, script) -> do
it name $ do
let sHash = hashPlutusScript (script slang)
txIn0 <- produceScript sHash
impAnn "Submitting consuming transaction" $
submitTx_
( mkBasicTx mkBasicTxBody
& bodyTxL . inputsTxBodyL .~ Set.singleton txIn0
)

0 comments on commit bd58778

Please sign in to comment.