Skip to content

Commit e633ef2

Browse files
committed
sadf
1 parent 12a8e1b commit e633ef2

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Api/TxSupplementalDatum.hs

+29-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Cardano.Testnet
2121
import Prelude
2222

2323
import Control.Monad
24+
import Data.Bifunctor (second)
2425
import Data.Default.Class
2526
import qualified Data.Map.Strict as M
2627
import Data.Proxy
@@ -84,11 +85,16 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
8485

8586
let scriptData1 = unsafeHashableScriptData $ ScriptDataBytes "CAFEBABE"
8687
scriptData2 = unsafeHashableScriptData $ ScriptDataBytes "DEADBEEF"
87-
txDatum1 =
88+
scriptData3 = unsafeHashableScriptData $ ScriptDataBytes "FEEDCOFFEE"
89+
H.noteShow_ $ hashScriptDataBytes scriptData1
90+
H.noteShow_ $ hashScriptDataBytes scriptData2
91+
H.noteShow_ $ hashScriptDataBytes scriptData3
92+
let txDatum1 =
8893
TxOutDatumHash
8994
(convert beo)
9095
(hashScriptDataBytes scriptData1)
91-
txDatum2 = TxOutDatumInline (convert ceo) scriptData2
96+
txDatum2 = TxOutDatumInline beo scriptData2
97+
txDatum3 = TxOutSupplementalDatum (convert beo) scriptData2
9298

9399
-- Build a first transaction with txout supplemental data
94100
tx1Utxo <- do
@@ -99,6 +105,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
99105
txOuts =
100106
[ TxOut addr1 txOutValue txDatum1 ReferenceScriptNone
101107
, TxOut addr1 txOutValue txDatum2 ReferenceScriptNone
108+
, TxOut addr1 txOutValue txDatum3 ReferenceScriptNone
102109
]
103110

104111
-- build a transaction
@@ -110,7 +117,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
110117

111118
utxo <- UTxO <$> findAllUtxos epochStateView sbe
112119

113-
BalancedTxBody _ txBody _ fee <-
120+
BalancedTxBody _ txBody@(ShelleyTxBody _ lbody _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) _ fee <-
114121
H.leftFail $
115122
makeTransactionBodyAutoBalance
116123
sbe
@@ -126,9 +133,21 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
126133
Nothing -- keys override
127134
H.noteShow_ fee
128135

136+
H.noteShowPretty_ lbody
137+
138+
let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData
139+
-- TODO: only inline datum gets included here, but should be all of them
140+
-- TODO what's the actual purpose of TxSupplementalDatum - can we remove it?
141+
-- TODO adding all datums breaks script integrity hash, might have to manually compute it?
142+
-- https://github.com/tweag/cooked-validators/blob/9cb80810d982c9eccd3f7710a996d20f944a95ec/src/Cooked/MockChain/GenerateTx/Body.hs#L127
143+
[scriptData1, scriptData2, scriptData3] === bodyScriptData
144+
145+
129146
let tx = signShelleyTransaction sbe txBody [wit0]
130147
txId <- H.noteShow . getTxId $ getTxBody tx
131148

149+
H.noteShowPretty_ tx
150+
132151
H.evalIO (submitTxToNodeLocal connectionInfo (TxInMode sbe tx)) >>= \case
133152
Net.Tx.SubmitFail reason -> H.noteShow_ reason >> H.failure
134153
Net.Tx.SubmitSuccess -> H.success
@@ -139,26 +158,27 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
139158
-- test if it's in UTxO set
140159
utxo1 <- findAllUtxos epochStateView sbe
141160
let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
142-
3 === length txUtxo
161+
4 === length txUtxo
143162

144163
let chainTxOuts =
145164
reverse
146165
. drop 1
147166
. reverse
148-
. map (fromCtxUTxOTxOut . snd)
167+
. map snd
149168
. toList
150169
$ M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
151170

152-
txOuts === chainTxOuts
171+
(toCtxUTxOTxOut <$> txOuts) === chainTxOuts
153172

154173
pure txUtxo
155174

156175
do
157176
[(txIn1, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum1) $ toList tx1Utxo
177+
-- H.noteShowPretty_ tx1Utxo
158178
[(txIn2, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum2) $ toList tx1Utxo
159179

160-
let scriptData3 = unsafeHashableScriptData $ ScriptDataBytes "C0FFEE"
161-
txDatum = TxOutDatumInline (convert ceo) scriptData3
180+
let scriptData4 = unsafeHashableScriptData $ ScriptDataBytes "C0FFEE"
181+
txDatum = TxOutDatumInline beo scriptData4
162182
txOutValue = lovelaceToTxOutValue sbe 99_999_500
163183
txOut = TxOut addr0 txOutValue txDatum ReferenceScriptNone
164184

@@ -172,7 +192,6 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
172192
txBody@(ShelleyTxBody _ _ _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) <-
173193
H.leftFail $ createTransactionBody sbe content
174194
let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData
175-
-- TODO why bodyScriptData is empty here?
176195
[scriptData1, scriptData2, scriptData3] === bodyScriptData
177196

178197
let tx = signShelleyTransaction sbe txBody [wit1]
@@ -189,6 +208,6 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
189208
-- test if it's in UTxO set
190209
utxo1 <- findAllUtxos epochStateView sbe
191210
let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
192-
[txOut] === M.elems txUtxo
211+
[toCtxUTxOTxOut txOut] === M.elems txUtxo
193212

194213
H.failure

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DisambiguateRecordFields #-}
2+
{-# LANGUAGE GADTs #-}
23
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE NamedFieldPuns #-}
45
{-# LANGUAGE NumericUnderscores #-}

0 commit comments

Comments
 (0)