Skip to content

Commit 2ff844d

Browse files
Fixed issue with missing key / fixed constraints.
Still need to write actual test.
1 parent f0db484 commit 2ff844d

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

test/Spec/BotPlutusInterface/Balance.hs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import PlutusTx qualified
3838
import Spec.MockContract (
3939
MockContractState,
4040
contractEnv,
41+
paymentPkh3,
42+
pkh3,
43+
pkhAddr3,
4144
runContractPure,
4245
runPABEffectPure,
4346
utxos,
@@ -71,10 +74,10 @@ pkh1, pkh2 :: PubKeyHash
7174
pkh1 = Address.unPaymentPubKeyHash . Wallet.paymentPubKeyHash $ Wallet.knownMockWallet 1
7275
pkh2 = Address.unPaymentPubKeyHash . Wallet.paymentPubKeyHash $ Wallet.knownMockWallet 2
7376

74-
addr1, addr2, addr3 :: Address
77+
addr1, addr2, valAddr :: Address
7578
addr1 = Ledger.pubKeyHashAddress (PaymentPubKeyHash pkh1) Nothing
7679
addr2 = Ledger.pubKeyHashAddress (PaymentPubKeyHash pkh2) Nothing
77-
addr3 = Ledger.scriptAddress validator
80+
valAddr = Ledger.scriptAddress validator
7881

7982
txOutRef1, txOutRef2, txOutRef3, txOutRef4, txOutRef5, txOutRef6, txOutRef7 :: TxOutRef
8083
txOutRef1 = TxOutRef "384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51" 0
@@ -102,7 +105,7 @@ utxo4 = (txOutRef4, TxOut addr1 (Ada.lovelaceValueOf 800_000 <> Value.singleton
102105
utxo7 = (txOutRef2, TxOut addr1 (Ada.lovelaceValueOf 5_000_000) Nothing)
103106

104107
scrValue :: Value.Value
105-
scrValue = (Value.singleton "11223344" "Token" 200) <> (Ada.lovelaceValueOf 500_000)
108+
scrValue = Value.singleton "11223344" "Token" 200 <> Ada.lovelaceValueOf 500_000
106109

107110
scrDatum :: Ledger.Datum
108111
scrDatum = Ledger.Datum $ Api.toBuiltinData (23 :: Integer)
@@ -162,38 +165,42 @@ dontAddChangeToDatum :: Assertion
162165
dontAddChangeToDatum = do
163166
let scrTxOut' =
164167
ScriptChainIndexTxOut
165-
addr3
168+
valAddr
166169
(Right validator) -- (valHash, Just validator)
167170
(Right scrDatum) -- (scrDatumHash, Just scrDatum)
168171
scrValue
169172
scrTxOut = Ledger.toTxOut scrTxOut'
170173
usrTxOut' =
171174
PublicKeyChainIndexTxOut
172-
addr1
175+
pkhAddr3
173176
(Ada.lovelaceValueOf 5_000_000)
174177
usrTxOut = Ledger.toTxOut usrTxOut'
175178
-- initState :: MockContractState ()
176179
initState =
177180
def & utxos .~ [(txOutRef6, scrTxOut), (txOutRef7, usrTxOut)]
178181
& contractEnv .~ contractEnv'
179182
pabConf :: PABConfig
180-
pabConf = def {pcOwnPubKeyHash = pkh1}
183+
pabConf = def {pcOwnPubKeyHash = pkh3}
181184
-- contractEnv' :: ContractEnvironment ()
182185
contractEnv' = def {cePABConfig = pabConf}
183186

184-
-- TODO: set these up.
185-
scrLkups = mempty
186-
txConsts = mempty
187-
187+
scrLkups =
188+
Constraints.unspentOutputs (Map.fromList [(txOutRef6, scrTxOut'), (txOutRef7, usrTxOut')])
189+
<> Constraints.ownPaymentPubKeyHash paymentPkh3
190+
txConsts =
191+
-- Pay the same datum to the script, but with more ada.
192+
Constraints.mustPayToOtherScript valHash scrDatum (scrValue <> Ada.lovelaceValueOf 1_000_000)
193+
<> Constraints.mustSpendScriptOutput txOutRef6 Ledger.unitRedeemer
194+
<> Constraints.mustSpendPubKeyOutput txOutRef7
188195
eunbalancedTx = Constraints.mkTx @Void scrLkups txConsts
189196

190197
case eunbalancedTx of
191198
Left mkTxErr -> assertFailure ("MkTx Error: " <> show mkTxErr)
192199
Right unbalancedTx -> do
193-
let (eRslt, finalState) = runPABEffectPure initState (balanceTxIO @() @'[PABEffect ()] pabConf pkh1 unbalancedTx)
200+
let (eRslt, finalState) = runPABEffectPure initState (balanceTxIO @() @'[PABEffect ()] pabConf pkh3 unbalancedTx)
194201
case eRslt of
195202
(Left txt) -> assertFailure ("PAB effect error: " <> Text.unpack txt)
196-
(Right (Left txt)) -> assertFailure ("Balancing error: " <> Text.unpack txt)
203+
(Right (Left txt)) -> assertFailure $ "Balancing error: " <> Text.unpack txt -- <> "\n(Tx: " <> show unbalancedTx <> ")"
197204
(Right (Right trx)) -> do
198-
-- TODO
205+
-- TODO: Write the actual test.
199206
assertFailure "Incomplete Test"

0 commit comments

Comments
 (0)