|
| 1 | +{-# LANGUAGE OverloadedLists #-} |
| 2 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 3 | +{-# LANGUAGE TypeApplications #-} |
| 4 | +{-# LANGUAGE TypeFamilies #-} |
| 5 | + |
| 6 | +module Test.Cardano.Ledger.Alonzo.Imp.BbodySpec (spec) where |
| 7 | + |
| 8 | +import Cardano.Ledger.Alonzo.Core |
| 9 | +import Cardano.Ledger.Alonzo.Scripts (eraLanguages) |
| 10 | +import Cardano.Ledger.Alonzo.TxWits (unRedeemersL) |
| 11 | +import Cardano.Ledger.Credential (Credential (..)) |
| 12 | +import Cardano.Ledger.Plutus ( |
| 13 | + Data (..), |
| 14 | + hashPlutusScript, |
| 15 | + withSLanguage, |
| 16 | + ) |
| 17 | +import Cardano.Ledger.Shelley.LedgerState (curPParamsEpochStateL, nesEsL) |
| 18 | +import qualified Data.Map.Strict as Map |
| 19 | +import Lens.Micro |
| 20 | +import qualified PlutusLedgerApi.Common as P |
| 21 | +import Test.Cardano.Ledger.Alonzo.ImpTest |
| 22 | +import Test.Cardano.Ledger.Common |
| 23 | +import Test.Cardano.Ledger.Plutus.Examples |
| 24 | + |
| 25 | +spec :: forall era. AlonzoEraImp era => SpecWith (ImpInit (LedgerSpec era)) |
| 26 | +spec = describe "BBODY" $ do |
| 27 | + forM_ (eraLanguages @era) $ \lang -> |
| 28 | + withSLanguage lang $ \slang -> |
| 29 | + describe (show lang) $ do |
| 30 | + let |
| 31 | + alwaysSucceedsWithDatumHash = hashPlutusScript $ alwaysSucceedsWithDatum slang :: ScriptHash |
| 32 | + alwaysFailsWithDatumHash = hashPlutusScript $ alwaysFailsWithDatum slang :: ScriptHash |
| 33 | + alwaysSucceedsNoDatumHash = hashPlutusScript $ alwaysSucceedsNoDatum slang :: ScriptHash |
| 34 | + alwaysFailsNoDatumHash = hashPlutusScript $ alwaysFailsNoDatum slang :: ScriptHash |
| 35 | + evenRedeemerNoDatumHash = hashPlutusScript $ evenRedeemerNoDatum slang :: ScriptHash |
| 36 | + |
| 37 | + it "succeeds with eight Plutus scripts" $ do |
| 38 | + rewardAccount <- registerStakeCredential $ ScriptHashObj evenRedeemerNoDatumHash |
| 39 | + txCert <- genUnRegTxCert $ ScriptHashObj evenRedeemerNoDatumHash |
| 40 | + |
| 41 | + withTxsInBlock_ $ do |
| 42 | + impAnn "notValidatingTx" $ do |
| 43 | + txIn <- produceScript alwaysFailsWithDatumHash |
| 44 | + submitPhase2Invalid_ $ mkBasicTx $ mkBasicTxBody & inputsTxBodyL .~ [txIn] |
| 45 | + impAnn "validatingTx" $ do |
| 46 | + txIn <- produceScript alwaysSucceedsWithDatumHash |
| 47 | + submitTx_ $ mkBasicTx $ mkBasicTxBody & inputsTxBodyL .~ [txIn] |
| 48 | + |
| 49 | + impAnn "notValidatingTxWithMint" $ do |
| 50 | + submitPhase2Invalid_ =<< mkTokenMintingTx alwaysFailsNoDatumHash |
| 51 | + impAnn "validatingTxWithMint" $ do |
| 52 | + submitTx_ =<< mkTokenMintingTx alwaysSucceedsNoDatumHash |
| 53 | + |
| 54 | + maxExUnits <- getsNES $ nesEsL . curPParamsEpochStateL . ppMaxTxExUnitsL |
| 55 | + |
| 56 | + let dex i = (Data $ P.I i, maxExUnits) |
| 57 | + rPurpose = mkRewardingPurpose (AsIx 0) |
| 58 | + cPurpose = mkCertifyingPurpose (AsIx 0) |
| 59 | + |
| 60 | + impAnn "notValidatingTxWithWithdrawal" $ do |
| 61 | + submitPhase2Invalid_ $ |
| 62 | + mkBasicTx mkBasicTxBody |
| 63 | + & bodyTxL . withdrawalsTxBodyL .~ Withdrawals [(rewardAccount, mempty)] |
| 64 | + & witsTxL . rdmrsTxWitsL . unRedeemersL %~ Map.insert rPurpose (dex 1) |
| 65 | + impAnn "validatingTxWithWithdrawal" $ do |
| 66 | + submitTx_ $ |
| 67 | + mkBasicTx mkBasicTxBody |
| 68 | + & bodyTxL . withdrawalsTxBodyL .~ Withdrawals [(rewardAccount, mempty)] |
| 69 | + & witsTxL . rdmrsTxWitsL . unRedeemersL %~ Map.insert rPurpose (dex 0) |
| 70 | + |
| 71 | + impAnn "notValidatingTxWithCert" $ do |
| 72 | + submitPhase2Invalid_ $ |
| 73 | + mkBasicTx mkBasicTxBody |
| 74 | + & bodyTxL . certsTxBodyL .~ [txCert] |
| 75 | + & witsTxL . rdmrsTxWitsL . unRedeemersL %~ Map.insert cPurpose (dex 1) |
| 76 | + impAnn "validatingTxWithCert" $ do |
| 77 | + submitTx_ $ |
| 78 | + mkBasicTx mkBasicTxBody |
| 79 | + & bodyTxL . certsTxBodyL .~ [txCert] |
| 80 | + & witsTxL . rdmrsTxWitsL . unRedeemersL %~ Map.insert cPurpose (dex 0) |
| 81 | + |
| 82 | + it "fails with bad pool MD hash in Tx" $ |
| 83 | + const $ |
| 84 | + pendingWith "not implemented yet" |
0 commit comments