-
Notifications
You must be signed in to change notification settings - Fork 155
/
MultiAssets.hs
677 lines (579 loc) · 19.2 KB
/
MultiAssets.hs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
{-# LANGUAGE TypeApplications #-}
-- |
-- Module : Test.Cardano.Ledger.Mary.Examples.MultiAssets
-- Description : Multi-Assets Examples
--
-- Examples demonstrating the use of multi-assets.
module Test.Cardano.Ledger.Mary.Examples.MultiAssets
( multiAssetsExample,
)
where
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Keys (KeyPair (..), asWitness, hashKey)
import Cardano.Ledger.Mary (MaryEra)
import Cardano.Ledger.Mary.Value
( AssetName (..),
PolicyID (..),
Value (..),
)
import Cardano.Ledger.SafeHash (hashAnnotated)
import Cardano.Ledger.Shelley.API (LEDGER, LedgerEnv (..))
import Cardano.Ledger.Shelley.LedgerState (AccountState (..))
import Cardano.Ledger.Shelley.PParams (PParams, PParams' (..), emptyPParams)
import Cardano.Ledger.Shelley.Rules.Ledger (LedgerPredicateFailure (..))
import Cardano.Ledger.Shelley.Rules.Utxow (UtxowPredicateFailure (..))
import Cardano.Ledger.Shelley.Tx
( Tx (..),
WitnessSetHKD (..),
hashScript,
)
import Cardano.Ledger.Shelley.TxBody (TxOut (..), Wdrl (..))
import Cardano.Ledger.Shelley.UTxO (UTxO (..), makeWitnessesVKey)
import Cardano.Ledger.ShelleyMA.Rules.Utxo (UtxoPredicateFailure (..))
import Cardano.Ledger.ShelleyMA.Timelocks (Timelock (..), ValidityInterval (..))
import Cardano.Ledger.ShelleyMA.TxBody (TxBody (..))
import Cardano.Ledger.Slot (SlotNo (..))
import Cardano.Ledger.TxIn (TxId, TxIn (..), txid)
import Cardano.Ledger.Val ((<+>), (<->))
import qualified Cardano.Ledger.Val as Val
import Control.Exception (ErrorCall (ErrorCall), evaluate, try)
import Control.State.Transition.Extended (PredicateFailure)
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map.Strict as Map
import qualified Data.Sequence.Strict as StrictSeq
import qualified Data.Set as Set
import Test.Cardano.Ledger.EraBuffet (TestCrypto)
import Test.Cardano.Ledger.Mary.Examples (testMaryNoDelegLEDGER)
import qualified Test.Cardano.Ledger.Mary.Examples.Cast as Cast
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (Assertion, assertFailure, testCase)
type MaryTest = MaryEra TestCrypto
------------------------------
-- Set Up the Initial State --
------------------------------
aliceInitCoin :: Coin
aliceInitCoin = Coin $ 10 * 1000 * 1000 * 1000 * 1000 * 1000
bobInitCoin :: Coin
bobInitCoin = Coin $ 1 * 1000 * 1000 * 1000 * 1000 * 1000
unboundedInterval :: ValidityInterval
unboundedInterval = ValidityInterval SNothing SNothing
bootstrapTxId :: TxId TestCrypto
bootstrapTxId = txid txb
where
txb :: TxBody MaryTest
txb =
TxBody
Set.empty
StrictSeq.empty
StrictSeq.empty
(Wdrl Map.empty)
(Coin 0)
unboundedInterval
SNothing
SNothing
(Val.inject (Coin 0))
initUTxO :: UTxO MaryTest
initUTxO =
UTxO $
Map.fromList
[ (TxIn bootstrapTxId 0, TxOut Cast.aliceAddr (Val.inject aliceInitCoin)),
(TxIn bootstrapTxId 1, TxOut Cast.bobAddr (Val.inject bobInitCoin))
]
pp :: PParams MaryTest
pp =
emptyPParams
{ _minfeeA = 0,
_minfeeB = 1,
_maxTxSize = 16384,
_minUTxOValue = Coin 100
}
ledgerEnv :: SlotNo -> LedgerEnv MaryTest
ledgerEnv s = LedgerEnv s 0 pp (AccountState (Coin 0) (Coin 0))
feeEx :: Coin
feeEx = Coin 3
-- These examples do not use several of the transaction components,
-- so we can simplify building them.
makeTxb ::
[TxIn TestCrypto] ->
[TxOut MaryTest] ->
ValidityInterval ->
Value TestCrypto ->
TxBody MaryTest
makeTxb ins outs interval minted =
TxBody
(Set.fromList ins)
(StrictSeq.fromList outs)
StrictSeq.empty
(Wdrl Map.empty)
feeEx
interval
SNothing
SNothing
minted
policyFailure :: PolicyID TestCrypto -> Either [PredicateFailure (LEDGER MaryTest)] (UTxO MaryTest)
policyFailure p =
Left
[ UtxowFailure
(ScriptWitnessNotValidatingUTXOW (Set.singleton (policyID p)))
]
outTooBigFailure :: TxOut MaryTest -> Either [PredicateFailure (LEDGER MaryTest)] (UTxO MaryTest)
outTooBigFailure out = Left [UtxowFailure (UtxoFailure (OutputTooBigUTxO [out]))]
----------------------------------------------------
-- Introduce a new Token Bundle, Purple Tokens
--
-- Variables ending with SimpleExN (for a numeral N)
-- refer to this example.
----------------------------------------------------
-- This is the most lax policy possible, requiring no authorization at all.
purplePolicy :: Timelock TestCrypto
purplePolicy = RequireAllOf (StrictSeq.fromList [])
purplePolicyId :: PolicyID TestCrypto
purplePolicyId = PolicyID $ hashScript @MaryTest purplePolicy
plum :: AssetName
plum = AssetName $ BS.pack "plum"
amethyst :: AssetName
amethyst = AssetName $ BS.pack "amethyst"
------------------------
-- Mint Purple Tokens --
------------------------
mintSimpleEx1 :: Value TestCrypto
mintSimpleEx1 =
Value 0 $
Map.singleton purplePolicyId (Map.fromList [(plum, 13), (amethyst, 2)])
aliceCoinSimpleEx1 :: Coin
aliceCoinSimpleEx1 = aliceInitCoin <-> feeEx
tokensSimpleEx1 :: Value TestCrypto
tokensSimpleEx1 = mintSimpleEx1 <+> Val.inject aliceCoinSimpleEx1
-- Mint a purple token bundle, consisting of thirteen plums and two amethysts.
-- Give the bundle to Alice.
txbodySimpleEx1 :: TxBody MaryTest
txbodySimpleEx1 =
makeTxb
[TxIn bootstrapTxId 0]
[TxOut Cast.aliceAddr tokensSimpleEx1]
unboundedInterval
mintSimpleEx1
txSimpleEx1 :: Tx MaryTest
txSimpleEx1 =
Tx
txbodySimpleEx1
mempty
{ addrWits = makeWitnessesVKey (hashAnnotated txbodySimpleEx1) [asWitness Cast.alicePay],
scriptWits = Map.fromList [(policyID purplePolicyId, purplePolicy)]
}
SNothing
expectedUTxOSimpleEx1 :: UTxO MaryTest
expectedUTxOSimpleEx1 =
UTxO $
Map.fromList
[ (TxIn (txid txbodySimpleEx1) 0, TxOut Cast.aliceAddr tokensSimpleEx1),
(TxIn bootstrapTxId 1, TxOut Cast.bobAddr (Val.inject bobInitCoin))
]
----------------------------
-- Transfer Purple Tokens --
----------------------------
minUtxoSimpleEx2 :: Coin
minUtxoSimpleEx2 = Coin 115
aliceCoinsSimpleEx2 :: Coin
aliceCoinsSimpleEx2 = aliceCoinSimpleEx1 <-> (feeEx <+> minUtxoSimpleEx2)
aliceTokensSimpleEx2 :: Value TestCrypto
aliceTokensSimpleEx2 =
Value (unCoin aliceCoinsSimpleEx2) $
Map.singleton purplePolicyId (Map.fromList [(plum, 8), (amethyst, 2)])
bobTokensSimpleEx2 :: Value TestCrypto
bobTokensSimpleEx2 =
Value (unCoin minUtxoSimpleEx2) $
Map.singleton purplePolicyId (Map.singleton plum 5)
-- Alice gives five plums to Bob.
txbodySimpleEx2 :: TxBody MaryTest
txbodySimpleEx2 =
makeTxb
[TxIn (txid txbodySimpleEx1) 0]
[ TxOut Cast.aliceAddr aliceTokensSimpleEx2,
TxOut Cast.bobAddr bobTokensSimpleEx2
]
unboundedInterval
Val.zero
txSimpleEx2 :: Tx MaryTest
txSimpleEx2 =
Tx
txbodySimpleEx2
mempty {addrWits = makeWitnessesVKey (hashAnnotated txbodySimpleEx2) [asWitness Cast.alicePay]}
SNothing
expectedUTxOSimpleEx2 :: UTxO MaryTest
expectedUTxOSimpleEx2 =
UTxO $
Map.fromList
[ (TxIn (txid txbodySimpleEx2) 0, TxOut Cast.aliceAddr aliceTokensSimpleEx2),
(TxIn (txid txbodySimpleEx2) 1, TxOut Cast.bobAddr bobTokensSimpleEx2),
(TxIn bootstrapTxId 1, TxOut Cast.bobAddr (Val.inject bobInitCoin))
]
------------------------------------------------------------
-- Introduce a new Token Bundle, Tokens With a Time Range
--
-- Variables ending with TimeExN (for a numeral N)
-- refer to this example.
------------------------------------------------------------
beforeStart :: SlotNo
beforeStart = SlotNo 12
startInterval :: SlotNo
startInterval = SlotNo 13
stopInterval :: SlotNo
stopInterval = SlotNo 19
afterStop :: SlotNo
afterStop = SlotNo 20
boundedTimePolicy :: Timelock TestCrypto
boundedTimePolicy =
RequireAllOf
( StrictSeq.fromList
[ RequireTimeStart startInterval,
RequireTimeExpire stopInterval
]
)
boundedTimePolicyId :: PolicyID TestCrypto
boundedTimePolicyId = PolicyID $ hashScript @MaryTest boundedTimePolicy
tokenTimeEx :: AssetName
tokenTimeEx = AssetName $ BS.pack "tokenTimeEx"
------------------------------------
-- Mint Bounded Time Range Tokens --
------------------------------------
mintTimeEx1 :: Value TestCrypto
mintTimeEx1 =
Value 0 $
Map.singleton boundedTimePolicyId (Map.singleton tokenTimeEx 1)
aliceCoinsTimeEx1 :: Coin
aliceCoinsTimeEx1 = aliceInitCoin <-> feeEx
tokensTimeEx1 :: Value TestCrypto
tokensTimeEx1 = mintTimeEx1 <+> Val.inject aliceCoinsTimeEx1
-- Mint tokens
txbodyTimeEx1 :: StrictMaybe SlotNo -> StrictMaybe SlotNo -> TxBody MaryTest
txbodyTimeEx1 s e =
makeTxb
[TxIn bootstrapTxId 0]
[TxOut Cast.aliceAddr tokensTimeEx1]
(ValidityInterval s e)
mintTimeEx1
txbodyTimeEx1Valid :: TxBody MaryTest
txbodyTimeEx1Valid = txbodyTimeEx1 (SJust startInterval) (SJust stopInterval)
txTimeEx1 :: TxBody MaryTest -> Tx MaryTest
txTimeEx1 txbody =
Tx
txbody
mempty
{ addrWits = makeWitnessesVKey (hashAnnotated txbody) [asWitness Cast.alicePay],
scriptWits = Map.fromList [(policyID boundedTimePolicyId, boundedTimePolicy)]
}
SNothing
txTimeEx1Valid :: Tx MaryTest
txTimeEx1Valid = txTimeEx1 txbodyTimeEx1Valid
txTimeEx1InvalidLHSfixed :: Tx MaryTest
txTimeEx1InvalidLHSfixed = txTimeEx1 $ txbodyTimeEx1 (SJust beforeStart) (SJust stopInterval)
txTimeEx1InvalidLHSopen :: Tx MaryTest
txTimeEx1InvalidLHSopen = txTimeEx1 $ txbodyTimeEx1 SNothing (SJust stopInterval)
txTimeEx1InvalidRHSfixed :: Tx MaryTest
txTimeEx1InvalidRHSfixed = txTimeEx1 $ txbodyTimeEx1 (SJust startInterval) (SJust afterStop)
txTimeEx1InvalidRHSopen :: Tx MaryTest
txTimeEx1InvalidRHSopen = txTimeEx1 $ txbodyTimeEx1 (SJust startInterval) SNothing
expectedUTxOTimeEx1 :: UTxO MaryTest
expectedUTxOTimeEx1 =
UTxO $
Map.fromList
[ (TxIn (txid txbodyTimeEx1Valid) 0, TxOut Cast.aliceAddr tokensTimeEx1),
(TxIn bootstrapTxId 1, TxOut Cast.bobAddr (Val.inject bobInitCoin))
]
----------------------------------------
-- Transfer Bounded Time Range Tokens --
----------------------------------------
mintTimeEx2 :: Coin
mintTimeEx2 = Coin 120
bobTokensTimeEx2 :: Value TestCrypto
bobTokensTimeEx2 =
Value (unCoin mintTimeEx2) $
Map.singleton boundedTimePolicyId (Map.singleton tokenTimeEx 1)
aliceCoinsTimeEx2 :: Coin
aliceCoinsTimeEx2 = aliceCoinSimpleEx1 <-> (feeEx <+> mintTimeEx2)
-- Alice gives one token to Bob
txbodyTimeEx2 :: TxBody MaryTest
txbodyTimeEx2 =
makeTxb
[TxIn (txid txbodyTimeEx1Valid) 0]
[ TxOut Cast.aliceAddr (Val.inject aliceCoinsTimeEx2),
TxOut Cast.bobAddr bobTokensTimeEx2
]
unboundedInterval
Val.zero
txTimeEx2 :: Tx MaryTest
txTimeEx2 =
Tx
txbodyTimeEx2
mempty
{ addrWits =
makeWitnessesVKey (hashAnnotated txbodyTimeEx2) [asWitness Cast.alicePay]
}
SNothing
expectedUTxOTimeEx2 :: UTxO MaryTest
expectedUTxOTimeEx2 =
UTxO $
Map.fromList
[ (TxIn (txid txbodyTimeEx2) 0, TxOut Cast.aliceAddr (Val.inject aliceCoinsTimeEx2)),
(TxIn (txid txbodyTimeEx2) 1, TxOut Cast.bobAddr bobTokensTimeEx2),
(TxIn bootstrapTxId 1, TxOut Cast.bobAddr (Val.inject bobInitCoin))
]
--------------------------------------------------------------
-- Introduce a new Token Bundle, Tokens only Alice can mint
--
-- Variables ending with SingExN (for a numeral N)
-- refer to this example.
--------------------------------------------------------------
alicePolicy :: Timelock TestCrypto
alicePolicy = RequireSignature . asWitness . hashKey . vKey $ Cast.alicePay
alicePolicyId :: PolicyID TestCrypto
alicePolicyId = PolicyID $ hashScript @MaryTest alicePolicy
tokenSingWitEx1 :: AssetName
tokenSingWitEx1 = AssetName $ BS.pack "tokenSingWitEx1"
-----------------------
-- Mint Alice Tokens --
-----------------------
mintSingWitEx1 :: Value TestCrypto
mintSingWitEx1 =
Value 0 $
Map.singleton alicePolicyId (Map.singleton tokenSingWitEx1 17)
bobCoinsSingWitEx1 :: Coin
bobCoinsSingWitEx1 = bobInitCoin <-> feeEx
tokensSingWitEx1 :: Value TestCrypto
tokensSingWitEx1 = mintSingWitEx1 <+> Val.inject bobCoinsSingWitEx1
-- Bob pays the fees, but only alice can witness the minting
txbodySingWitEx1 :: TxBody MaryTest
txbodySingWitEx1 =
makeTxb
[TxIn bootstrapTxId 1]
[TxOut Cast.bobAddr tokensSingWitEx1]
unboundedInterval
mintSingWitEx1
txSingWitEx1Valid :: Tx MaryTest
txSingWitEx1Valid =
Tx
txbodySingWitEx1
mempty
{ addrWits =
makeWitnessesVKey (hashAnnotated txbodySingWitEx1) [asWitness Cast.bobPay, asWitness Cast.alicePay],
scriptWits = Map.fromList [(policyID alicePolicyId, alicePolicy)]
}
SNothing
expectedUTxOSingWitEx1 :: UTxO MaryTest
expectedUTxOSingWitEx1 =
UTxO $
Map.fromList
[ (TxIn (txid txbodySingWitEx1) 0, TxOut Cast.bobAddr tokensSingWitEx1),
(TxIn bootstrapTxId 0, TxOut Cast.aliceAddr (Val.inject aliceInitCoin))
]
txSingWitEx1Invalid :: Tx MaryTest
txSingWitEx1Invalid =
Tx
txbodySingWitEx1
mempty
{ addrWits = makeWitnessesVKey (hashAnnotated txbodySingWitEx1) [asWitness Cast.bobPay],
scriptWits = Map.fromList [(policyID alicePolicyId, alicePolicy)]
}
SNothing
------------------------
-- Mint Negative Values
--
-- Variables ending with NegExN (for a numeral N)
-- refer to this example. We assume that the simple
-- tokens in the SimpleEx1 example have been minted
-- and we use expectedUTxOSimpleEx1 as our starting
-- state.
------------------------
-- Mint negative valued tokens
mintNegEx1 :: Value TestCrypto
mintNegEx1 =
Value 0 $
Map.singleton purplePolicyId (Map.singleton plum (-8))
aliceTokensNegEx1 :: Value TestCrypto
aliceTokensNegEx1 =
Value (unCoin $ aliceCoinsSimpleEx2 <-> feeEx) $
Map.singleton purplePolicyId (Map.singleton amethyst 2)
txbodyNegEx1 :: TxBody MaryTest
txbodyNegEx1 =
makeTxb
[TxIn (txid txbodySimpleEx2) 0]
[TxOut Cast.aliceAddr aliceTokensNegEx1]
unboundedInterval
mintNegEx1
txNegEx1 :: Tx MaryTest
txNegEx1 =
Tx
txbodyNegEx1
mempty
{ addrWits = makeWitnessesVKey (hashAnnotated txbodyNegEx1) [asWitness Cast.alicePay],
scriptWits = Map.fromList [(policyID purplePolicyId, purplePolicy)]
}
SNothing
initialUTxONegEx1 :: UTxO MaryTest
initialUTxONegEx1 = expectedUTxOSimpleEx2
expectedUTxONegEx1 :: UTxO MaryTest
expectedUTxONegEx1 =
UTxO $
Map.fromList
[ (TxIn (txid txbodyNegEx1) 0, TxOut Cast.aliceAddr aliceTokensNegEx1),
(TxIn bootstrapTxId 1, TxOut Cast.bobAddr (Val.inject bobInitCoin)),
(TxIn (txid txbodySimpleEx2) 1, TxOut Cast.bobAddr bobTokensSimpleEx2)
]
--
-- Now attempt to produce negative outputs
--
mintNegEx2 :: Value TestCrypto
mintNegEx2 =
Value 0 $
Map.singleton purplePolicyId (Map.singleton plum (-9))
aliceTokensNegEx2 :: Value TestCrypto
aliceTokensNegEx2 =
Value (unCoin $ aliceCoinsSimpleEx2 <-> feeEx) $
Map.singleton purplePolicyId (Map.fromList [(plum, -1), (amethyst, 2)])
-- Mint negative valued tokens
txbodyNegEx2 :: TxBody MaryTest
txbodyNegEx2 =
makeTxb
[TxIn (txid txbodySimpleEx2) 0]
[TxOut Cast.aliceAddr aliceTokensNegEx2]
unboundedInterval
mintNegEx2
testNegEx2 :: Assertion
testNegEx2 = do
r <- try (evaluate $ txbodyNegEx2 == txbodyNegEx2)
case r of
Left (ErrorCall _) -> pure ()
Right _ -> assertFailure "constructed negative TxOut Value"
--
-- Create a Value that is too big
--
minUtxoBigEx :: Coin
minUtxoBigEx = Coin 50000
smallValue :: Value TestCrypto
smallValue =
Value 0 $
Map.singleton purplePolicyId (Map.fromList [(plum, 13), (amethyst, 2)])
smallOut :: TxOut MaryTest
smallOut =
TxOut Cast.aliceAddr $ smallValue <+> Val.inject (aliceInitCoin <-> (feeEx <+> minUtxoBigEx))
numAssets :: Int
numAssets = 1000
bigValue :: Value TestCrypto
bigValue =
Value 0 $
Map.singleton
purplePolicyId
(Map.fromList $ map (\x -> (AssetName . BS.pack $ show x, 1)) [1 .. numAssets])
bigOut :: TxOut MaryTest
bigOut = TxOut Cast.aliceAddr $ bigValue <+> Val.inject minUtxoBigEx
txbodyWithBigValue :: TxBody MaryTest
txbodyWithBigValue =
makeTxb
[TxIn bootstrapTxId 0]
[smallOut, bigOut]
unboundedInterval
(bigValue <+> smallValue)
txBigValue :: Tx MaryTest
txBigValue =
Tx
txbodyWithBigValue
mempty
{ addrWits = makeWitnessesVKey (hashAnnotated txbodyWithBigValue) [asWitness Cast.alicePay],
scriptWits = Map.fromList [(policyID purplePolicyId, purplePolicy)]
}
SNothing
--
-- Multi-Assets Test Group
--
multiAssetsExample :: TestTree
multiAssetsExample =
testGroup
"multi-assets"
[ testGroup
"simple"
[ testCase "minting" $
testMaryNoDelegLEDGER
initUTxO
txSimpleEx1
(ledgerEnv $ SlotNo 0)
(Right expectedUTxOSimpleEx1),
testCase "transfer" $
testMaryNoDelegLEDGER
expectedUTxOSimpleEx1
txSimpleEx2
(ledgerEnv $ SlotNo 1)
(Right expectedUTxOSimpleEx2)
],
testGroup
"bounded time interval"
[ testCase "minting, valid" $
testMaryNoDelegLEDGER
initUTxO
txTimeEx1Valid
(ledgerEnv startInterval)
(Right expectedUTxOTimeEx1),
testCase "minting, invalid LHS too small" $
testMaryNoDelegLEDGER
initUTxO
txTimeEx1InvalidLHSfixed
(ledgerEnv startInterval)
(policyFailure boundedTimePolicyId),
testCase "minting, invalid LHS unspecified" $
testMaryNoDelegLEDGER
initUTxO
txTimeEx1InvalidLHSopen
(ledgerEnv startInterval)
(policyFailure boundedTimePolicyId),
testCase "minting, invalid RHS too big" $
testMaryNoDelegLEDGER
initUTxO
txTimeEx1InvalidRHSfixed
(ledgerEnv startInterval)
(policyFailure boundedTimePolicyId),
testCase "minting, invalid RHS unspecified" $
testMaryNoDelegLEDGER
initUTxO
txTimeEx1InvalidRHSopen
(ledgerEnv startInterval)
(policyFailure boundedTimePolicyId),
testCase "transfer, after minting period" $
testMaryNoDelegLEDGER
expectedUTxOTimeEx1
txTimeEx2
(ledgerEnv afterStop)
(Right expectedUTxOTimeEx2)
],
testGroup
"single key"
[ testCase "minting, valid" $
testMaryNoDelegLEDGER
initUTxO
txSingWitEx1Valid
(ledgerEnv $ SlotNo 0)
(Right expectedUTxOSingWitEx1),
testCase "minting, invalid no mint signature" $
testMaryNoDelegLEDGER
initUTxO
txSingWitEx1Invalid
(ledgerEnv $ SlotNo 0)
(policyFailure alicePolicyId)
],
testGroup
"negative minting"
[ testCase "remove assets" $
testMaryNoDelegLEDGER
initialUTxONegEx1
txNegEx1
(ledgerEnv $ SlotNo 3)
(Right expectedUTxONegEx1),
testCase "no negative outputs" testNegEx2
],
testCase "value too big" $
testMaryNoDelegLEDGER
initUTxO
txBigValue
(ledgerEnv $ SlotNo 0)
(outTooBigFailure bigOut)
]