11
11
12
12
import Cardano.Api qualified as Api
13
13
import Cardano.Api.Experimental qualified as Exp
14
+ import Cardano.Api.Experimental.Era (convert )
14
15
import Cardano.Api.Genesis qualified as Genesis
15
16
import Cardano.Api.Ledger qualified as Ledger
16
17
import Cardano.Api.Plutus qualified as Script
@@ -23,15 +24,21 @@ import Cardano.Slotting.Slot qualified as Slotting
23
24
import Cardano.Slotting.Time qualified as Slotting
24
25
25
26
import Control.Monad.Identity (Identity )
27
+ import Data.Bifunctor (first )
26
28
import Data.Maybe (fromMaybe )
27
29
import Data.Ratio ((%) )
30
+ import Data.Text.Encoding qualified as Text
28
31
import Data.Time qualified as Time
29
32
import Data.Time.Clock.POSIX qualified as Time
30
33
import Lens.Micro ((&) )
31
34
32
- import Hedgehog (Property )
35
+ import Test.Gen.Cardano.Api.Typed (genTx )
36
+
37
+ import Hedgehog (Gen , Property )
33
38
import Hedgehog qualified as H
34
39
import Hedgehog.Extras qualified as H
40
+ import Hedgehog.Gen qualified as Gen
41
+ import Hedgehog.Internal.Property qualified as H
35
42
import Test.Tasty (TestTree , testGroup )
36
43
import Test.Tasty.Hedgehog (testProperty )
37
44
@@ -52,6 +59,12 @@ tests =
52
59
, testProperty
53
60
" Check two methods of balancing transaction are equivalent"
54
61
prop_balance_transaction_two_ways
62
+ , testProperty
63
+ " Roundtrip SerialiseAsRawBytes UnsignedTx"
64
+ prop_roundtrip_serialise_as_raw_bytes_unsigned_tx
65
+ , testProperty
66
+ " Roundtrip SerialiseAsRawBytes SignedTx"
67
+ prop_roundtrip_serialise_as_raw_bytes_signed_tx
55
68
]
56
69
57
70
prop_created_transaction_with_both_apis_are_the_same :: Property
@@ -280,3 +293,38 @@ exampleSigningKey =
280
293
H. evalEither $
281
294
Api. deserialiseFromBech32
282
295
" addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms"
296
+
297
+ expEraGen :: Gen (Exp. Some Exp. Era )
298
+ expEraGen =
299
+ let eras :: [Exp. Some Exp. Era ] = [minBound .. maxBound ]
300
+ in Gen. element eras
301
+
302
+ expTxForEraGen :: Exp. Era era -> Gen (Ledger. Tx (Exp. LedgerEra era ))
303
+ expTxForEraGen era = do
304
+ Exp. obtainCommonConstraints era $ do
305
+ ShelleyTx _ tx <- genTx (convert era)
306
+ return tx
307
+
308
+ prop_roundtrip_serialise_as_raw_bytes_unsigned_tx :: Property
309
+ prop_roundtrip_serialise_as_raw_bytes_unsigned_tx = H. withTests (H. TestLimit 20 ) $ H. property $ do
310
+ Exp. Some era <- H. forAll expEraGen
311
+ Exp. obtainCommonConstraints era $ do
312
+ tx <- H. forAll $ expTxForEraGen era
313
+ let signedTx = Exp. UnsignedTx tx
314
+ signedTx H. === signedTx
315
+ H. tripping
316
+ signedTx
317
+ (Text. decodeUtf8 . Api. serialiseToRawBytesHex)
318
+ (first show . Api. deserialiseFromRawBytesHex . Text. encodeUtf8)
319
+
320
+ prop_roundtrip_serialise_as_raw_bytes_signed_tx :: Property
321
+ prop_roundtrip_serialise_as_raw_bytes_signed_tx = H. withTests (H. TestLimit 20 ) $ H. property $ do
322
+ Exp. Some era <- H. forAll expEraGen
323
+ Exp. obtainCommonConstraints era $ do
324
+ tx <- H. forAll $ expTxForEraGen era
325
+ let signedTx = Exp. SignedTx tx
326
+ signedTx H. === signedTx
327
+ H. tripping
328
+ signedTx
329
+ (Text. decodeUtf8 . Api. serialiseToRawBytesHex)
330
+ (first show . Api. deserialiseFromRawBytesHex . Text. encodeUtf8)
0 commit comments