Skip to content

Commit cb16ad7

Browse files
UTxO change test now passes.
Unsure whether it correctly tests the condition, but it seems to.
1 parent 48329eb commit cb16ad7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

test/Spec/BotPlutusInterface/Balance.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import BotPlutusInterface.Types (
1010
ContractEnvironment (cePABConfig),
1111
PABConfig (pcOwnPubKeyHash, pcProtocolParams),
1212
)
13-
import Control.Lens ((&), (.~), (^.))
13+
import Control.Lens ((&), (.~), (<>~), (^.))
1414
import Data.Default (Default (def))
1515
import Data.Map qualified as Map
1616
import Data.Set qualified as Set
@@ -22,6 +22,7 @@ import Ledger.Address (Address, PaymentPubKeyHash (PaymentPubKeyHash))
2222
import Ledger.Address qualified as Address
2323
import Ledger.CardanoWallet qualified as Wallet
2424
import Ledger.Constraints qualified as Constraints
25+
import Ledger.Constraints.OffChain qualified as OffChain
2526
import Ledger.Crypto (PubKeyHash)
2627
import Ledger.Scripts qualified as Scripts
2728
import Ledger.Tx (
@@ -173,7 +174,7 @@ dontAddChangeToDatum = do
173174
usrTxOut' =
174175
PublicKeyChainIndexTxOut
175176
pkhAddr3
176-
(Ada.lovelaceValueOf 5_000_000)
177+
(Ada.lovelaceValueOf 1_001_000)
177178
usrTxOut = Ledger.toTxOut usrTxOut'
178179
-- initState :: MockContractState ()
179180
initState =
@@ -189,7 +190,9 @@ dontAddChangeToDatum = do
189190
<> Constraints.ownPaymentPubKeyHash paymentPkh3
190191
txConsts =
191192
-- Pay the same datum to the script, but with more ada.
192-
Constraints.mustPayToOtherScript valHash scrDatum (scrValue <> Ada.lovelaceValueOf 1_000_000)
193+
Constraints.mustPayToOtherScript valHash scrDatum (scrValue <> Ada.lovelaceValueOf 500)
194+
-- <> Constraints.mustPayToOtherScript valHash scrDatum (Ada.lovelaceValueOf 1_000_000)
195+
<> Constraints.mustPayToPubKey paymentPkh3 (Ada.lovelaceValueOf 1_000_000)
193196
<> Constraints.mustSpendScriptOutput txOutRef6 Ledger.unitRedeemer
194197
<> Constraints.mustSpendPubKeyOutput txOutRef7
195198
eunbalancedTx = Constraints.mkTx @Void scrLkups txConsts
@@ -202,12 +205,15 @@ dontAddChangeToDatum = do
202205
(Left txt) -> assertFailure ("PAB effect error: " <> Text.unpack txt)
203206
(Right (Left txt)) -> assertFailure $ "Balancing error: " <> Text.unpack txt -- <> "\n(Tx: " <> show unbalancedTx <> ")"
204207
(Right (Right trx)) -> do
205-
-- TODO: Write the actual test.
208+
let scrTxOut'' = scrTxOut' & Ledger.ciTxOutValue <>~ Ada.lovelaceValueOf 500
209+
scrTxOutNew = Ledger.toTxOut scrTxOut''
206210
assertBool
207211
( "Original UTxO not in output Tx."
208212
<> "\nOriginal UTxO: "
209213
<> show scrTxOut
210214
<> "\nNew UTxOs: "
211215
<> show (txOutputs trx)
216+
<> "\nUnbalanced UTxOs: "
217+
<> show (txOutputs (unbalancedTx ^. OffChain.tx))
212218
)
213-
(scrTxOut `elem` txOutputs trx)
219+
(scrTxOutNew `elem` txOutputs trx)

0 commit comments

Comments
 (0)