Skip to content

Commit cb5455b

Browse files
committed
sadf
1 parent 37fb0c9 commit cb5455b

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed

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

+56-16
Original file line numberDiff line numberDiff line change
@@ -21,17 +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

37+
import Hedgehog
3538
import Hedgehog (Property, (===))
3639
import qualified Hedgehog as H
3740
import qualified Hedgehog.Extras.Test.Base as H
@@ -84,11 +87,19 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
8487

8588
let scriptData1 = unsafeHashableScriptData $ ScriptDataBytes "CAFEBABE"
8689
scriptData2 = unsafeHashableScriptData $ ScriptDataBytes "DEADBEEF"
87-
txDatum1 =
90+
scriptData3 = unsafeHashableScriptData $ ScriptDataBytes "FEEDCOFFEE"
91+
-- 4e548d257ab5309e4d029426a502e5609f7b0dbd1ac61f696f8373bd2b147e23
92+
H.noteShow_ $ hashScriptDataBytes scriptData1
93+
-- 24f56ef6459a29416df2e89d8df944e29591220283f198d39f7873917b8fa7c1
94+
H.noteShow_ $ hashScriptDataBytes scriptData2
95+
-- 5e47eaf4f0a604fcc939076f74ce7ed59d1503738973522e4d9cb99db703dcb8
96+
H.noteShow_ $ hashScriptDataBytes scriptData3
97+
let txDatum1 =
8898
TxOutDatumHash
8999
(convert beo)
90100
(hashScriptDataBytes scriptData1)
91-
txDatum2 = TxOutDatumInline (convert ceo) scriptData2
101+
txDatum2 = TxOutDatumInline beo scriptData2
102+
txDatum3 = TxOutSupplementalDatum (convert beo) scriptData3
92103

93104
-- Build a first transaction with txout supplemental data
94105
tx1Utxo <- do
@@ -99,6 +110,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
99110
txOuts =
100111
[ TxOut addr1 txOutValue txDatum1 ReferenceScriptNone
101112
, TxOut addr1 txOutValue txDatum2 ReferenceScriptNone
113+
, TxOut addr1 txOutValue txDatum3 ReferenceScriptNone
102114
]
103115

104116
-- build a transaction
@@ -110,7 +122,7 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
110122

111123
utxo <- UTxO <$> findAllUtxos epochStateView sbe
112124

113-
BalancedTxBody _ txBody _ fee <-
125+
BalancedTxBody _ txBody@(ShelleyTxBody _ lbody _ (TxBodyScriptData _ (L.TxDats' datums) _) _ _) _ fee <-
114126
H.leftFail $
115127
makeTransactionBodyAutoBalance
116128
sbe
@@ -126,39 +138,56 @@ hprop_tx_supp_datum = integrationRetryWorkspace 2 "api-tx-supp-dat" $ \tempAbsBa
126138
Nothing -- keys override
127139
H.noteShow_ fee
128140

141+
H.noteShowPretty_ lbody
142+
143+
let bodyScriptData = fromList . map fromAlonzoData $ M.elems datums :: Set HashableScriptData
144+
-- TODO: only inline datum gets included here, but should be all of them
145+
-- TODO what's the actual purpose of TxSupplementalDatum - can we remove it?
146+
-- TODO adding all datums breaks script integrity hash, might have to manually compute it?
147+
-- https://github.com/tweag/cooked-validators/blob/9cb80810d982c9eccd3f7710a996d20f944a95ec/src/Cooked/MockChain/GenerateTx/Body.hs#L127
148+
--
149+
-- TODO getDataHashBabbageTxOut excludes inline datums - WHY IT HAPPENS ONLY HERE BUT NOT WHEN CALLING CLI?
150+
151+
-- TODO add scriptData1 when datum can be provided to transaction building
152+
[ scriptData2
153+
, scriptData3
154+
]
155+
=== bodyScriptData
156+
129157
let tx = signShelleyTransaction sbe txBody [wit0]
130158
txId <- H.noteShow . getTxId $ getTxBody tx
131159

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
160+
H.noteShowPretty_ tx
161+
162+
submitTx sbe connectionInfo tx
135163

136164
-- wait till transaction gets included in the block
137165
_ <- waitForBlocks epochStateView 1
138166

139167
-- test if it's in UTxO set
140168
utxo1 <- findAllUtxos epochStateView sbe
141169
let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
142-
3 === length txUtxo
170+
4 === length txUtxo
143171

144172
let chainTxOuts =
145173
reverse
146174
. drop 1
147175
. reverse
148-
. map (fromCtxUTxOTxOut . snd)
176+
. map snd
149177
. toList
150178
$ M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
151179

152-
txOuts === chainTxOuts
180+
(toCtxUTxOTxOut <$> txOuts) === chainTxOuts
153181

154182
pure txUtxo
155183

156184
do
157185
[(txIn1, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum1) $ toList tx1Utxo
186+
-- H.noteShowPretty_ tx1Utxo
158187
[(txIn2, _)] <- pure $ filter (\(_, TxOut _ _ datum _) -> datum == txDatum2) $ toList tx1Utxo
159188

160-
let scriptData3 = unsafeHashableScriptData $ ScriptDataBytes "C0FFEE"
161-
txDatum = TxOutDatumInline (convert ceo) scriptData3
189+
let scriptData4 = unsafeHashableScriptData $ ScriptDataBytes "C0FFEE"
190+
txDatum = TxOutDatumInline beo scriptData4
162191
txOutValue = lovelaceToTxOutValue sbe 99_999_500
163192
txOut = TxOut addr0 txOutValue txDatum ReferenceScriptNone
164193

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

178206
let tx = signShelleyTransaction sbe txBody [wit1]
179207
-- H.noteShowPretty_ tx
180208
txId <- H.noteShow . getTxId $ getTxBody tx
181209

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
210+
submitTx sbe connectionInfo tx
185211

186212
-- wait till transaction gets included in the block
187213
_ <- waitForBlocks epochStateView 1
188214

189215
-- test if it's in UTxO set
190216
utxo1 <- findAllUtxos epochStateView sbe
191217
let txUtxo = M.filterWithKey (\(TxIn txId' _) _ -> txId == txId') utxo1
192-
[txOut] === M.elems txUtxo
218+
[toCtxUTxOTxOut txOut] === M.elems txUtxo
193219

194220
H.failure
221+
222+
submitTx
223+
:: MonadTest m
224+
=> MonadIO m
225+
=> HasCallStack
226+
=> ShelleyBasedEra era
227+
-> LocalNodeConnectInfo
228+
-> Tx era
229+
-> m ()
230+
submitTx sbe connectionInfo tx =
231+
withFrozenCallStack $
232+
H.evalIO (submitTxToNodeLocal connectionInfo (TxInMode sbe tx)) >>= \case
233+
Net.Tx.SubmitFail reason -> H.noteShowPretty_ reason >> H.failure
234+
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
@@ -84,12 +84,19 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
8484
(txin1, TxOut _addr outValue _datum _refScript) <- H.nothingFailM $ findLargestUtxoWithAddress epochStateView sbe (paymentKeyInfoAddr wallet0)
8585
let (L.Coin initialAmount) = txOutValueToLovelace outValue
8686

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

106113
void $ execCli' execConfig
107114
[ 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)