@@ -171,22 +171,22 @@ dontAddChangeToDatum = do
171171 let scrTxOut' =
172172 ScriptChainIndexTxOut
173173 valAddr
174- (Right validator) -- (valHash, Just validator)
175- (Right scrDatum) -- (scrDatumHash, Just scrDatum)
174+ (Right validator)
175+ (Right scrDatum)
176176 scrValue
177177 scrTxOut = Ledger. toTxOut scrTxOut'
178178 usrTxOut' =
179179 PublicKeyChainIndexTxOut
180180 pkhAddr3
181181 (Ada. lovelaceValueOf 1_001_000 )
182182 usrTxOut = Ledger. toTxOut usrTxOut'
183- -- initState :: MockContractState ()
183+ initState :: MockContractState ()
184184 initState =
185185 def & utxos .~ [(txOutRef6, scrTxOut), (txOutRef7, usrTxOut)]
186186 & contractEnv .~ contractEnv'
187187 pabConf :: PABConfig
188188 pabConf = def {pcOwnPubKeyHash = pkh3}
189- -- contractEnv' :: ContractEnvironment ()
189+ contractEnv' :: ContractEnvironment ()
190190 contractEnv' = def {cePABConfig = pabConf}
191191
192192 -- Input UTxOs:
@@ -203,7 +203,7 @@ dontAddChangeToDatum = do
203203 -- - Amt: 1 ADA
204204 -- UTxO 2:
205205 -- - To : Script
206- -- - Amt: 1.0005 Ada + 200 Token
206+ -- - Amt: 0.5005 Ada + 200 Token
207207 --
208208 -- Fees : 400 Lovelace
209209 -- Change : 100 Lovelace
@@ -214,7 +214,6 @@ dontAddChangeToDatum = do
214214 txConsts =
215215 -- Pay the same datum to the script, but with more ada.
216216 Constraints. mustPayToOtherScript valHash scrDatum (scrValue <> Ada. lovelaceValueOf 500 )
217- -- <> Constraints.mustPayToOtherScript valHash scrDatum (Ada.lovelaceValueOf 1_000_000)
218217 <> Constraints. mustPayToPubKey paymentPkh3 (Ada. lovelaceValueOf 1_000_000 )
219218 <> Constraints. mustSpendScriptOutput txOutRef6 Ledger. unitRedeemer
220219 <> Constraints. mustSpendPubKeyOutput txOutRef7
@@ -226,20 +225,20 @@ dontAddChangeToDatum = do
226225 let (eRslt, _finalState) = runPABEffectPure initState (balanceTxIO @ () @ '[PABEffect () ] pabConf pkh3 unbalancedTx)
227226 case eRslt of
228227 (Left txt) -> assertFailure (" PAB effect error: " <> Text. unpack txt)
229- (Right (Left txt)) -> assertFailure $ " Balancing error: " <> Text. unpack txt -- <> "\n(Tx: " <> show unbalancedTx <> ")"
228+ (Right (Left txt)) -> assertFailure $ " Balancing error: " <> Text. unpack txt
230229 (Right (Right trx)) -> do
231230 let scrTxOut'' = scrTxOut' & Ledger. ciTxOutValue <>~ Ada. lovelaceValueOf 500
232- scrTxOutNew = Ledger. toTxOut scrTxOut''
231+ scrTxOutExpected = Ledger. toTxOut scrTxOut''
233232 assertBool
234233 ( " Expected UTxO not in output Tx."
235234 <> " \n Expected UTxO: "
236- <> show scrTxOutNew
235+ <> show scrTxOutExpected
237236 <> " \n New UTxOs: "
238237 <> show (txOutputs trx)
239238 <> " \n Unbalanced UTxOs: "
240239 <> show (txOutputs (unbalancedTx ^. OffChain. tx))
241240 )
242- (scrTxOutNew `elem` txOutputs trx)
241+ (scrTxOutExpected `elem` txOutputs trx)
243242
244243-- Like the first one, but
245244-- only has inputs from the script.
@@ -248,26 +247,37 @@ dontAddChangeToDatum2 = do
248247 let scrTxOut' =
249248 ScriptChainIndexTxOut
250249 valAddr
251- (Right validator) -- (valHash, Just validator)
252- (Right scrDatum) -- (scrDatumHash, Just scrDatum)
250+ (Right validator)
251+ (Right scrDatum)
253252 (scrValue <> Ada. lovelaceValueOf 1_500_000 )
254253 scrTxOut = Ledger. toTxOut scrTxOut'
255- -- initState :: MockContractState ()
254+ initState :: MockContractState ()
256255 initState =
257256 def & utxos .~ [(txOutRef6, scrTxOut)]
258257 & contractEnv .~ contractEnv'
259258 pabConf :: PABConfig
260259 pabConf = def {pcOwnPubKeyHash = pkh3}
261- -- contractEnv' :: ContractEnvironment ()
260+ contractEnv' :: ContractEnvironment ()
262261 contractEnv' = def {cePABConfig = pabConf}
263262
263+ -- Input UTxO :
264+ -- - 2.0 ADA
265+ -- - 200 tokens
266+ -- Output UTxO :
267+ -- - 0.5 ADA
268+ -- - 100 tokens
269+ -- Change:
270+ -- - 1.5 ADA (400 Lovelace to fees)
271+ -- - 100 tokens
272+
264273 scrLkups =
265274 Constraints. unspentOutputs (Map. fromList [(txOutRef6, scrTxOut')])
266275 <> Constraints. ownPaymentPubKeyHash paymentPkh3
267276 txConsts =
268277 -- Pay the same datum to the script, but with LESS ada
269278 -- and fewer tokens. This is to ensure that the excess
270279 -- ADA and tokens are moved into their own UTxO(s),
280+ -- rather than just being left in the original UTxO.
271281 -- (The extra ada is used to cover fees etc...)
272282 Constraints. mustPayToOtherScript valHash scrDatum scrValue'
273283 <> Constraints. mustSpendScriptOutput txOutRef6 Ledger. unitRedeemer
@@ -279,17 +289,17 @@ dontAddChangeToDatum2 = do
279289 let (eRslt, _finalState) = runPABEffectPure initState (balanceTxIO @ () @ '[PABEffect () ] pabConf pkh3 unbalancedTx)
280290 case eRslt of
281291 (Left txt) -> assertFailure (" PAB effect error: " <> Text. unpack txt)
282- (Right (Left txt)) -> assertFailure $ " Balancing error: " <> Text. unpack txt -- <> "\n(Tx: " <> show unbalancedTx <> ")"
292+ (Right (Left txt)) -> assertFailure $ " Balancing error: " <> Text. unpack txt
283293 (Right (Right trx)) -> do
284294 let scrTxOut'' = scrTxOut' & Ledger. ciTxOutValue .~ scrValue'
285- scrTxOutNew = Ledger. toTxOut scrTxOut''
295+ scrTxOutExpected = Ledger. toTxOut scrTxOut''
286296 assertBool
287297 ( " Expected UTxO not in output Tx."
288298 <> " \n Expected UTxO: "
289- <> show scrTxOutNew
299+ <> show scrTxOutExpected
290300 <> " \n New UTxOs: "
291301 <> show (txOutputs trx)
292302 <> " \n Unbalanced UTxOs: "
293303 <> show (txOutputs (unbalancedTx ^. OffChain. tx))
294304 )
295- (scrTxOutNew `elem` txOutputs trx)
305+ (scrTxOutExpected `elem` txOutputs trx)
0 commit comments