/
CBOR.hs
196 lines (151 loc) · 7.36 KB
/
CBOR.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wno-deprecations #-} -- TODO Fix deprecations
module Test.Cardano.Api.Typed.CBOR
( tests
) where
import Cardano.Prelude
import Hedgehog (Property, forAll, property, success, tripping)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.Hedgehog (testProperty)
import Test.Tasty.TH (testGroupGenerator)
import Cardano.Api
import Gen.Cardano.Api.Typed
import Gen.Hedgehog.Roundtrip.CBOR (roundtrip_CBOR)
import Test.Cardano.Api.Typed.Orphans ()
{- HLINT ignore "Use camelCase" -}
-- TODO: Need to add PaymentExtendedKey roundtrip tests however
-- we can't derive an Eq instance for Crypto.HD.XPrv
test_roundtrip_txbody_CBOR :: [TestTree]
test_roundtrip_txbody_CBOR =
[ testProperty (show era) $
roundtrip_CBOR (proxyToAsType Proxy) (genTxBody era)
| AnyCardanoEra era <- [minBound..(AnyCardanoEra AlonzoEra)] -- TODO: Babbage era
]
test_roundtrip_tx_CBOR :: [TestTree]
test_roundtrip_tx_CBOR =
[ testProperty (show era) $ roundtrip_CBOR (proxyToAsType Proxy) (genTx era)
| AnyCardanoEra era <- [minBound..(AnyCardanoEra AlonzoEra)] -- TODO: Babbage era
]
prop_roundtrip_witness_byron_CBOR :: Property
prop_roundtrip_witness_byron_CBOR =
roundtrip_CBOR (AsKeyWitness AsByronEra) genByronKeyWitness
prop_roundtrip_witness_shelley_CBOR :: Property
prop_roundtrip_witness_shelley_CBOR =
roundtrip_CBOR (AsKeyWitness AsShelleyEra) (genShelleyWitness ShelleyEra)
prop_roundtrip_witness_allegra_CBOR :: Property
prop_roundtrip_witness_allegra_CBOR =
roundtrip_CBOR (AsKeyWitness AsAllegraEra) (genShelleyWitness AllegraEra)
prop_roundtrip_witness_mary_CBOR :: Property
prop_roundtrip_witness_mary_CBOR =
roundtrip_CBOR (AsKeyWitness AsMaryEra) (genShelleyWitness MaryEra)
prop_roundtrip_witness_alonzo_CBOR :: Property
prop_roundtrip_witness_alonzo_CBOR =
roundtrip_CBOR (AsKeyWitness AsAlonzoEra) (genShelleyWitness AlonzoEra)
prop_roundtrip_operational_certificate_CBOR :: Property
prop_roundtrip_operational_certificate_CBOR =
roundtrip_CBOR AsOperationalCertificate genOperationalCertificate
prop_roundtrip_operational_certificate_issue_counter_CBOR :: Property
prop_roundtrip_operational_certificate_issue_counter_CBOR =
roundtrip_CBOR AsOperationalCertificateIssueCounter genOperationalCertificateIssueCounter
prop_roundtrip_verification_key_byron_CBOR :: Property
prop_roundtrip_verification_key_byron_CBOR =
roundtrip_CBOR (AsVerificationKey AsByronKey) (genVerificationKey AsByronKey)
prop_roundtrip_signing_key_byron_CBOR :: Property
prop_roundtrip_signing_key_byron_CBOR =
roundtrip_CBOR (AsSigningKey AsByronKey) (genSigningKey AsByronKey)
prop_roundtrip_verification_key_payment_CBOR :: Property
prop_roundtrip_verification_key_payment_CBOR =
roundtrip_CBOR (AsVerificationKey AsPaymentKey) (genVerificationKey AsPaymentKey)
prop_roundtrip_signing_key_payment_CBOR :: Property
prop_roundtrip_signing_key_payment_CBOR =
roundtrip_CBOR (AsSigningKey AsPaymentKey) (genSigningKey AsPaymentKey)
prop_roundtrip_verification_key_stake_CBOR :: Property
prop_roundtrip_verification_key_stake_CBOR =
roundtrip_CBOR (AsVerificationKey AsStakeKey) (genVerificationKey AsStakeKey)
prop_roundtrip_signing_key_stake_CBOR :: Property
prop_roundtrip_signing_key_stake_CBOR =
roundtrip_CBOR (AsSigningKey AsStakeKey) (genSigningKey AsStakeKey)
prop_roundtrip_verification_key_genesis_CBOR :: Property
prop_roundtrip_verification_key_genesis_CBOR =
roundtrip_CBOR (AsVerificationKey AsGenesisKey) (genVerificationKey AsGenesisKey)
prop_roundtrip_signing_key_genesis_CBOR :: Property
prop_roundtrip_signing_key_genesis_CBOR =
roundtrip_CBOR (AsSigningKey AsGenesisKey) (genSigningKey AsGenesisKey)
prop_roundtrip_verification_key_genesis_delegate_CBOR :: Property
prop_roundtrip_verification_key_genesis_delegate_CBOR =
roundtrip_CBOR (AsVerificationKey AsGenesisDelegateKey) (genVerificationKey AsGenesisDelegateKey)
prop_roundtrip_signing_key_genesis_delegate_CBOR :: Property
prop_roundtrip_signing_key_genesis_delegate_CBOR =
roundtrip_CBOR (AsSigningKey AsGenesisDelegateKey) (genSigningKey AsGenesisDelegateKey)
prop_roundtrip_verification_key_stake_pool_CBOR :: Property
prop_roundtrip_verification_key_stake_pool_CBOR =
roundtrip_CBOR (AsVerificationKey AsStakePoolKey) (genVerificationKey AsStakePoolKey)
prop_roundtrip_signing_key_stake_pool_CBOR :: Property
prop_roundtrip_signing_key_stake_pool_CBOR =
roundtrip_CBOR (AsSigningKey AsStakePoolKey) (genSigningKey AsStakePoolKey)
prop_roundtrip_verification_key_vrf_CBOR :: Property
prop_roundtrip_verification_key_vrf_CBOR =
roundtrip_CBOR (AsVerificationKey AsVrfKey) (genVerificationKey AsVrfKey)
prop_roundtrip_signing_key_vrf_CBOR :: Property
prop_roundtrip_signing_key_vrf_CBOR =
roundtrip_CBOR (AsSigningKey AsVrfKey) (genSigningKey AsVrfKey)
prop_roundtrip_verification_key_kes_CBOR :: Property
prop_roundtrip_verification_key_kes_CBOR =
roundtrip_CBOR (AsVerificationKey AsKesKey) (genVerificationKey AsKesKey)
prop_roundtrip_signing_key_kes_CBOR :: Property
prop_roundtrip_signing_key_kes_CBOR =
roundtrip_CBOR (AsSigningKey AsKesKey) (genSigningKey AsKesKey)
prop_roundtrip_script_SimpleScriptV1_CBOR :: Property
prop_roundtrip_script_SimpleScriptV1_CBOR =
roundtrip_CBOR (AsScript AsSimpleScriptV1)
(genScript (SimpleScriptLanguage SimpleScriptV1))
prop_roundtrip_script_SimpleScriptV2_CBOR :: Property
prop_roundtrip_script_SimpleScriptV2_CBOR =
roundtrip_CBOR (AsScript AsSimpleScriptV2)
(genScript (SimpleScriptLanguage SimpleScriptV2))
prop_roundtrip_script_PlutusScriptV1_CBOR :: Property
prop_roundtrip_script_PlutusScriptV1_CBOR =
roundtrip_CBOR (AsScript AsPlutusScriptV1)
(genScript (PlutusScriptLanguage PlutusScriptV1))
prop_roundtrip_script_PlutusScriptV2_CBOR :: Property
prop_roundtrip_script_PlutusScriptV2_CBOR =
roundtrip_CBOR (AsScript AsPlutusScriptV2)
(genScript (PlutusScriptLanguage PlutusScriptV2))
prop_roundtrip_UpdateProposal_CBOR :: Property
prop_roundtrip_UpdateProposal_CBOR =
roundtrip_CBOR AsUpdateProposal genUpdateProposal
test_roundtrip_Tx_Cddl :: [TestTree]
test_roundtrip_Tx_Cddl =
[ testProperty (show era) $ roundtrip_Tx_Cddl anyEra
| anyEra@(AnyCardanoEra era) <- [minBound..(AnyCardanoEra AlonzoEra)] --TODO: Babbage era
]
test_roundtrip_TxWitness_Cddl :: [TestTree]
test_roundtrip_TxWitness_Cddl =
[ testProperty (show era) $ roundtrip_TxWitness_Cddl era
| AnyCardanoEra era <- [minBound..(AnyCardanoEra AlonzoEra)] --TODO: Babbage era
, AnyCardanoEra era /= AnyCardanoEra ByronEra
]
roundtrip_TxWitness_Cddl :: CardanoEra era -> Property
roundtrip_TxWitness_Cddl era =
property $
case cardanoEraStyle era of
LegacyByronEra -> success
ShelleyBasedEra sbe -> do
keyWit <- forAll $ genShelleyKeyWitness era
tripping keyWit
(serialiseWitnessLedgerCddl sbe)
(deserialiseWitnessLedgerCddl sbe)
roundtrip_Tx_Cddl :: AnyCardanoEra -> Property
roundtrip_Tx_Cddl (AnyCardanoEra era) =
property $ do
tx <- forAll $ genTx era
tripping tx
serialiseTxLedgerCddl
(deserialiseTxLedgerCddl era)
-- -----------------------------------------------------------------------------
tests :: TestTree
tests = $testGroupGenerator