@@ -21,6 +21,7 @@ import Cardano.Testnet
21
21
import Prelude
22
22
23
23
import Control.Monad
24
+ import Data.Bifunctor (second )
24
25
import Data.Default.Class
25
26
import qualified Data.Map.Strict as M
26
27
import Data.Proxy
@@ -84,11 +85,16 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
84
85
85
86
let scriptData1 = unsafeHashableScriptData $ ScriptDataBytes " CAFEBABE"
86
87
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 =
88
93
TxOutDatumHash
89
94
(convert beo)
90
95
(hashScriptDataBytes scriptData1)
91
- txDatum2 = TxOutDatumInline (convert ceo) scriptData2
96
+ txDatum2 = TxOutDatumInline beo scriptData2
97
+ txDatum3 = TxOutSupplementalDatum (convert beo) scriptData2
92
98
93
99
-- Build a first transaction with txout supplemental data
94
100
tx1Utxo <- do
@@ -99,6 +105,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
99
105
txOuts =
100
106
[ TxOut addr1 txOutValue txDatum1 ReferenceScriptNone
101
107
, TxOut addr1 txOutValue txDatum2 ReferenceScriptNone
108
+ , TxOut addr1 txOutValue txDatum3 ReferenceScriptNone
102
109
]
103
110
104
111
-- build a transaction
@@ -110,7 +117,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
110
117
111
118
utxo <- UTxO <$> findAllUtxos epochStateView sbe
112
119
113
- BalancedTxBody _ txBody _ fee <-
120
+ BalancedTxBody _ txBody@ ( ShelleyTxBody _ lbody _ ( TxBodyScriptData _ ( L. TxDats' datums) _) _ _) _ fee <-
114
121
H. leftFail $
115
122
makeTransactionBodyAutoBalance
116
123
sbe
@@ -126,9 +133,21 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
126
133
Nothing -- keys override
127
134
H. noteShow_ fee
128
135
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
+
129
146
let tx = signShelleyTransaction sbe txBody [wit0]
130
147
txId <- H. noteShow . getTxId $ getTxBody tx
131
148
149
+ H. noteShowPretty_ tx
150
+
132
151
H. evalIO (submitTxToNodeLocal connectionInfo (TxInMode sbe tx)) >>= \ case
133
152
Net.Tx. SubmitFail reason -> H. noteShow_ reason >> H. failure
134
153
Net.Tx. SubmitSuccess -> H. success
@@ -139,26 +158,27 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
139
158
-- test if it's in UTxO set
140
159
utxo1 <- findAllUtxos epochStateView sbe
141
160
let txUtxo = M. filterWithKey (\ (TxIn txId' _) _ -> txId == txId') utxo1
142
- 3 === length txUtxo
161
+ 4 === length txUtxo
143
162
144
163
let chainTxOuts =
145
164
reverse
146
165
. drop 1
147
166
. reverse
148
- . map (fromCtxUTxOTxOut . snd )
167
+ . map snd
149
168
. toList
150
169
$ M. filterWithKey (\ (TxIn txId' _) _ -> txId == txId') utxo1
151
170
152
- txOuts === chainTxOuts
171
+ (toCtxUTxOTxOut <$> txOuts) === chainTxOuts
153
172
154
173
pure txUtxo
155
174
156
175
do
157
176
[(txIn1, _)] <- pure $ filter (\ (_, TxOut _ _ datum _) -> datum == txDatum1) $ toList tx1Utxo
177
+ -- H.noteShowPretty_ tx1Utxo
158
178
[(txIn2, _)] <- pure $ filter (\ (_, TxOut _ _ datum _) -> datum == txDatum2) $ toList tx1Utxo
159
179
160
- let scriptData3 = unsafeHashableScriptData $ ScriptDataBytes " C0FFEE"
161
- txDatum = TxOutDatumInline (convert ceo) scriptData3
180
+ let scriptData4 = unsafeHashableScriptData $ ScriptDataBytes " C0FFEE"
181
+ txDatum = TxOutDatumInline beo scriptData4
162
182
txOutValue = lovelaceToTxOutValue sbe 99_999_500
163
183
txOut = TxOut addr0 txOutValue txDatum ReferenceScriptNone
164
184
@@ -172,7 +192,6 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
172
192
txBody@ (ShelleyTxBody _ _ _ (TxBodyScriptData _ (L. TxDats' datums) _) _ _) <-
173
193
H. leftFail $ createTransactionBody sbe content
174
194
let bodyScriptData = fromList . map fromAlonzoData $ M. elems datums :: Set HashableScriptData
175
- -- TODO why bodyScriptData is empty here?
176
195
[scriptData1, scriptData2, scriptData3] === bodyScriptData
177
196
178
197
let tx = signShelleyTransaction sbe txBody [wit1]
@@ -189,6 +208,6 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
189
208
-- test if it's in UTxO set
190
209
utxo1 <- findAllUtxos epochStateView sbe
191
210
let txUtxo = M. filterWithKey (\ (TxIn txId' _) _ -> txId == txId') utxo1
192
- [txOut] === M. elems txUtxo
211
+ [toCtxUTxOTxOut txOut] === M. elems txUtxo
193
212
194
213
H. failure
0 commit comments