-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathSameWallets.purs
92 lines (79 loc) · 2.67 KB
/
SameWallets.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Test.Ctl.Testnet.SameWallets
( suite
) where
import Contract.Prelude
import Cardano.Types.BigNum as BigNum
import Cardano.Types.Int as Int
import Cardano.Types.Mint as Mint
import Cardano.Types.PlutusScript as PlutusScript
import Contract.Address (PaymentPubKeyHash)
import Contract.Monad (Contract, liftedM)
import Contract.ScriptLookups as Lookups
import Contract.Test.Testnet
( ContractTestPlan
, sameWallets
, withKeyWallet
)
import Contract.Transaction (awaitTxConfirmed, submitTxFromConstraints)
import Contract.TxConstraints as Constraints
import Contract.Value (TokenName, Value)
import Contract.Value as Value
import Contract.Wallet (ownPaymentPubKeyHashes)
import Ctl.Examples.AlwaysMints (alwaysMintsPolicy)
import Ctl.Examples.Helpers (mkAssetName) as Helpers
import Ctl.Internal.Test.UtxoDistribution (InitialUTxOs)
import Data.Array as Array
import Mote (group, test)
suite :: ContractTestPlan
suite =
let
distribution :: InitialUTxOs /\ InitialUTxOs
distribution =
-- Alice
[ BigNum.fromInt 1_000_000_000 ] /\
-- Bob
[ BigNum.fromInt 1_000_000_000 ]
tokenNameAscii :: String
tokenNameAscii = "CTLNFT"
in
sameWallets distribution do
group "SameWallets" do
test "Alice mints some tokens" \(alice /\ _) -> do
tn <- Helpers.mkAssetName tokenNameAscii
withKeyWallet alice $ void $ alwaysMint tn
test "Alice sends a token to Bob" \(alice /\ bob) -> do
bobPKH <- withKeyWallet bob do
liftedM "Failed to get Bob's PKH"
$ Array.head
<$> ownPaymentPubKeyHashes
withKeyWallet alice do
mp <- alwaysMintsPolicy
let cs = PlutusScript.hash mp
tn <- Helpers.mkAssetName tokenNameAscii
pkh2pkh bobPKH $ Value.singleton cs tn BigNum.one
alwaysMint :: TokenName -> Contract Unit
alwaysMint tn = do
mp <- alwaysMintsPolicy
let
cs = PlutusScript.hash mp
constraints :: Constraints.TxConstraints
constraints = Constraints.mustMintValue
$ Mint.singleton cs tn
$ Int.fromInt 100
lookups :: Lookups.ScriptLookups
lookups = Lookups.plutusMintingPolicy mp
submitTxFromConstraints lookups constraints
>>= awaitTxConfirmed
pkh2pkh :: PaymentPubKeyHash -> Value -> Contract Unit
pkh2pkh recipient val = do
pkh <-
liftedM "Failed to get own PKH"
$ Array.head
<$> ownPaymentPubKeyHashes
let
constraints :: Constraints.TxConstraints
constraints = Constraints.mustPayToPubKey recipient val
lookups :: Lookups.ScriptLookups
lookups = Lookups.ownPaymentPubKeyHash pkh
submitTxFromConstraints lookups constraints
>>= awaitTxConfirmed