Skip to content

Commit fcffb28

Browse files
committed
Implement BBODY Imp tests for Alonzo
1 parent 66801d9 commit fcffb28

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ library testlib
161161
Test.Cardano.Ledger.Alonzo.Era
162162
Test.Cardano.Ledger.Alonzo.Examples
163163
Test.Cardano.Ledger.Alonzo.Imp
164+
Test.Cardano.Ledger.Alonzo.Imp.BbodySpec
164165
Test.Cardano.Ledger.Alonzo.Imp.UtxoSpec
165166
Test.Cardano.Ledger.Alonzo.Imp.UtxosSpec
166167
Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Test.Cardano.Ledger.Alonzo.Imp where
1010

1111
import Cardano.Ledger.Alonzo (AlonzoEra)
1212
import Cardano.Ledger.Shelley.Core (ShelleyEraTxCert)
13+
import qualified Test.Cardano.Ledger.Alonzo.Imp.BbodySpec as Bbody
1314
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxoSpec as Utxo
1415
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxosSpec as Utxos
1516
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as Utxow
@@ -27,6 +28,7 @@ spec ::
2728
spec = do
2829
MaryImp.spec @era
2930
describe "AlonzoImpSpec" . withEachEraVersion @era $ do
31+
Bbody.spec
3032
Utxo.spec
3133
Utxos.spec
3234
Utxow.spec
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)