Skip to content

Commit 28974a5

Browse files
committed
update test suite
1 parent 30b9701 commit 28974a5

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

test/Spec/BotPlutusInterface/Balance.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Ledger.CardanoWallet qualified as Wallet
1515
import Ledger.Crypto (PubKeyHash)
1616
import Ledger.Tx (Tx (..), TxIn (..), TxInType (..), TxOut (..), TxOutRef (..))
1717
import Ledger.Value qualified as Value
18-
import Spec.MockContract (runPABEffectPure)
18+
import Spec.MockContract (currencySymbol1, runPABEffectPure)
1919
import Test.Tasty (TestTree, testGroup)
2020
import Test.Tasty.HUnit (Assertion, assertFailure, testCase, (@?=))
2121
import Prelude
@@ -56,7 +56,7 @@ utxo1, utxo2, utxo3, utxo4 :: (TxOutRef, TxOut)
5656
utxo1 = (txOutRef1, TxOut addr1 (Ada.lovelaceValueOf 1_100_000) Nothing)
5757
utxo2 = (txOutRef2, TxOut addr1 (Ada.lovelaceValueOf 1_000_000) Nothing)
5858
utxo3 = (txOutRef3, TxOut addr1 (Ada.lovelaceValueOf 900_000) Nothing)
59-
utxo4 = (txOutRef4, TxOut addr1 (Ada.lovelaceValueOf 800_000 <> Value.singleton "11223344" "Token" 200) Nothing)
59+
utxo4 = (txOutRef4, TxOut addr1 (Ada.lovelaceValueOf 800_000 <> Value.singleton currencySymbol1 "Token" 200) Nothing)
6060

6161
addUtxosForFees :: Assertion
6262
addUtxosForFees = do
@@ -83,7 +83,7 @@ addUtxosForNativeTokens = do
8383
to `txout` Value aims to simulate result of `adjustUnbalancedTx` call.
8484
Note that 1 Ada is test value - real amount is determined by Ledger and can vary.
8585
-}
86-
txout = TxOut addr2 (Value.singleton "11223344" "Token" 123 <> minimumAdaRequired) Nothing
86+
txout = TxOut addr2 (Value.singleton currencySymbol1 "Token" 123 <> minimumAdaRequired) Nothing
8787
tx = mempty {txOutputs = [txout]} `withFee` 500_000
8888
utxoIndex = Map.fromList [utxo1, utxo2, utxo3, utxo4]
8989
ownAddr = addr1

test/Spec/BotPlutusInterface/Contract.hs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import Spec.MockContract (
6161
addr1,
6262
addr2,
6363
commandHistory,
64+
currencySymbol1,
6465
files,
6566
observableState,
6667
paymentPkh2,
@@ -354,12 +355,12 @@ sendTokens = do
354355
txOut1 =
355356
PublicKeyChainIndexTxOut
356357
pkhAddr1
357-
(Ada.lovelaceValueOf 1350 <> Value.singleton "abcd1234" "testToken" 100)
358+
(Ada.adaValueOf 50 <> Value.singleton currencySymbol1 "testToken" 100)
358359
Nothing
359360
Nothing
360361
txOutRef2 = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 1
361362
txOut2 =
362-
PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1250) Nothing Nothing
363+
PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
363364
initState = def & utxos <>~ [(txOutRef1, txOut1), (txOutRef2, txOut2)]
364365
inTxId1 = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef1
365366

@@ -368,9 +369,12 @@ sendTokens = do
368369
let constraints =
369370
Constraints.mustPayToPubKey
370371
paymentPkh2
371-
(Ada.lovelaceValueOf 1000 <> Value.singleton "abcd1234" "testToken" 5)
372+
(Ada.lovelaceValueOf 1000 <> Value.singleton currencySymbol1 "testToken" 5)
372373
Plutus.Contract.submitTx constraints
373374

375+
curSymbol' :: Text
376+
curSymbol' = encodeByteString $ fromBuiltin $ Value.unCurrencySymbol currencySymbol1
377+
374378
assertContract contract initState $ \state ->
375379
assertCommandHistory
376380
state
@@ -379,8 +383,8 @@ sendTokens = do
379383
, [text|
380384
cardano-cli transaction build-raw --babbage-era
381385
--tx-in ${inTxId1}#0
382-
--tx-out ${addr2}+1000 + 5 abcd1234.74657374546F6B656E
383-
--tx-out ${addr1}+50 + 95 abcd1234.74657374546F6B656E
386+
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
387+
--tx-out ${addr1}+49998700 + 95 ${curSymbol'}.74657374546F6B656E
384388
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
385389
--fee 300
386390
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
@@ -392,10 +396,10 @@ sendTokensWithoutName :: Assertion
392396
sendTokensWithoutName = do
393397
let txOutRef1 = TxOutRef "08b27dbdcff9ab3b432638536ec7eab36c8a2e457703fb1b559dd754032ef431" 0
394398
txOut1 =
395-
PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1350 <> Value.singleton "abcd1234" "" 100) Nothing Nothing
399+
PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50 <> Value.singleton currencySymbol1 "" 100) Nothing Nothing
396400
txOutRef2 = TxOutRef "e406b0cf676fc2b1a9edb0617f259ad025c20ea6f0333820aa7cef1bfe7302e5" 1
397401
txOut2 =
398-
PublicKeyChainIndexTxOut pkhAddr1 (Ada.lovelaceValueOf 1250) Nothing Nothing
402+
PublicKeyChainIndexTxOut pkhAddr1 (Ada.adaValueOf 50) Nothing Nothing
399403
initState = def & utxos <>~ [(txOutRef1, txOut1), (txOutRef2, txOut2)]
400404
inTxId1 = encodeByteString $ fromBuiltin $ Tx.getTxId $ Tx.txOutRefId txOutRef1
401405

@@ -404,9 +408,12 @@ sendTokensWithoutName = do
404408
let constraints =
405409
Constraints.mustPayToPubKey
406410
paymentPkh2
407-
(Ada.lovelaceValueOf 1000 <> Value.singleton "abcd1234" "" 5)
411+
(Ada.lovelaceValueOf 1000 <> Value.singleton currencySymbol1 "" 5)
408412
Plutus.Contract.submitTx constraints
409413

414+
curSymbol' :: Text
415+
curSymbol' = encodeByteString $ fromBuiltin $ Value.unCurrencySymbol currencySymbol1
416+
410417
assertContract contract initState $ \state ->
411418
assertCommandHistory
412419
state
@@ -415,8 +422,8 @@ sendTokensWithoutName = do
415422
, [text|
416423
cardano-cli transaction build-raw --babbage-era
417424
--tx-in ${inTxId1}#0
418-
--tx-out ${addr2}+1000 + 5 abcd1234
419-
--tx-out ${addr1}+50 + 95 abcd1234
425+
--tx-out ${addr2}+1000 + 5 ${curSymbol'}
426+
--tx-out ${addr1}+49998700 + 95 ${curSymbol'}
420427
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
421428
--fee 300
422429
--protocol-params-file ./protocol.json --out-file ./txs/tx-?.raw
@@ -433,9 +440,7 @@ mintTokens = do
433440
collateralTxId = encodeByteString $ fromBuiltin $ Tx.getTxId theCollateralTxId
434441

435442
mintingPolicy :: Scripts.MintingPolicy
436-
mintingPolicy =
437-
Scripts.mkMintingPolicyScript
438-
$$(PlutusTx.compile [||(\_ _ -> ())||])
443+
mintingPolicy = Scripts.mkMintingPolicyScript $$(PlutusTx.compile [||(\_ _ -> ())||])
439444

440445
curSymbol :: Ledger.CurrencySymbol
441446
curSymbol = Ledger.scriptCurrencySymbol mintingPolicy

test/Spec/MockContract.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module Spec.MockContract (
3131
pkhAddr1,
3232
pkhAddr2,
3333
pkhAddr3,
34+
currencySymbol1,
3435
-- Test interpreter
3536
runPABEffectPure,
3637
runContractPure,
@@ -174,6 +175,9 @@ import Text.Read (readMaybe)
174175
import Wallet.Types (ContractInstanceId (ContractInstanceId))
175176
import Prelude
176177

178+
currencySymbol1 :: Ledger.CurrencySymbol
179+
currencySymbol1 = "363d3944282b3d16b239235a112c0f6e2f1195de5067f61c0dfc0f5f"
180+
177181
signingKey1, signingKey2, signingKey3 :: SigningKey PaymentKey
178182
signingKey1 = PaymentSigningKey $ genKeyDSIGN $ mkSeedFromBytes $ ByteString.replicate 32 0
179183
signingKey2 = PaymentSigningKey $ genKeyDSIGN $ mkSeedFromBytes $ ByteString.replicate 32 1

0 commit comments

Comments
 (0)