@@ -13,6 +13,7 @@ module Test.Cardano.Ledger.Conway.Binary.Golden (
1313 goldenListRedeemers ,
1414 witsEmptyFieldWithSetTag ,
1515 conwayDecodeDuplicateDelegCertFails ,
16+ expectFailureOnTxWitsEmptyFieldWithTag ,
1617 module Test.Cardano.Ledger.Alonzo.Binary.Golden ,
1718) where
1819
@@ -25,7 +26,13 @@ import Cardano.Ledger.Alonzo.Core (
2526 )
2627import Cardano.Ledger.Alonzo.Scripts (ExUnits (.. ))
2728import Cardano.Ledger.Alonzo.TxWits (Redeemers (.. ), unRedeemers )
28- import Cardano.Ledger.Binary (Annotator , DecoderError (.. ), DeserialiseFailure (.. ), Version )
29+ import Cardano.Ledger.Binary (
30+ Annotator ,
31+ DecCBOR ,
32+ DecoderError (.. ),
33+ DeserialiseFailure (.. ),
34+ Version ,
35+ )
2936import qualified Cardano.Ledger.Binary as Binary
3037import Cardano.Ledger.Binary.Plain (Tokens (.. ))
3138import Cardano.Ledger.Conway.Core (
@@ -39,7 +46,9 @@ import PlutusLedgerApi.Common (Data (..))
3946import Test.Cardano.Ledger.Alonzo.Binary.Golden hiding (spec )
4047import Test.Cardano.Ledger.Binary.Plain.Golden (Enc (.. ))
4148import Test.Cardano.Ledger.Common (
49+ Expectation ,
4250 Spec ,
51+ ToExpr ,
4352 describe ,
4453 it ,
4554 )
@@ -82,6 +91,15 @@ witsEmptyFieldWithSetTag k =
8291 , E @ [Void ] []
8392 ]
8493
94+ expectFailureOnTxWitsEmptyFieldWithTag ::
95+ forall era .
96+ ( ToExpr (TxWits era )
97+ , DecCBOR (Annotator (TxWits era ))
98+ ) =>
99+ Version -> Int -> DecoderError -> Expectation
100+ expectFailureOnTxWitsEmptyFieldWithTag version k =
101+ expectDecoderFailureAnn @ (TxWits era ) version (witsEmptyFieldWithSetTag k)
102+
85103conwayDecodeDuplicateDelegCertFails ::
86104 forall era . ConwayEraTest era => Version -> Spec
87105conwayDecodeDuplicateDelegCertFails version =
@@ -100,74 +118,68 @@ spec = do
100118 describe " Empty fields not allowed" $ do
101119 forEachEraVersion @ era $ \ version -> do
102120 describe " Untagged" $ do
103- let
104- expectFailureOnEmptyField k =
105- expectDecoderFailureAnn @ (TxWits era ) version (witsEmptyField k)
106- it " addrTxWits" . expectFailureOnEmptyField 0 $
121+ it " addrTxWits" . expectFailureOnTxWitsEmptyField @ era version 0 $
107122 DecoderErrorDeserialiseFailure
108123 (Binary. label $ Proxy @ (Annotator (TxWits era )))
109124 (DeserialiseFailure 4 " Empty list found, expected non-empty" )
110- it " nativeScripts" . expectFailureOnEmptyField 1 $
125+ it " nativeScripts" . expectFailureOnTxWitsEmptyField @ era version 1 $
111126 DecoderErrorDeserialiseFailure
112127 (Binary. label $ Proxy @ (Annotator (TxWits era )))
113128 (DeserialiseFailure 4 " Empty list found, expected non-empty" )
114- it " bootstrapWitness" . expectFailureOnEmptyField 2 $
129+ it " bootstrapWitness" . expectFailureOnTxWitsEmptyField @ era version 2 $
115130 DecoderErrorDeserialiseFailure
116131 (Binary. label $ Proxy @ (Annotator (TxWits era )))
117132 (DeserialiseFailure 4 " Empty list found, expected non-empty" )
118- it " plutusV1Script" . expectFailureOnEmptyField 3 $
133+ it " plutusV1Script" . expectFailureOnTxWitsEmptyField @ era version 3 $
119134 DecoderErrorDeserialiseFailure
120135 (Binary. label $ Proxy @ (Annotator (TxWits era )))
121136 (DeserialiseFailure 4 " Empty list of scripts is not allowed" )
122- it " plutusData" . expectFailureOnEmptyField 4 $
137+ it " plutusData" . expectFailureOnTxWitsEmptyField @ era version 4 $
123138 DecoderErrorDeserialiseFailure
124139 (Binary. label $ Proxy @ (Annotator (TxWits era )))
125140 (DeserialiseFailure 4 " Empty list found, expected non-empty" )
126- it " redeemers" . expectFailureOnEmptyField 5 $
141+ it " redeemers" . expectFailureOnTxWitsEmptyField @ era version 5 $
127142 DecoderErrorDeserialiseFailure
128143 (Binary. label $ Proxy @ (Annotator (TxWits era )))
129144 (DeserialiseFailure 4 " Empty list found, expected non-empty" )
130- it " plutusV2Script" . expectFailureOnEmptyField 6 $
145+ it " plutusV2Script" . expectFailureOnTxWitsEmptyField @ era version 6 $
131146 DecoderErrorDeserialiseFailure
132147 (Binary. label $ Proxy @ (Annotator (TxWits era )))
133148 (DeserialiseFailure 4 " Empty list of scripts is not allowed" )
134- it " plutusV3Script" . expectFailureOnEmptyField 7 $
149+ it " plutusV3Script" . expectFailureOnTxWitsEmptyField @ era version 7 $
135150 DecoderErrorDeserialiseFailure
136151 (Binary. label $ Proxy @ (Annotator (TxWits era )))
137152 (DeserialiseFailure 4 " Empty list of scripts is not allowed" )
138- it " 8th field" . expectFailureOnEmptyField 8 $
153+ it " 8th field" . expectFailureOnTxWitsEmptyField @ era version 8 $
139154 DecoderErrorDeserialiseFailure
140155 (Binary. label $ Proxy @ (Annotator (TxWits era )))
141156 (DeserialiseFailure 2 " An error occurred while decoding (Int,Void) not a valid key:.\n Error: 8" )
142157 describe " Tagged" $ do
143- let
144- expectFailureOnEmptyField k =
145- expectDecoderFailureAnn @ (TxWits era ) version (witsEmptyFieldWithSetTag k)
146- it " addrTxWits" . expectFailureOnEmptyField 0 $
158+ it " addrTxWits" . expectFailureOnTxWitsEmptyField @ era version 0 $
147159 DecoderErrorDeserialiseFailure
148160 (Binary. label $ Proxy @ (Annotator (TxWits era )))
149161 (DeserialiseFailure 7 " Empty list found, expected non-empty" )
150- it " nativeScripts" . expectFailureOnEmptyField 1 $
162+ it " nativeScripts" . expectFailureOnTxWitsEmptyFieldWithTag @ era version 1 $
151163 DecoderErrorDeserialiseFailure
152164 (Binary. label $ Proxy @ (Annotator (TxWits era )))
153165 (DeserialiseFailure 7 " Empty list found, expected non-empty" )
154- it " bootstrapWitness" . expectFailureOnEmptyField 2 $
166+ it " bootstrapWitness" . expectFailureOnTxWitsEmptyFieldWithTag @ era version 2 $
155167 DecoderErrorDeserialiseFailure
156168 (Binary. label $ Proxy @ (Annotator (TxWits era )))
157169 (DeserialiseFailure 7 " Empty list found, expected non-empty" )
158- it " plutusV1Script" . expectFailureOnEmptyField 3 $
170+ it " plutusV1Script" . expectFailureOnTxWitsEmptyFieldWithTag @ era version 3 $
159171 DecoderErrorDeserialiseFailure
160172 (Binary. label $ Proxy @ (Annotator (TxWits era )))
161173 (DeserialiseFailure 7 " Empty list of scripts is not allowed" )
162- it " plutusData" . expectFailureOnEmptyField 4 $
174+ it " plutusData" . expectFailureOnTxWitsEmptyFieldWithTag @ era version 4 $
163175 DecoderErrorDeserialiseFailure
164176 (Binary. label $ Proxy @ (Annotator (TxWits era )))
165177 (DeserialiseFailure 7 " Empty list found, expected non-empty" )
166- it " plutusV2Script" . expectFailureOnEmptyField 6 $
178+ it " plutusV2Script" . expectFailureOnTxWitsEmptyFieldWithTag @ era version 6 $
167179 DecoderErrorDeserialiseFailure
168180 (Binary. label $ Proxy @ (Annotator (TxWits era )))
169181 (DeserialiseFailure 7 " Empty list of scripts is not allowed" )
170- it " plutusV3Script" . expectFailureOnEmptyField 7 $
182+ it " plutusV3Script" . expectFailureOnTxWitsEmptyFieldWithTag @ era version 7 $
171183 DecoderErrorDeserialiseFailure
172184 (Binary. label $ Proxy @ (Annotator (TxWits era )))
173185 (DeserialiseFailure 7 " Empty list of scripts is not allowed" )
0 commit comments