@@ -21,18 +21,20 @@ 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
27
28
import Data.Set (Set )
28
29
import GHC.Exts (IsList (.. ))
30
+ import GHC.Stack
29
31
import Lens.Micro
30
32
31
33
import Testnet.Components.Query
32
34
import Testnet.Property.Util (integrationRetryWorkspace )
33
35
import Testnet.Types
34
36
35
- import Hedgehog ( Property , (===) )
37
+ import Hedgehog
36
38
import qualified Hedgehog as H
37
39
import qualified Hedgehog.Extras.Test.Base as H
38
40
import qualified Hedgehog.Extras.Test.TestWatchdog as H
@@ -84,11 +86,19 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
84
86
85
87
let scriptData1 = unsafeHashableScriptData $ ScriptDataBytes " CAFEBABE"
86
88
scriptData2 = unsafeHashableScriptData $ ScriptDataBytes " DEADBEEF"
87
- txDatum1 =
89
+ scriptData3 = unsafeHashableScriptData $ ScriptDataBytes " FEEDCOFFEE"
90
+ -- 4e548d257ab5309e4d029426a502e5609f7b0dbd1ac61f696f8373bd2b147e23
91
+ H. noteShow_ $ hashScriptDataBytes scriptData1
92
+ -- 24f56ef6459a29416df2e89d8df944e29591220283f198d39f7873917b8fa7c1
93
+ H. noteShow_ $ hashScriptDataBytes scriptData2
94
+ -- 5e47eaf4f0a604fcc939076f74ce7ed59d1503738973522e4d9cb99db703dcb8
95
+ H. noteShow_ $ hashScriptDataBytes scriptData3
96
+ let txDatum1 =
88
97
TxOutDatumHash
89
98
(convert beo)
90
99
(hashScriptDataBytes scriptData1)
91
- txDatum2 = TxOutDatumInline (convert ceo) scriptData2
100
+ txDatum2 = TxOutDatumInline beo scriptData2
101
+ txDatum3 = TxOutSupplementalDatum (convert beo) scriptData3
92
102
93
103
-- Build a first transaction with txout supplemental data
94
104
tx1Utxo <- do
@@ -99,6 +109,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
99
109
txOuts =
100
110
[ TxOut addr1 txOutValue txDatum1 ReferenceScriptNone
101
111
, TxOut addr1 txOutValue txDatum2 ReferenceScriptNone
112
+ , TxOut addr1 txOutValue txDatum3 ReferenceScriptNone
102
113
]
103
114
104
115
-- build a transaction
@@ -110,7 +121,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
110
121
111
122
utxo <- UTxO <$> findAllUtxos epochStateView sbe
112
123
113
- BalancedTxBody _ txBody _ fee <-
124
+ BalancedTxBody _ txBody@ ( ShelleyTxBody _ lbody _ ( TxBodyScriptData _ ( L. TxDats' datums) _) _ _) _ fee <-
114
125
H. leftFail $
115
126
makeTransactionBodyAutoBalance
116
127
sbe
@@ -126,39 +137,56 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
126
137
Nothing -- keys override
127
138
H. noteShow_ fee
128
139
140
+ H. noteShowPretty_ lbody
141
+
142
+ let bodyScriptData = fromList . map fromAlonzoData $ M. elems datums :: Set HashableScriptData
143
+ -- TODO: only inline datum gets included here, but should be all of them
144
+ -- TODO what's the actual purpose of TxSupplementalDatum - can we remove it?
145
+ -- TODO adding all datums breaks script integrity hash, might have to manually compute it?
146
+ -- https://github.com/tweag/cooked-validators/blob/9cb80810d982c9eccd3f7710a996d20f944a95ec/src/Cooked/MockChain/GenerateTx/Body.hs#L127
147
+ --
148
+ -- TODO getDataHashBabbageTxOut excludes inline datums - WHY IT HAPPENS ONLY HERE BUT NOT WHEN CALLING CLI?
149
+
150
+ -- TODO add scriptData1 when datum can be provided to transaction building
151
+ -- [ scriptData2
152
+ -- , scriptData3
153
+ -- ]
154
+ -- === bodyScriptData
155
+
129
156
let tx = signShelleyTransaction sbe txBody [wit0]
130
157
txId <- H. noteShow . getTxId $ getTxBody tx
131
158
132
- H. evalIO (submitTxToNodeLocal connectionInfo ( TxInMode sbe tx)) >>= \ case
133
- Net.Tx. SubmitFail reason -> H. noteShow_ reason >> H. failure
134
- Net.Tx. SubmitSuccess -> H. success
159
+ H. noteShowPretty_ tx
160
+
161
+ submitTx sbe connectionInfo tx
135
162
136
163
-- wait till transaction gets included in the block
137
164
_ <- waitForBlocks epochStateView 1
138
165
139
166
-- test if it's in UTxO set
140
167
utxo1 <- findAllUtxos epochStateView sbe
141
- let txUtxo = M. filterWithKey (\ (TxIn txId' _) _ -> txId == txId') utxo1
142
- 3 === length txUtxo
168
+ txUtxo <- H. noteShowPretty $ M. filterWithKey (\ (TxIn txId' _) _ -> txId == txId') utxo1
169
+ ( length txOuts + 1 ) === length txUtxo
143
170
144
171
let chainTxOuts =
145
172
reverse
146
173
. drop 1
147
174
. reverse
148
- . map (fromCtxUTxOTxOut . snd )
175
+ . map snd
149
176
. toList
150
177
$ M. filterWithKey (\ (TxIn txId' _) _ -> txId == txId') utxo1
151
178
152
- txOuts === chainTxOuts
179
+ (toCtxUTxOTxOut <$> txOuts) === chainTxOuts
153
180
154
181
pure txUtxo
155
182
156
183
do
157
184
[(txIn1, _)] <- pure $ filter (\ (_, TxOut _ _ datum _) -> datum == txDatum1) $ toList tx1Utxo
185
+ -- H.noteShowPretty_ tx1Utxo
158
186
[(txIn2, _)] <- pure $ filter (\ (_, TxOut _ _ datum _) -> datum == txDatum2) $ toList tx1Utxo
159
187
160
- let scriptData3 = unsafeHashableScriptData $ ScriptDataBytes " C0FFEE"
161
- txDatum = TxOutDatumInline (convert ceo) scriptData3
188
+ let scriptData4 = unsafeHashableScriptData $ ScriptDataBytes " C0FFEE"
189
+ txDatum = TxOutDatumInline beo scriptData4
162
190
txOutValue = lovelaceToTxOutValue sbe 99_999_500
163
191
txOut = TxOut addr0 txOutValue txDatum ReferenceScriptNone
164
192
@@ -172,23 +200,34 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
172
200
txBody@ (ShelleyTxBody _ _ _ (TxBodyScriptData _ (L. TxDats' datums) _) _ _) <-
173
201
H. leftFail $ createTransactionBody sbe content
174
202
let bodyScriptData = fromList . map fromAlonzoData $ M. elems datums :: Set HashableScriptData
175
- -- TODO why bodyScriptData is empty here?
176
203
[scriptData1, scriptData2, scriptData3] === bodyScriptData
177
204
178
205
let tx = signShelleyTransaction sbe txBody [wit1]
179
206
-- H.noteShowPretty_ tx
180
207
txId <- H. noteShow . getTxId $ getTxBody tx
181
208
182
- H. evalIO (submitTxToNodeLocal connectionInfo (TxInMode sbe tx)) >>= \ case
183
- Net.Tx. SubmitFail reason -> H. noteShow_ reason >> H. failure
184
- Net.Tx. SubmitSuccess -> H. success
209
+ submitTx sbe connectionInfo tx
185
210
186
211
-- wait till transaction gets included in the block
187
212
_ <- waitForBlocks epochStateView 1
188
213
189
214
-- test if it's in UTxO set
190
215
utxo1 <- findAllUtxos epochStateView sbe
191
216
let txUtxo = M. filterWithKey (\ (TxIn txId' _) _ -> txId == txId') utxo1
192
- [txOut] === M. elems txUtxo
217
+ [toCtxUTxOTxOut txOut] === M. elems txUtxo
193
218
194
219
H. failure
220
+
221
+ submitTx
222
+ :: MonadTest m
223
+ => MonadIO m
224
+ => HasCallStack
225
+ => ShelleyBasedEra era
226
+ -> LocalNodeConnectInfo
227
+ -> Tx era
228
+ -> m ()
229
+ submitTx sbe connectionInfo tx =
230
+ withFrozenCallStack $
231
+ H. evalIO (submitTxToNodeLocal connectionInfo (TxInMode sbe tx)) >>= \ case
232
+ Net.Tx. SubmitFail reason -> H. noteShowPretty_ reason >> H. failure
233
+ Net.Tx. SubmitSuccess -> H. success
0 commit comments