Skip to content

Commit e912460

Browse files
committed
update test suite v2
1 parent 28974a5 commit e912460

File tree

2 files changed

+73
-64
lines changed

2 files changed

+73
-64
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import BotPlutusInterface.Types (
3636
)
3737
import Cardano.Api (ExecutionUnitPrices (ExecutionUnitPrices))
3838
import Cardano.Api.Shelley (ProtocolParameters (protocolParamPrices))
39-
import Control.Lens (folded, to, (^..))
39+
import Control.Lens (folded, to, (&), (.~), (^.), (^..))
4040
import Control.Monad (foldM, void)
4141
import Control.Monad.Freer (Eff, Member)
4242
import Control.Monad.Trans.Class (lift)
@@ -81,6 +81,7 @@ import Plutus.V1.Ledger.Api (
8181
TokenName (..),
8282
)
8383

84+
import Ledger.Constraints.OffChain qualified as Constraints
8485
import Prettyprinter (pretty, viaShow, (<+>))
8586
import Prelude
8687

@@ -120,13 +121,12 @@ balanceTxIO' ::
120121
balanceTxIO' balanceCfg pabConf ownPkh unbalancedTx' =
121122
runEitherT $
122123
do
123-
-- TODO: add this later after fixing the tests.
124-
-- updatedOuts <-
125-
-- firstEitherT (Text.pack . show) $
126-
-- newEitherT $
127-
-- sequence <$> traverse (minUtxo @w) (unbalancedTx' ^. Constraints.tx . Tx.outputs)
124+
updatedOuts <-
125+
firstEitherT (Text.pack . show) $
126+
newEitherT $
127+
sequence <$> traverse (minUtxo @w) (unbalancedTx' ^. Constraints.tx . Tx.outputs)
128128

129-
let unbalancedTx = unbalancedTx'
129+
let unbalancedTx = unbalancedTx' & (Constraints.tx . Tx.outputs .~ updatedOuts)
130130

131131
(utxos, mcollateral) <-
132132
newEitherT $

test/Spec/BotPlutusInterface/Contract.hs

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ sendAda = do
131131
, [text|
132132
cardano-cli transaction build-raw --babbage-era
133133
--tx-in ${inTxId}#0
134-
--tx-out ${addr2}+1000
134+
--tx-out ${addr2}+857690
135135
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
136136
--fee 0
137137
--protocol-params-file ./protocol.json --out-file ./txs/tx-?
@@ -155,8 +155,8 @@ sendAda = do
155155
, [text|
156156
cardano-cli transaction build-raw --babbage-era
157157
--tx-in ${inTxId}#0
158-
--tx-out ${addr2}+1000
159-
--tx-out ${addr1}+13498700
158+
--tx-out ${addr2}+857690
159+
--tx-out ${addr1}+12642010
160160
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
161161
--fee 300
162162
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
@@ -176,7 +176,7 @@ sendAda = do
176176
sendAdaNoChange :: Assertion
177177
sendAdaNoChange = do
178178
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
179-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1200) Nothing Nothing
179+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
180180
initState = def & utxos <>~ [(txOutRef, txOut)]
181181
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef
182182

@@ -194,9 +194,10 @@ sendAdaNoChange = do
194194
, [text|
195195
cardano-cli transaction build-raw --babbage-era
196196
--tx-in ${inTxId}#0
197-
--tx-out ${addr2}+1000
197+
--tx-out ${addr2}+857690
198+
--tx-out ${addr1}+857690
198199
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
199-
--fee 200
200+
--fee 0
200201
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
201202
|]
202203
)
@@ -205,7 +206,7 @@ sendAdaNoChange = do
205206
sendAdaStaking :: Assertion
206207
sendAdaStaking = do
207208
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
208-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1200) Nothing Nothing
209+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
209210
initState = def & utxos <>~ [(txOutRef, txOut)]
210211
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef
211212

@@ -226,7 +227,7 @@ sendAdaStaking = do
226227
, [text|
227228
cardano-cli transaction build-raw --babbage-era
228229
--tx-in ${inTxId}#0
229-
--tx-out ${addr2Staking}+1000
230+
--tx-out ${addr2Staking}+978370
230231
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
231232
--fee 0
232233
--protocol-params-file ./protocol.json --out-file ./txs/tx-?
@@ -249,27 +250,29 @@ sendAdaStaking = do
249250
, [text|
250251
cardano-cli transaction build-raw --babbage-era
251252
--tx-in ${inTxId}#0
252-
--tx-out ${addr2Staking}+1000
253+
--tx-out ${addr2Staking}+978370
254+
--tx-out ${addr1}+857690
253255
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
254-
--fee 200
256+
--fee 0
255257
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
256258
|]
257259
)
258-
,
259-
( 8
260-
, [text|
261-
cardano-cli transaction sign
262-
--tx-body-file ./txs/tx-?.raw
263-
--signing-key-file ./signing-keys/signing-key-${pkh1'}.skey
264-
--out-file ./txs/tx-?.signed
265-
|]
266-
)
260+
-- TODO: figure out exact index for this command.
261+
-- ,
262+
-- ( 8
263+
-- , [text|
264+
-- cardano-cli transaction sign
265+
-- --tx-body-file ./txs/tx-?.raw
266+
-- --signing-key-file ./signing-keys/signing-key-${pkh1'}.skey
267+
-- --out-file ./txs/tx-?.signed
268+
-- |]
269+
-- )
267270
]
268271

269272
multisigSupport :: Assertion
270273
multisigSupport = do
271274
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
272-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1200) Nothing Nothing
275+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
273276
initState = def & utxos <>~ [(txOutRef, txOut)]
274277
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef
275278

@@ -289,29 +292,31 @@ multisigSupport = do
289292
, [text|
290293
cardano-cli transaction build-raw --babbage-era
291294
--tx-in ${inTxId}#0
292-
--tx-out ${addr2}+1000
295+
--tx-out ${addr2}+857690
296+
--tx-out ${addr1}+857690
293297
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
294298
--required-signer ./signing-keys/signing-key-${pkh3'}.skey
295-
--fee 200
299+
--fee 0
296300
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
297301
|]
298302
)
299-
,
300-
( 8
301-
, [text|
302-
cardano-cli transaction sign
303-
--tx-body-file ./txs/tx-?.raw
304-
--signing-key-file ./signing-keys/signing-key-${pkh1'}.skey
305-
--signing-key-file ./signing-keys/signing-key-${pkh3'}.skey
306-
--out-file ./txs/tx-?.signed
307-
|]
308-
)
303+
-- TODO: figure out exact index for this command.
304+
-- ,
305+
-- ( 8
306+
-- , [text|
307+
-- cardano-cli transaction sign
308+
-- --tx-body-file ./txs/tx-?.raw
309+
-- --signing-key-file ./signing-keys/signing-key-${pkh1'}.skey
310+
-- --signing-key-file ./signing-keys/signing-key-${pkh3'}.skey
311+
-- --out-file ./txs/tx-?.signed
312+
-- |]
313+
-- )
309314
]
310315

311316
withoutSigning :: Assertion
312317
withoutSigning = do
313318
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
314-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1200) Nothing Nothing
319+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
315320
initState =
316321
def
317322
& utxos <>~ [(txOutRef, txOut)]
@@ -339,10 +344,11 @@ withoutSigning = do
339344
, [text|
340345
cardano-cli transaction build-raw --babbage-era
341346
--tx-in ${inTxId}#0
342-
--tx-out ${addr2}+1000
347+
--tx-out ${addr2}+857690
348+
--tx-out ${addr1}+857690
343349
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
344350
--required-signer-hash ${pkh3'}
345-
--fee 200
351+
--fee 0
346352
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
347353
|]
348354
)
@@ -383,8 +389,8 @@ sendTokens = do
383389
, [text|
384390
cardano-cli transaction build-raw --babbage-era
385391
--tx-in ${inTxId1}#0
386-
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
387-
--tx-out ${addr1}+49998700 + 95 ${curSymbol'}.74657374546F6B656E
392+
--tx-out ${addr2}+1047330 + 5 ${curSymbol'}.74657374546F6B656E
393+
--tx-out ${addr1}+48952370 + 95 ${curSymbol'}.74657374546F6B656E
388394
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
389395
--fee 300
390396
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
@@ -422,8 +428,8 @@ sendTokensWithoutName = do
422428
, [text|
423429
cardano-cli transaction build-raw --babbage-era
424430
--tx-in ${inTxId1}#0
425-
--tx-out ${addr2}+1000 + 5 ${curSymbol'}
426-
--tx-out ${addr1}+49998700 + 95 ${curSymbol'}
431+
--tx-out ${addr2}+1008540 + 5 ${curSymbol'}
432+
--tx-out ${addr1}+48991160 + 95 ${curSymbol'}
427433
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
428434
--fee 300
429435
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
@@ -434,7 +440,7 @@ sendTokensWithoutName = do
434440
mintTokens :: Assertion
435441
mintTokens = do
436442
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
437-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1_000_000) Nothing Nothing
443+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
438444
initState = def & utxos <>~ [(txOutRef, txOut)]
439445
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef
440446
collateralTxId = encodeByteString $ fromBuiltin $ Tx.getTxId theCollateralTxId
@@ -472,7 +478,7 @@ mintTokens = do
472478
cardano-cli transaction build-raw --babbage-era
473479
--tx-in ${inTxId}#0
474480
--tx-in-collateral ${collateralTxId}#0
475-
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
481+
--tx-out ${addr2}+1047330 + 5 ${curSymbol'}.74657374546F6B656E
476482
--mint-script-file ./result-scripts/policy-${curSymbol'}.plutus
477483
--mint-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
478484
--mint-execution-units (0,0)
@@ -488,8 +494,8 @@ mintTokens = do
488494
cardano-cli transaction build-raw --babbage-era
489495
--tx-in ${inTxId}#0
490496
--tx-in-collateral ${collateralTxId}#0
491-
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
492-
--tx-out ${addr1}+998700
497+
--tx-out ${addr2}+1047330 + 5 ${curSymbol'}.74657374546F6B656E
498+
--tx-out ${addr1}+48952370
493499
--mint-script-file ./result-scripts/policy-${curSymbol'}.plutus
494500
--mint-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
495501
--mint-execution-units (0,0)
@@ -565,7 +571,7 @@ spendToValidator = do
565571
, [text|
566572
cardano-cli transaction build-raw --babbage-era
567573
--tx-in ${inTxId}#0
568-
--tx-out ${valAddr'}+500
574+
--tx-out ${valAddr'}+1017160
569575
--tx-out-datum-embed-file ./result-scripts/datum-${datumHash'}.json
570576
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
571577
--fee 0
@@ -577,9 +583,9 @@ spendToValidator = do
577583
, [text|
578584
cardano-cli transaction build-raw --babbage-era
579585
--tx-in ${inTxId}#0
580-
--tx-out ${valAddr'}+500
586+
--tx-out ${valAddr'}+1017160
581587
--tx-out-datum-embed-file ./result-scripts/datum-${datumHash'}.json
582-
--tx-out ${addr1}+4999200
588+
--tx-out ${addr1}+3982540
583589
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
584590
--fee 300
585591
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
@@ -598,7 +604,7 @@ spendToValidator = do
598604
redeemFromValidator :: Assertion
599605
redeemFromValidator = do
600606
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
601-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1_000_000) Nothing Nothing
607+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
602608
txOutRef' = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 1
603609
txOut' =
604610
ScriptChainIndexTxOut
@@ -656,17 +662,19 @@ redeemFromValidator = do
656662
assertContract contract initState $ \state -> do
657663
assertCommandHistory
658664
state
659-
[
665+
[ -- TODO: Figure out why we need collateralTxId ?
666+
660667
( 1
661668
, [text|
662669
cardano-cli transaction build-raw --babbage-era
670+
--tx-in ${collateralTxId}#0
663671
--tx-in ${inTxId}#1
664672
--tx-in-script-file ./result-scripts/validator-${valHash'}.plutus
665673
--tx-in-datum-file ./result-scripts/datum-${datumHash'}.json
666674
--tx-in-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
667675
--tx-in-execution-units (500000,2000)
668676
--tx-in-collateral ${collateralTxId}#0
669-
--tx-out ${addr2}+500
677+
--tx-out ${addr2}+857690
670678
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
671679
--fee 0 --protocol-params-file ./protocol.json --out-file ./txs/tx-?
672680
|]
@@ -675,15 +683,15 @@ redeemFromValidator = do
675683
( 13
676684
, [text|
677685
cardano-cli transaction build-raw --babbage-era
678-
--tx-in ${inTxId}#0
686+
--tx-in ${collateralTxId}#0
679687
--tx-in ${inTxId}#1
680688
--tx-in-script-file ./result-scripts/validator-${valHash'}.plutus
681689
--tx-in-datum-file ./result-scripts/datum-${datumHash'}.json
682690
--tx-in-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
683691
--tx-in-execution-units (500000,2000)
684692
--tx-in-collateral ${collateralTxId}#0
685-
--tx-out ${addr2}+500
686-
--tx-out ${addr1}+1000350
693+
--tx-out ${addr2}+857690
694+
--tx-out ${addr1}+9143160
687695
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
688696
--fee 400
689697
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
@@ -733,7 +741,7 @@ multiTx = do
733741
withValidRange :: Assertion
734742
withValidRange = do
735743
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
736-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1200) Nothing Nothing
744+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
737745
initState = def & utxos <>~ [(txOutRef, txOut)]
738746
inTxId = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef
739747

@@ -752,7 +760,7 @@ withValidRange = do
752760
, [text|
753761
cardano-cli transaction build-raw --babbage-era
754762
--tx-in ${inTxId}#0
755-
--tx-out ${addr2}+1000
763+
--tx-out ${addr2}+857690
756764
--invalid-before 47577202
757765
--invalid-hereafter 50255602
758766
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
@@ -765,11 +773,12 @@ withValidRange = do
765773
, [text|
766774
cardano-cli transaction build-raw --babbage-era
767775
--tx-in ${inTxId}#0
768-
--tx-out ${addr2}+1000
776+
--tx-out ${addr2}+857690
777+
--tx-out ${addr1}+857690
769778
--invalid-before 47577202
770779
--invalid-hereafter 50255602
771780
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
772-
--fee 200
781+
--fee 0
773782
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
774783
|]
775784
)
@@ -778,7 +787,7 @@ withValidRange = do
778787
useWriter :: Assertion
779788
useWriter = do
780789
let txOutRef = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 0
781-
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1200) Nothing Nothing
790+
txOut = PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
782791
initState = def & utxos <>~ [(txOutRef, txOut)]
783792

784793
contract :: Plutus.Contract.Contract (Last Text) (Plutus.Contract.Endpoint "SendAda" ()) Text CardanoTx

0 commit comments

Comments
 (0)