Skip to content

Commit 86616c5

Browse files
committed
WIP: Fixing tests. You need to update the tests to test the equivalence
of the new txbody conten vs the old one
1 parent a91cc5d commit 86616c5

File tree

8 files changed

+176
-286
lines changed

8 files changed

+176
-286
lines changed

cardano-api/cardano-api.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,17 @@ library
227227
Cardano.Api.Experimental.Plutus.Internal.Script
228228
Cardano.Api.Experimental.Plutus.Internal.ScriptWitness
229229
Cardano.Api.Experimental.Plutus.Internal.Shim.LegacyScripts
230+
Cardano.Api.Experimental.Script
230231
Cardano.Api.Experimental.Serialise.TextEnvelope.Internal
231232
Cardano.Api.Experimental.Tx.Internal.AnyWitness
232-
Cardano.Api.Experimental.Tx.Internal.Body
233+
Cardano.Api.Experimental.Tx.Internal.BodyContent.New
233234
Cardano.Api.Experimental.Tx.Internal.Certificate
234235
Cardano.Api.Experimental.Tx.Internal.Certificate.Compatible
235236
Cardano.Api.Experimental.Tx.Internal.Certificate.Type
236237
Cardano.Api.Experimental.Tx.Internal.Compatible
237238
Cardano.Api.Experimental.Tx.Internal.Fee
238239
Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements
240+
Cardano.Api.Experimental.Tx.Internal.Type
239241
Cardano.Api.Genesis.Internal
240242
Cardano.Api.Genesis.Internal.Parameters
241243
Cardano.Api.Governance.Internal.Action.ProposalProcedure
@@ -306,6 +308,7 @@ library gen
306308
Test.Gen.Cardano.Api
307309
Test.Gen.Cardano.Api.Byron
308310
Test.Gen.Cardano.Api.Era
311+
Test.Gen.Cardano.Api.Experimental
309312
Test.Gen.Cardano.Api.Hardcoded
310313
Test.Gen.Cardano.Api.Metadata
311314
Test.Gen.Cardano.Api.Orphans
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Test.Gen.Cardano.Api.Experimental
2+
( genScriptWitnessedTxIn
3+
, genScriptWitnessedTxMintValue
4+
)
5+
where
6+
7+
import Cardano.Api.Experimental
8+
import Cardano.Api.Experimental.Tx.Internal.BodyContent.New
9+
import Cardano.Api (TxIn)
10+
import Hedgehog (Gen)
11+
12+
genScriptWitnessedTxIn :: Gen [(TxIn, AnyWitness era)]
13+
genScriptWitnessedTxIn = undefined
14+
15+
16+
genScriptWitnessedTxMintValue :: Gen (TxMintValue era)
17+
genScriptWitnessedTxMintValue = undefined

cardano-api/src/Cardano/Api/Experimental/Tx.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ module Cardano.Api.Experimental.Tx
124124
, convertTxBodyToUnsignedTx
125125
, hashTxBody
126126

127+
-- * TxBodyContent
128+
, TxBodyContent (..)
129+
, defaultTxBodyContent
130+
, setTxIns
131+
, setTxMintValue
132+
127133
-- * Witness
128134

129135
-- ** Any witness (key, simple script, plutus script).
@@ -150,10 +156,7 @@ import Cardano.Api.Era.Internal.Core qualified as Api
150156
import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
151157
import Cardano.Api.Experimental.Era
152158
import Cardano.Api.Experimental.Tx.Internal.AnyWitness
153-
import Cardano.Api.Experimental.Tx.Internal.BodyContent.Old
154-
( extractAllIndexedPlutusScriptWitnesses
155-
, makeUnsignedTx
156-
)
159+
import Cardano.Api.Experimental.Tx.Internal.BodyContent.New
157160
import Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements
158161
import Cardano.Api.Experimental.Tx.Internal.Type
159162
import Cardano.Api.HasTypeProxy (HasTypeProxy (..), Proxy, asType)

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/BodyContent/New.hs

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ module Cardano.Api.Experimental.Tx.Internal.BodyContent.New
1919
, TxVotingProcedures (..)
2020
, TxWithdrawals (..)
2121
, TxBodyContent (..)
22+
, defaultTxBodyContent
2223
, collectTxBodyScriptWitnessRequirements
23-
, createUnsignedTx
24+
, makeUnsignedTx
2425
, extractAllIndexedPlutusScriptWitnesses
2526
, txMintValueToValue
27+
28+
-- * Getters and Setters
29+
, setTxIns
30+
, setTxMintValue
2631
)
2732
where
2833

@@ -71,6 +76,7 @@ import Control.Monad
7176
import Data.Functor
7277
import Data.List qualified as List
7378
import Data.Map.Ordered.Strict (OMap)
79+
import Data.Map.Ordered.Strict qualified as OMap
7480
import Data.Map.Strict (Map)
7581
import Data.Map.Strict qualified as Map
7682
import Data.Maybe
@@ -82,13 +88,13 @@ import Data.Set qualified as Set
8288
import GHC.Exts (IsList (..))
8389
import Lens.Micro
8490

85-
createUnsignedTx
91+
makeUnsignedTx
8692
:: forall era
8793
. Era era
88-
-> TxBodyContent CtxTx (LedgerEra era)
94+
-> TxBodyContent (LedgerEra era)
8995
-> Either String (UnsignedTx era)
90-
createUnsignedTx DijkstraEra _ = error "makeUnsignedTx: Dijkstra era not supported yet"
91-
createUnsignedTx era@ConwayEra bc = obtainCommonConstraints era $ do
96+
makeUnsignedTx DijkstraEra _ = error "makeUnsignedTx: Dijkstra era not supported yet"
97+
makeUnsignedTx era@ConwayEra bc = obtainCommonConstraints era $ do
9298
TxScriptWitnessRequirements languages scripts datums redeemers <-
9399
collectTxBodyScriptWitnessRequirements bc
94100

@@ -158,7 +164,7 @@ convTxIns :: [(TxIn, AnyWitness era)] -> Set L.TxIn
158164
convTxIns inputs =
159165
Set.fromList [toShelleyTxIn txin | (txin, _) <- inputs]
160166

161-
convCollateralTxIns :: TxBodyContent ctx era -> Set L.TxIn
167+
convCollateralTxIns :: TxBodyContent (LedgerEra era) -> Set L.TxIn
162168
convCollateralTxIns b =
163169
fromList (map toShelleyTxIn $ txInsCollateral b)
164170

@@ -245,7 +251,7 @@ toAuxiliaryData txMData ss' =
245251
eraSpecificLedgerTxBody
246252
:: Era era
247253
-> L.TxBody (LedgerEra era)
248-
-> TxBodyContent ctx (LedgerEra era)
254+
-> TxBodyContent (LedgerEra era)
249255
-> L.TxBody (LedgerEra era)
250256
eraSpecificLedgerTxBody era ledgerbody bc =
251257
body era
@@ -319,12 +325,15 @@ newtype TxCertificates era
319325
-- This is incorrect. Only scripts can witness minting!
320326
newtype TxMintValue era
321327
= TxMintValue
322-
( Map
323-
PolicyId
324-
( PolicyAssets
325-
, AnyWitness era
326-
)
327-
)
328+
{ unTxMintValue
329+
:: ( Map
330+
PolicyId
331+
( PolicyAssets
332+
, AnyWitness era
333+
)
334+
)
335+
}
336+
deriving (Eq, Show)
328337

329338
-- | Convert 'TxMintValue' to a more handy 'Value'.
330339
txMintValueToValue :: TxMintValue era -> Value
@@ -346,12 +355,12 @@ data TxVotingProcedures era
346355
(L.VotingProcedures era)
347356
(Map L.Voter (AnyWitness era))
348357

349-
data TxBodyContent ctx era
358+
data TxBodyContent era
350359
= TxBodyContent
351360
{ txIns :: [(TxIn, AnyWitness era)]
352361
, txInsCollateral :: [TxIn]
353362
, txInsReference :: TxInsReference era
354-
, txOuts :: [TxOut ctx era]
363+
, txOuts :: [TxOut CtxTx era]
355364
, txCollateral :: Maybe (TxCollateral era)
356365
, txFee :: L.Coin
357366
, txValidityLowerBound :: Maybe L.SlotNo
@@ -372,10 +381,36 @@ data TxBodyContent ctx era
372381
-- -- ^ Treasury donation to perform
373382
}
374383

384+
defaultTxBodyContent
385+
:: TxBodyContent (LedgerEra era)
386+
defaultTxBodyContent =
387+
TxBodyContent
388+
{ txIns = []
389+
, txInsCollateral = []
390+
, txInsReference = TxInsReference mempty Set.empty
391+
, txOuts = []
392+
, txCollateral = Nothing
393+
, txFee = 0
394+
, txValidityLowerBound = Nothing
395+
, txValidityUpperBound = Nothing
396+
, txMetadata = TxMetadata mempty
397+
, txAuxScripts = []
398+
, txExtraKeyWits = TxExtraKeyWitnesses []
399+
, txProtocolParams = Nothing
400+
, txWithdrawals = TxWithdrawals mempty
401+
, txCertificates = TxCertificates OMap.empty
402+
, txMintValue = TxMintValue mempty
403+
, txScriptValidity = ScriptValid
404+
, txProposalProcedures = Nothing
405+
, txVotingProcedures = Nothing
406+
, txCurrentTreasuryValue = Nothing
407+
, txTreasuryDonation = Nothing
408+
}
409+
375410
extractAllIndexedPlutusScriptWitnesses
376-
:: forall era ctx
411+
:: forall era
377412
. Era era
378-
-> TxBodyContent ctx (LedgerEra era)
413+
-> TxBodyContent (LedgerEra era)
379414
-> Either
380415
CBOR.DecoderError
381416
[AnyIndexedPlutusScriptWitness (LedgerEra era)]
@@ -506,7 +541,7 @@ extractWitnessableProposals (Just txPropProcedures) =
506541
collectTxBodyScriptWitnessRequirements
507542
:: forall era
508543
. IsEra era
509-
=> TxBodyContent CtxTx (LedgerEra era)
544+
=> TxBodyContent (LedgerEra era)
510545
-> Either
511546
String
512547
(TxScriptWitnessRequirements (LedgerEra era))
@@ -591,3 +626,11 @@ getDatums txInsRef txOutsFromTx = do
591626
L.TxDats $
592627
fromList $
593628
refInDatums <> txOutsDats
629+
630+
-- Getters and Setters
631+
632+
setTxIns :: [(TxIn, AnyWitness era)] -> TxBodyContent era -> TxBodyContent era
633+
setTxIns v txBodyContent = txBodyContent{txIns = v}
634+
635+
setTxMintValue :: TxMintValue era -> TxBodyContent era -> TxBodyContent era
636+
setTxMintValue v txBodyContent = txBodyContent{txMintValue = v}

0 commit comments

Comments
 (0)