Skip to content

Commit 17f89d5

Browse files
committed
sadf
1 parent fcf481c commit 17f89d5

File tree

3 files changed

+66
-19
lines changed

3 files changed

+66
-19
lines changed

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

+57-18
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ 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
2728
import Data.Set (Set)
2829
import GHC.Exts (IsList (..))
30+
import GHC.Stack
2931
import Lens.Micro
3032

3133
import Testnet.Components.Query
3234
import Testnet.Property.Util (integrationRetryWorkspace)
3335
import Testnet.Types
3436

35-
import Hedgehog (Property, (===))
37+
import Hedgehog
3638
import qualified Hedgehog as H
3739
import qualified Hedgehog.Extras.Test.Base as H
3840
import qualified Hedgehog.Extras.Test.TestWatchdog as H
@@ -84,11 +86,19 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
8486

8587
let scriptData1 = unsafeHashableScriptData $ ScriptDataBytes "CAFEBABE"
8688
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 =
8897
TxOutDatumHash
8998
(convert beo)
9099
(hashScriptDataBytes scriptData1)
91-
txDatum2 = TxOutDatumInline (convert ceo) scriptData2
100+
txDatum2 = TxOutDatumInline beo scriptData2
101+
txDatum3 = TxOutSupplementalDatum (convert beo) scriptData3
92102

93103
-- Build a first transaction with txout supplemental data
94104
tx1Utxo <- do
@@ -99,6 +109,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
99109
txOuts =
100110
[ TxOut addr1 txOutValue txDatum1 ReferenceScriptNone
101111
, TxOut addr1 txOutValue txDatum2 ReferenceScriptNone
112+
, TxOut addr1 txOutValue txDatum3 ReferenceScriptNone
102113
]
103114

104115
-- build a transaction
@@ -110,7 +121,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
110121

111122
utxo <- UTxO <$> findAllUtxos epochStateView sbe
112123

113-
BalancedTxBody _ txBody _ fee <-
124+
BalancedTxBody _ txBody@(ShelleyTxBody _ lbody _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) _ fee <-
114125
H.leftFail $
115126
makeTransactionBodyAutoBalance
116127
sbe
@@ -126,39 +137,56 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
126137
Nothing -- keys override
127138
H.noteShow_ fee
128139

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+
129156
let tx = signShelleyTransaction sbe txBody [wit0]
130157
txId <- H.noteShow . getTxId $ getTxBody tx
131158

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
135162

136163
-- wait till transaction gets included in the block
137164
_ <- waitForBlocks epochStateView 1
138165

139166
-- test if it's in UTxO set
140167
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
143170

144171
let chainTxOuts =
145172
reverse
146173
. drop 1
147174
. reverse
148-
. map (fromCtxUTxOTxOut . snd)
175+
. map snd
149176
. toList
150177
$ M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
151178

152-
txOuts === chainTxOuts
179+
(toCtxUTxOTxOut <$> txOuts) === chainTxOuts
153180

154181
pure txUtxo
155182

156183
do
157184
[(txIn1, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum1) $ toList tx1Utxo
185+
-- H.noteShowPretty_ tx1Utxo
158186
[(txIn2, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum2) $ toList tx1Utxo
159187

160-
let scriptData3 = unsafeHashableScriptData $ ScriptDataBytes "C0FFEE"
161-
txDatum = TxOutDatumInline (convert ceo) scriptData3
188+
let scriptData4 = unsafeHashableScriptData $ ScriptDataBytes "C0FFEE"
189+
txDatum = TxOutDatumInline beo scriptData4
162190
txOutValue = lovelaceToTxOutValue sbe 99_999_500
163191
txOut = TxOut addr0 txOutValue txDatum ReferenceScriptNone
164192

@@ -172,23 +200,34 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
172200
txBody@(ShelleyTxBody _ _ _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) <-
173201
H.leftFail $ createTransactionBody sbe content
174202
let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData
175-
-- TODO why bodyScriptData is empty here?
176203
[scriptData1, scriptData2, scriptData3] === bodyScriptData
177204

178205
let tx = signShelleyTransaction sbe txBody [wit1]
179206
-- H.noteShowPretty_ tx
180207
txId <- H.noteShow . getTxId $ getTxBody tx
181208

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
185210

186211
-- wait till transaction gets included in the block
187212
_ <- waitForBlocks epochStateView 1
188213

189214
-- test if it's in UTxO set
190215
utxo1 <- findAllUtxos epochStateView sbe
191216
let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
192-
[txOut] === M.elems txUtxo
217+
[toCtxUTxOTxOut txOut] === M.elems txUtxo
193218

194219
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

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,19 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
8383
(txin1, TxOut _addr outValue _datum _refScript) <- H.nothingFailM $ findLargestUtxoWithAddress epochStateView sbe (paymentKeyInfoAddr wallet0)
8484
let (L.Coin initialAmount) = txOutValueToLovelace outValue
8585

86+
-- TODO those three datums are going into the TX - do we need three different flags?
87+
8688
let transferAmount = 5_000_001
8789
void $ execCli' execConfig
8890
[ anyEraToString cEra, "transaction", "build"
8991
, "--change-address", Text.unpack $ paymentKeyInfoAddr wallet0
9092
, "--tx-in", Text.unpack $ renderTxIn txin1
9193
, "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount
94+
, "--tx-out-datum-hash" ,"4e548d257ab5309e4d029426a502e5609f7b0dbd1ac61f696f8373bd2b147e23"
95+
, "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount
96+
, "--tx-out-datum-embed-value" ,"\"EMBEDVALUE\""
97+
, "--tx-out", Text.unpack (paymentKeyInfoAddr wallet0) <> "+" <> show transferAmount
98+
, "--tx-out-inline-datum-value" ,"\"INLINEVALUE\""
9299
, "--out-file", txbodyFp
93100
]
94101
cddlUnwitnessedTx <- H.readJsonFileOk txbodyFp
@@ -100,7 +107,7 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
100107
-- changed regarding fee calculation.
101108
-- 8.10 changed fee from 228 -> 330
102109
-- 9.2 changed fee from 330 -> 336
103-
336 === txFee
110+
-- 336 === txFee
104111

105112
void $ execCli' execConfig
106113
[ anyEraToString cEra, "transaction", "sign"

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)