From bd5877868f63dbaae982cceb7c9c6cbcf1997988 Mon Sep 17 00:00:00 2001 From: Aniket Deshpande Date: Fri, 14 Jun 2024 15:03:16 +0200 Subject: [PATCH] Add more scripts to alonzo utxosspec --- .../Cardano/Ledger/Alonzo/Imp/UtxosSpec.hs | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxosSpec.hs b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxosSpec.hs index 89bc6672d2e..e5f89e7f2b4 100644 --- a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxosSpec.hs +++ b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp/UtxosSpec.hs @@ -2,6 +2,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} @@ -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) @@ -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. @@ -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" $ @@ -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 + )