-
Notifications
You must be signed in to change notification settings - Fork 1
/
extended_cmtat_single_asset.test.mligo
1749 lines (1522 loc) · 81 KB
/
extended_cmtat_single_asset.test.mligo
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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import "extended_cmtat_single_asset.instance.mligo" "CMTAT_single_asset"
#import "../helpers/list.mligo" "List_helper"
#import "../helpers/totalsupply_view_caller_contract.mligo" "Caller"
#import "../helpers/isoperator_view_caller_contract.mligo" "Caller_ISOPERATOR"
#import "../helpers/tokenmetadata_view_caller_contract.mligo" "Caller_TOKENMETADATA"
#import "../helpers/getnextsnapshots_view_caller_contract.mligo" "Caller_GETNEXTSNAPSHOTS"
#import "../helpers/snapshottotalsupply_view_caller_contract.mligo" "Caller_SNAPSHOTTOTALSUPPLY"
#import "../helpers/snapshotbalanceof_view_caller_contract.mligo" "Caller_SNAPSHOTBALANCEOF"
#import "../helpers/rule_engine_bl_contract.mligo" "RULE_ENGINE_BLACKLIST"
#import "../helpers/rule_engine_wl_contract.mligo" "RULE_ENGINE_WHITELIST"
module TZIP12 = CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET_EXTENDABLE.TZIP12
let get_initial_storage_ (a, b, c : nat * nat * nat) =
let owner1 = Test.nth_bootstrap_account 0 in
let owner2 = Test.nth_bootstrap_account 1 in
let owner3 = Test.nth_bootstrap_account 2 in
let owners = [owner1; owner2; owner3] in
let op1 = Test.nth_bootstrap_account 3 in
let op2 = Test.nth_bootstrap_account 4 in
let op3 = Test.nth_bootstrap_account 5 in
let ops = [op1; op2; op3] in
let ledger = Big_map.literal ([
(owner1, a);
(owner2, b);
(owner3, c);
])
in
let operators = Big_map.literal ([
(owner1, Set.literal [op1]);
(owner2, Set.literal [op1;op2]);
(owner3, Set.literal [op1;op3]);
(op3 , Set.literal [op1;op2]);
])
in
let token_info = (Map.empty: (string, bytes) map) in
let token_data = {
token_id = 0n;
token_info = token_info;
} in
let token_metadata = Big_map.literal ([
(0n, token_data);
])
in
let metadata =Big_map.literal [
("", [%bytes {|tezos-storage:data|}]);
("data", [%bytes
{|{
"name":"FA2",
"description":"Example FA2 implementation",
"version":"0.1.0",
"license":{"name":"MIT"},
"authors":["Benjamin Fuentes<[email protected]>"],
"homepage":"",
"source":{"tools":["Ligo"], "location":"https://github.com/ligolang/contract-catalogue/tree/main/lib/fa2"},
"interfaces":["TZIP-012"],
"errors":[],
"views":[]
}|}]);
] in
let initial_storage: CMTAT_single_asset.storage = {
ledger = ledger;
metadata = metadata;
token_metadata = token_metadata;
operators = operators;
administration = { admin = op1; paused = false; killed = false };
totalsupplies = a + b + c;
authorizations = Big_map.empty;
snapshots = {
account_snapshots = Big_map.empty;
totalsupply_snapshots = Big_map.empty;
scheduled_snapshots = ([] : timestamp list)
};
validation = {
rule_engine_contract = (None: address option)
};
extension = {
issuer = op2;
}
} in
initial_storage, owners, ops
let get_initial_storage (a, b, c : nat * nat * nat) =
let () = Test.reset_state 6n ([] : tez list) in
get_initial_storage_ (a,b,c)
let get_initial_storage_at (time: timestamp) (a, b, c : nat * nat * nat) =
let () = Test.reset_state_at time 6n ([] : tez list) in
get_initial_storage_ (a,b,c)
let assert_balances
(contract_address : (CMTAT_single_asset parameter_of, CMTAT_single_asset.storage) typed_address )
(a, b, c : (address * nat) * (address * nat) * (address * nat)) =
let (owner1, balance1) = a in
let (owner2, balance2) = b in
let (owner3, balance3) = c in
let storage = Test.get_storage contract_address in
let ledger = storage.ledger in
let () = match (Big_map.find_opt owner1 ledger) with
Some amt -> assert (amt = balance1)
| None -> failwith "incorret address"
in
let () = match (Big_map.find_opt owner2 ledger) with
Some amt -> assert (amt = balance2)
| None -> failwith "incorret address"
in
let () = match (Big_map.find_opt owner3 ledger) with
Some amt -> assert (amt = balance3)
| None -> failwith "incorret address"
in
()
let assert_no_balances
(contract_address : (CMTAT_single_asset parameter_of, CMTAT_single_asset.storage) typed_address )
(a, b, c : address * address * address) =
let storage = Test.get_storage contract_address in
let ledger = storage.ledger in
let () = match (Big_map.find_opt a ledger) with
Some _amt -> failwith "Should not have balance"
| None -> ()
in
let () = match (Big_map.find_opt b ledger) with
Some _amt -> failwith "Should not have balance"
| None -> ()
in
let () = match (Big_map.find_opt c ledger) with
Some _amt -> failwith "Should not have balance"
| None -> ()
in
()
let assert_paused
(contract_address : (CMTAT_single_asset parameter_of, CMTAT_single_asset.storage) typed_address )
(expected : bool) =
let storage = Test.get_storage contract_address in
let administration = storage.administration in
assert (administration.paused = expected)
let assert_totalsupply
(contract_address : (CMTAT_single_asset parameter_of, CMTAT_single_asset.storage) typed_address )
(expected : nat) =
let storage = Test.get_storage contract_address in
let actual = storage.totalsupplies in
assert (actual = expected)
let assert_role
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(user : address)
(expected_role: CMTAT_single_asset.Token.AUTHORIZATIONS.role) =
let storage = Test.get_storage contract_address in
match Big_map.find_opt user storage.authorizations with
| Some(flags) -> assert (Set.mem expected_role flags)
| None -> failwith "[assert_role] Unknown user"
let assert_not_role
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(user : address)
(expected_role: CMTAT_single_asset.Token.AUTHORIZATIONS.role) =
let storage = Test.get_storage contract_address in
match Big_map.find_opt user storage.authorizations with
| Some(flags) -> assert (not (Set.mem expected_role flags))
| None -> failwith "[assert_not_role] Unknown user"
let assert_no_role
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(user : address) =
let storage = Test.get_storage contract_address in
match Big_map.find_opt user storage.authorizations with
| Some(_flags) -> failwith "[assert_no_role] User should not have role"
| None -> ()
let assert_account_snapshot
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(time: timestamp)
(a, b, c : (address * nat) * (address * nat) * (address * nat)) =
let storage = Test.get_storage contract_address in
let () = match Big_map.find_opt (a.0, time) storage.snapshots.account_snapshots with
| Some (v) -> assert(a.1 = v)
| None -> failwith "[assert_account_snapshot] user 1 has no snapshot"
in
let () = match Big_map.find_opt (b.0, time) storage.snapshots.account_snapshots with
| Some (v) -> assert(b.1 = v)
| None -> failwith "[assert_account_snapshot] user 2 has no snapshot"
in
let () = match Big_map.find_opt (c.0, time) storage.snapshots.account_snapshots with
| Some (v) -> assert(c.1 = v)
| None -> failwith "[assert_account_snapshot] user 3 has no snapshot"
in
()
let assert_totalsupply_snapshot
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(time: timestamp)
(expected: nat) =
let storage = Test.get_storage contract_address in
let () = match Big_map.find_opt time storage.snapshots.totalsupply_snapshots with
| Some (v) -> assert(expected = v)
| None -> failwith "No total supply snapshot for this time"
in
()
let assert_scheduled_snapshot
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(time: timestamp) =
let storage = Test.get_storage contract_address in
let () = assert (List_helper.contains time storage.snapshots.scheduled_snapshots)
in
()
let assert_no_scheduled_snapshot
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(time: timestamp) =
let storage = Test.get_storage contract_address in
assert (not List_helper.contains time storage.snapshots.scheduled_snapshots)
let assert_scheduled_snapshots_contains
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(times: timestamp list) =
let storage = Test.get_storage contract_address in
let contains_one (time: timestamp) = assert (List_helper.contains time storage.snapshots.scheduled_snapshots) in
List.iter contains_one times
// Verify that scheduled_snapshot is ordered
let check_invariant_scheduled_snapshot
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
=
let storage = Test.get_storage contract_address in
match storage.snapshots.scheduled_snapshots with
| [] -> ()
| [_] -> ()
| _::tl ->
let merged = List_helper.zip(storage.snapshots.scheduled_snapshots, tl) in
List.iter (fun(a, b: timestamp * timestamp) -> assert(a > b)) merged
let assert_rule_engine
(contract_address : ((CMTAT_single_asset parameter_of), CMTAT_single_asset.storage) typed_address )
(expected: address option) =
let storage = Test.get_storage contract_address in
assert (storage.validation.rule_engine_contract = expected)
(* Assert contract call results in failwith with given string *)
let string_failure (res : test_exec_result) (expected : string) : unit =
let expected = Test.eval expected in
match res with
| Fail (Rejected (actual,_)) -> assert (actual = expected)
| Fail (Balance_too_low _err) -> Test.failwith "contract failed: balance too low"
| Fail (Other s) -> Test.failwith s
| Success _ -> Test.failwith "Transaction should fail"
/////////////////////////////////////////////////////////////////////////////////////////////////////
// ORIGINATION
/////////////////////////////////////////////////////////////////////////////////////////////////////
let test_origination_success =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let () = assert_balances orig.addr ((owner1, 10n), (owner2, 10n), (owner3, 10n)) in
let () = assert_totalsupply orig.addr 30n in
()
//////////////////////////////////////////////////////////////////////////////////////////////
// KILL
//////////////////////////////////////////////////////////////////////////////////////////////
let test_kill_success_with_admin =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// KILL
let _ = Test.transfer_exn orig.addr (Kill ()) 0tez in
let () = assert_paused orig.addr true in
let () = assert_no_balances orig.addr (owner1, owner2, owner3) in
let () = assert_totalsupply orig.addr 0n in
let () = assert_rule_engine orig.addr (None: address option) in
let storage = Test.get_storage orig.addr in
let () = assert (storage.snapshots.scheduled_snapshots = ([]: timestamp list)) in
// let () = assert_no_account_snapshot orig.addr (owner1, owner2, owner3) in
// PAUSE
// Special case: due to override, it is possible to Unpause the contract despite the fact that the contract is killed
let _r = Test.transfer orig.addr (Pause false) 0tez in
let () = assert_paused orig.addr false in
// GRANT ROLE - fails
let flag_snapshooter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = SNAPSHOOTER in
let r = Test.transfer orig.addr (GrantRole (owner1, flag_snapshooter)) 0tez in
let () = string_failure r CMTAT_single_asset.Token.ADMINISTRATION.Errors.contract_killed in
// TRANSFER - fails
let transfer_requests = ([
({from_=owner1; txs=([{to_=owner2;token_id=0n;amount=2n};{to_=owner3;token_id=0n;amount=3n}] : TZIP12.atomic_trans list)});
({from_=owner2; txs=([{to_=owner3;token_id=0n;amount=2n};{to_=owner1;token_id=0n;amount=3n}] : TZIP12.atomic_trans list)});
] : TZIP12.transfer)
in
let r = Test.transfer orig.addr (Transfer transfer_requests) 0tez in
let () = string_failure r CMTAT_single_asset.Token.ADMINISTRATION.Errors.contract_killed in
()
let test_kill_failure_not_admin =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let () = Test.set_source owner1 in
// KILL - fails
let r = Test.transfer orig.addr (Kill ()) 0tez in
let () = string_failure r CMTAT_single_asset.Token.ADMINISTRATION.Errors.not_admin in
let () = Test.set_source initial_storage.administration.admin in
// GRANT ROLE
let flag_snapshooter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = SNAPSHOOTER in
let _r = Test.transfer_exn orig.addr (GrantRole (owner1, flag_snapshooter)) 0tez in
// GRANT ROLE
let flag_ruler : CMTAT_single_asset.Token.AUTHORIZATIONS.role = RULER in
let _r = Test.transfer_exn orig.addr (GrantRole (owner1, flag_ruler)) 0tez in
// GRANT ROLE
let flag_validator : CMTAT_single_asset.Token.AUTHORIZATIONS.role = VALIDATOR in
let _r = Test.transfer_exn orig.addr (GrantRole (owner1, flag_validator)) 0tez in
// KILL - fails
let () = Test.set_source owner1 in
let r = Test.transfer orig.addr (Kill ()) 0tez in
let () = string_failure r CMTAT_single_asset.Token.ADMINISTRATION.Errors.not_admin in
()
//////////////////////////////////////////////////////////////////////////////////////////////
// PAUSE (overide)
//////////////////////////////////////////////////////////////////////////////////////////////
let test_pause_success_with_admin =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let _ = Test.transfer_exn orig.addr (Pause true) 0tez in
let () = assert_paused orig.addr true in
()
let test_pause_success_with_issuer =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op2 = List_helper.nth_exn 1 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let () = Test.set_source op2 in
let _ = Test.transfer_exn orig.addr (Pause true) 0tez in
let () = assert_paused orig.addr true in
()
let test_pause_failure =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let _op2 = List_helper.nth_exn 1 operators in
let op3 = List_helper.nth_exn 2 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let () = Test.set_source op3 in
let r = Test.transfer orig.addr (Pause true) 0tez in
let () = string_failure r CMTAT_single_asset.Errors.not_issuer_nor_admin in
let () = assert_paused orig.addr false in
()
// verify that override works. Pauser role is not enough in this extended contract , only issuer or admin)
let test_pause_failure_with_pauser =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let _op2 = List_helper.nth_exn 1 operators in
let op3 = List_helper.nth_exn 2 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// GRANT op3 the role Pauser
let contr = Test.to_contract orig.addr in
let flag : CMTAT_single_asset.Token.AUTHORIZATIONS.role = PAUSER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (op3, flag)) 0tez in
let () = assert_role orig.addr op3 flag in
// PAUSE (by op3 fails)
let () = Test.set_source op3 in
let r = Test.transfer orig.addr (Pause true) 0tez in
let () = string_failure r CMTAT_single_asset.Errors.not_issuer_nor_admin in
let () = assert_paused orig.addr false in
()
/////////////////////////////////////////////////////////////////////////////////////////////////////
// TRANSFER
/////////////////////////////////////////////////////////////////////////////////////////////////////
let test_atomic_transfer_success =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let transfer_requests = ([
({from_=owner1; txs=([{to_=owner2;token_id=0n;amount=2n};{to_=owner3;token_id=0n;amount=3n}] : TZIP12.atomic_trans list)});
({from_=owner2; txs=([{to_=owner3;token_id=0n;amount=2n};{to_=owner1;token_id=0n;amount=3n}] : TZIP12.atomic_trans list)});
] : TZIP12.transfer)
in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let _ = Test.transfer_exn orig.addr (Transfer transfer_requests) 0tez in
let () = assert_balances orig.addr ((owner1, 8n), (owner2, 7n), (owner3, 15n)) in
()
let test_atomic_transfer_failure_in_pause =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let transfer_requests = ([
({from_=owner1; txs=([{to_=owner2;token_id=0n;amount=2n};{to_=owner3;token_id=0n;amount=3n}] : TZIP12.atomic_trans list)});
({from_=owner2; txs=([{to_=owner3;token_id=0n;amount=2n};{to_=owner1;token_id=0n;amount=3n}] : TZIP12.atomic_trans list)});
] : TZIP12.transfer)
in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let _ = Test.transfer_exn orig.addr (Pause true) 0tez in
let () = assert_paused orig.addr true in
let r = Test.transfer orig.addr (Transfer transfer_requests) 0tez in
let () = string_failure r CMTAT_single_asset.Token.ADMINISTRATION.Errors.contract_in_pause in
()
/////////////////////////////////////////////////////////////////////////////////////////////////////
// TOTALSUPPLY VIEW
/////////////////////////////////////////////////////////////////////////////////////////////////////
let test_totalsupply_view_success =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op3 = List_helper.nth_exn 2 operators in
// ORIGINATION CALLER
let () = Test.set_source op1 in
let orig_caller = Test.originate (contract_of Caller) 0n 0tez in
let contr_caller = Test.to_contract orig_caller.addr in
// ORIGINATION
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract orig.addr in
let fa2_address : address = Tezos.address contr in
// GRANT op3 the role Minter
let () = Test.set_source initial_storage.administration.admin in
let flag : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (op3, flag)) 0tez in
let () = assert_role orig.addr op3 flag in
// MINT (with minter)
let () = Test.set_source op3 in
let mint_request = ({ recipient=owner1; token_id=0n; amount=2n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.mint_param)
in
let _ = Test.transfer_exn orig.addr (Mint mint_request) 0tez in
let () = assert_balances orig.addr ((owner1, 12n), (owner2, 10n), (owner3, 10n)) in
let () = assert_totalsupply orig.addr 32n in
// Call View of Caller contract
// Caller contract calls the "totalSupply" view of CMTAT contract
let _ = Test.transfer_to_contract_exn contr_caller (Request (fa2_address,0n)) 0tez in
let storage_caller = Test.get_storage orig_caller.addr in
let () = assert(storage_caller = 32n) in
()
/////////////////////////////////////////////////////////////////////////////////////////////////////
// IS_OPERATOR VIEW
/////////////////////////////////////////////////////////////////////////////////////////////////////
let test_isoperator_view_success =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
// ORIGINATION CALLER
let () = Test.set_source op1 in
let orig_caller = Test.originate (contract_of Caller_ISOPERATOR) (None: bool option) 0tez in
let contr_caller = Test.to_contract orig_caller.addr in
// ORIGINATION
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract orig.addr in
let fa2_address : address = Tezos.address contr in
// Call View of Caller contract
// Caller contract calls the "is_opertor" view of CMTAT contract
let op_request : TZIP12.operator = { owner=owner1; operator=op1; token_id=0n } in
let _ = Test.transfer_to_contract_exn contr_caller (Request (fa2_address, op_request)) 0tez in
let storage_caller = Test.get_storage orig_caller.addr in
let () = assert(storage_caller = Some(true)) in
()
/////////////////////////////////////////////////////////////////////////////////////////////////////
// TOKEN_METADATA VIEW
/////////////////////////////////////////////////////////////////////////////////////////////////////
type tokenMetadataData = TZIP12.tokenMetadataData
let test_tokenmetadata_view_success =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
// ORIGINATION CALLER
let () = Test.set_source op1 in
let orig_caller = Test.originate (contract_of Caller_TOKENMETADATA) (None: tokenMetadataData option) 0tez in
let contr_caller = Test.to_contract orig_caller.addr in
// ORIGINATION
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract orig.addr in
let fa2_address : address = Tezos.address contr in
// Call View of Caller contract
// Caller contract calls the "is_opertor" view of CMTAT contract
let _r = Test.transfer_to_contract_exn contr_caller (Request (fa2_address, 0n)) 0tez in
let storage_caller = Test.get_storage orig_caller.addr in
match storage_caller with
| Some(data) ->
let () = assert (data.token_id=0n) in
let () = assert (data.token_info=(Map.empty : (string, bytes) map)) in
()
| None -> failwith "[Test] missing token_metadata"
/////////////////////////////////////////////////////////////////////////////////////////////////////
// MINT
/////////////////////////////////////////////////////////////////////////////////////////////////////
let test_mint_failure_with_admin =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
// ORIGINATION
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// MINT (with admin)
let () = Test.set_source initial_storage.administration.admin in
let mint_request = ({ recipient=owner1; token_id=0n; amount=2n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.mint_param)
in
let r = Test.transfer orig.addr (Mint mint_request) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.not_minter in
let () = assert_balances orig.addr ((owner1, 10n), (owner2, 10n), (owner3, 10n)) in
let () = assert_totalsupply orig.addr 30n in
()
let test_mint_success_with_minter =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op3 = List_helper.nth_exn 2 operators in
// ORIGINATION
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// GRANT op3 the role Minter
let contr = Test.to_contract orig.addr in
let flag : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (op3, flag)) 0tez in
let () = assert_role orig.addr op3 flag in
// MINT (with minter)
let () = Test.set_source op3 in
let mint_request = ({ recipient=owner1; token_id=0n; amount=2n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.mint_param)
in
let _ = Test.transfer_exn orig.addr (Mint mint_request) 0tez in
let () = assert_balances orig.addr ((owner1, 12n), (owner2, 10n), (owner3, 10n)) in
let () = assert_totalsupply orig.addr 32n in
()
let test_mint_failure_not_minter =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op3 = List_helper.nth_exn 2 operators in
// ORIGINATION
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// MINT (fails with not minter)
let () = Test.set_source op3 in
let mint_request = ({ recipient=owner1; token_id=0n; amount=2n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.mint_param)
in
let r = Test.transfer orig.addr (Mint mint_request) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.not_minter in
let () = assert_balances orig.addr ((owner1, 10n), (owner2, 10n), (owner3, 10n)) in
let () = assert_totalsupply orig.addr 30n in
()
/////////////////////////////////////////////////////////////////////////////////////////////////////
// BURN
/////////////////////////////////////////////////////////////////////////////////////////////////////
let test_burn_failure_with_admin =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// BURN (with admin)
let burn_request = ({ recipient=owner1; token_id=0n; amount=2n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.burn_param)
in
let r = Test.transfer orig.addr (Burn burn_request) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.not_burner in
let () = assert_balances orig.addr ((owner1, 10n), (owner2, 10n), (owner3, 10n)) in
let () = assert_totalsupply orig.addr 30n in
()
let test_burn_success_with_burner =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op3 = List_helper.nth_exn 2 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// GRANT op3 the role Burner
let contr = Test.to_contract orig.addr in
let flag : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (op3, flag)) 0tez in
let () = assert_role orig.addr op3 flag in
// BURN (with burner)
let () = Test.set_source op3 in
let burn_request = ({ recipient=owner1; token_id=0n; amount=2n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.burn_param)
in
let _ = Test.transfer_exn orig.addr (Burn burn_request) 0tez in
let () = assert_balances orig.addr ((owner1, 8n), (owner2, 10n), (owner3, 10n)) in
let () = assert_totalsupply orig.addr 28n in
()
let test_burn_failure_not_burner =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op3 = List_helper.nth_exn 2 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// BURN (with burner)
let () = Test.set_source op3 in
let burn_request = ({ recipient=owner1; token_id=0n; amount=2n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.burn_param)
in
let r = Test.transfer orig.addr (Burn burn_request) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.not_burner in
let () = assert_totalsupply orig.addr 30n in
()
let test_burn_failure_not_enough =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op3 = List_helper.nth_exn 2 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// GRANT op3 the role Burner
let contr = Test.to_contract orig.addr in
let flag : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (op3, flag)) 0tez in
let () = assert_role orig.addr op3 flag in
// BURN (with burner)
let () = Test.set_source op3 in
let burn_request = ({ recipient=owner1; token_id=0n; amount=12n } : CMTAT_single_asset.CMTAT.CMTAT_SINGLE_ASSET.CmtatSingleAssetExtendable.burn_param)
in
let r = Test.transfer orig.addr (Burn burn_request) 0tez in
let () = string_failure r CMTAT_single_asset.Token.FA2.SingleAssetExtendable.Errors.ins_balance in
let () = assert_totalsupply orig.addr 30n in
()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AUTHORIZATION module
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
let test_grant_role_success_simple =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
let () = Test.set_source initial_storage.administration.admin in
let flag : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag)) 0tez in
let () = assert_role addr owner1 flag in
()
let test_grant_role_success_with_ruler =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op2 = List_helper.nth_exn 1 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
// GRANT RULER ROLE
let () = Test.set_source initial_storage.administration.admin in
let flag_ruler : CMTAT_single_asset.Token.AUTHORIZATIONS.role = RULER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (op2, flag_ruler)) 0tez in
let () = assert_role addr op2 flag_ruler in
// GRANT ROLE
let () = Test.set_source op2 in
let flag : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag)) 0tez in
let () = assert_role addr owner1 flag in
()
let test_grant_role_success_multiple =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
let () = Test.set_source initial_storage.administration.admin in
let flag_minter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_minter)) 0tez in
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_burner)) 0tez in
let () = assert_role addr owner1 flag_minter in
let () = assert_role addr owner1 flag_burner in
()
let test_grant_role_failure_not_ruler =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
let () = Test.set_source owner2 in
let flag_minter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let r = Test.transfer_to_contract contr (GrantRole (owner1, flag_minter)) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.not_ruler in
let () = assert_no_role addr owner1 in
()
let test_revoke_role_success_with_admin =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
let () = Test.set_source initial_storage.administration.admin in
let flag_minter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_minter)) 0tez in
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_burner)) 0tez in
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (RevokeRole (owner1, flag_burner)) 0tez in
let () = assert_role addr owner1 flag_minter in
let () = assert_not_role addr owner1 flag_burner in
()
let test_revoke_role_success_with_ruler =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op2 = List_helper.nth_exn 1 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
// GRANT RULER ROLE
let () = Test.set_source initial_storage.administration.admin in
let flag_ruler : CMTAT_single_asset.Token.AUTHORIZATIONS.role = RULER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (op2, flag_ruler)) 0tez in
// GRANT ROLE with RULER
let () = Test.set_source op2 in
let flag_minter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_minter)) 0tez in
// GRANT ROLE with RULER
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_burner)) 0tez in
// REVOKE ROLE with RULER
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (RevokeRole (owner1, flag_burner)) 0tez in
let () = assert_role addr owner1 flag_minter in
let () = assert_not_role addr owner1 flag_burner in
()
let test_revoke_role_failure_not_ruler =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let op2 = List_helper.nth_exn 1 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
// GRANT ROLE with admin
let () = Test.set_source initial_storage.administration.admin in
let flag_minter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_minter)) 0tez in
// REVOKE ROLE with not RULER - fails
let () = Test.set_source op2 in
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let r = Test.transfer_to_contract contr (RevokeRole (owner2, flag_burner)) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.not_ruler in
let () = assert_role addr owner1 flag_minter in
()
let test_revoke_role_failure_unknown_user =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
let () = Test.set_source initial_storage.administration.admin in
let flag_minter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_minter)) 0tez in
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_burner)) 0tez in
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let r = Test.transfer_to_contract contr (RevokeRole (owner2, flag_burner)) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.unknown_user in
let () = assert_role addr owner1 flag_minter in
let () = assert_role addr owner1 flag_burner in
()
let test_revoke_role_failure_missing_role =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let { addr;code = _code; size = _size} = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
let contr = Test.to_contract addr in
let () = Test.set_source initial_storage.administration.admin in
let flag_minter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = MINTER in
let _ = Test.transfer_to_contract_exn contr (GrantRole (owner1, flag_minter)) 0tez in
let flag_burner : CMTAT_single_asset.Token.AUTHORIZATIONS.role = BURNER in
let r = Test.transfer_to_contract contr (RevokeRole (owner1, flag_burner)) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.missing_role in
let () = assert_role addr owner1 flag_minter in
()
////////////////////////////////////////////////////////////////////////////////
// SNAPSHOTS
////////////////////////////////////////////////////////////////////////////////
let test_schedule_snapshot_success =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// SCHEDULE SNAPSHOT
let snapshot_time_0 = ("2024-01-01t00:00:00Z" : timestamp) in
let _r = Test.transfer_exn orig.addr (ScheduleSnapshot snapshot_time_0) 0tez in
let () = assert_scheduled_snapshot orig.addr snapshot_time_0 in
()
let test_schedule_snapshot_success_with_snapshooter =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// GRANT ROLE SNAPSHOOTER (GLOBAL)
let () = Test.set_source initial_storage.administration.admin in
let flag_snapshooter : CMTAT_single_asset.Token.AUTHORIZATIONS.role = SNAPSHOOTER in
let _ = Test.transfer_exn orig.addr (GrantRole (owner1, flag_snapshooter)) 0tez in
// SCHEDULE SNAPSHOT
let () = Test.set_source owner1 in
let snapshot_time_0 = ("2024-01-01t00:00:00Z" : timestamp) in
let _r = Test.transfer_exn orig.addr (ScheduleSnapshot snapshot_time_0) 0tez in
let () = assert_scheduled_snapshot orig.addr snapshot_time_0 in
()
let test_schedule_snapshot_failure_not_snapshooter =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// SCHEDULE SNAPSHOT - fails because need snapshooter role
let () = Test.set_source owner1 in
let snapshot_time_0 = ("2024-01-01t00:00:00Z" : timestamp) in
let r = Test.transfer orig.addr (ScheduleSnapshot snapshot_time_0) 0tez in
let () = string_failure r CMTAT_single_asset.Token.AUTHORIZATIONS.Errors.not_snapshooter in
()
let test_schedule_snapshot_failure_before_next_scheduled =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// SCHEDULE SNAPSHOT
let snapshot_time_0 = ("2024-01-01t00:00:00Z" : timestamp) in
let _r = Test.transfer_exn orig.addr (ScheduleSnapshot snapshot_time_0) 0tez in
let () = assert_scheduled_snapshot orig.addr snapshot_time_0 in
// SCHEDULE SNAPSHOT
let snapshot_time_1 = ("2023-01-01t00:00:00Z" : timestamp) in
let r = Test.transfer orig.addr (ScheduleSnapshot snapshot_time_1) 0tez in
let () = string_failure r CMTAT_single_asset.Token.SNAPSHOTS.Errors.before_next_scheduled in
()
let test_schedule_snapshot_failure_already_scheduled =
let initial_storage, owners, operators = get_initial_storage (10n, 10n, 10n) in
let _owner1 = List_helper.nth_exn 0 owners in
let _owner2 = List_helper.nth_exn 1 owners in
let _owner3 = List_helper.nth_exn 2 owners in
let op1 = List_helper.nth_exn 0 operators in
let () = Test.set_source op1 in
let orig = Test.originate (contract_of CMTAT_single_asset) initial_storage 0tez in
// SCHEDULE SNAPSHOT
let snapshot_time_0 = ("2024-01-01t00:00:00Z" : timestamp) in
let _r = Test.transfer_exn orig.addr (ScheduleSnapshot snapshot_time_0) 0tez in