1
+ import test from 'ava' ;
2
+ import { stablecoin } from '.' ;
3
+
4
+ import { buildStablecoin , StablecoinOptions } from './stablecoin' ;
5
+ import { printContract } from './print' ;
6
+
7
+ function testStablecoin ( title : string , opts : Partial < StablecoinOptions > ) {
8
+ test ( title , t => {
9
+ const c = buildStablecoin ( {
10
+ name : 'MyStablecoin' ,
11
+ symbol : 'MST' ,
12
+ ...opts ,
13
+ } ) ;
14
+ t . snapshot ( printContract ( c ) ) ;
15
+ } ) ;
16
+ }
17
+
18
+ /**
19
+ * Tests external API for equivalence with internal API
20
+ */
21
+ function testAPIEquivalence ( title : string , opts ?: StablecoinOptions ) {
22
+ test ( title , t => {
23
+ t . is ( stablecoin . print ( opts ) , printContract ( buildStablecoin ( {
24
+ name : 'MyStablecoin' ,
25
+ symbol : 'MST' ,
26
+ ...opts ,
27
+ } ) ) ) ;
28
+ } ) ;
29
+ }
30
+
31
+ testStablecoin ( 'basic stablecoin' , { } ) ;
32
+
33
+ testStablecoin ( 'stablecoin burnable' , {
34
+ burnable : true ,
35
+ } ) ;
36
+
37
+ testStablecoin ( 'stablecoin pausable' , {
38
+ pausable : true ,
39
+ access : 'ownable' ,
40
+ } ) ;
41
+
42
+ testStablecoin ( 'stablecoin pausable with roles' , {
43
+ pausable : true ,
44
+ access : 'roles' ,
45
+ } ) ;
46
+
47
+ testStablecoin ( 'stablecoin pausable with managed' , {
48
+ pausable : true ,
49
+ access : 'managed' ,
50
+ } ) ;
51
+
52
+ testStablecoin ( 'stablecoin burnable pausable' , {
53
+ burnable : true ,
54
+ pausable : true ,
55
+ } ) ;
56
+
57
+ testStablecoin ( 'stablecoin preminted' , {
58
+ premint : '1000' ,
59
+ } ) ;
60
+
61
+ testStablecoin ( 'stablecoin premint of 0' , {
62
+ premint : '0' ,
63
+ } ) ;
64
+
65
+ testStablecoin ( 'stablecoin mintable' , {
66
+ mintable : true ,
67
+ access : 'ownable' ,
68
+ } ) ;
69
+
70
+ testStablecoin ( 'stablecoin mintable with roles' , {
71
+ mintable : true ,
72
+ access : 'roles' ,
73
+ } ) ;
74
+
75
+ testStablecoin ( 'stablecoin permit' , {
76
+ permit : true ,
77
+ } ) ;
78
+
79
+ testStablecoin ( 'stablecoin custodian' , {
80
+ custodian : true ,
81
+ } ) ;
82
+
83
+ testStablecoin ( 'stablecoin allowlist' , {
84
+ limitations : 'allowlist' ,
85
+ } ) ;
86
+
87
+ testStablecoin ( 'stablecoin blocklist' , {
88
+ limitations : 'blocklist' ,
89
+ } ) ;
90
+
91
+ testStablecoin ( 'stablecoin votes' , {
92
+ votes : true ,
93
+ } ) ;
94
+
95
+ testStablecoin ( 'stablecoin votes + blocknumber' , {
96
+ votes : 'blocknumber' ,
97
+ } ) ;
98
+
99
+ testStablecoin ( 'stablecoin votes + timestamp' , {
100
+ votes : 'timestamp' ,
101
+ } ) ;
102
+
103
+ testStablecoin ( 'stablecoin flashmint' , {
104
+ flashmint : true ,
105
+ } ) ;
106
+
107
+ testAPIEquivalence ( 'stablecoin API default' ) ;
108
+
109
+ testAPIEquivalence ( 'stablecoin API basic' , { name : 'CustomStablecoin' , symbol : 'CST' } ) ;
110
+
111
+ testAPIEquivalence ( 'stablecoin API full' , {
112
+ name : 'CustomStablecoin' ,
113
+ symbol : 'CST' ,
114
+ premint : '2000' ,
115
+ access : 'roles' ,
116
+ burnable : true ,
117
+ mintable : true ,
118
+ pausable : true ,
119
+ permit : true ,
120
+ votes : true ,
121
+ flashmint : true ,
122
+ limitations : 'allowlist' ,
123
+ custodian : true
124
+ } ) ;
125
+
126
+ test ( 'stablecoin API assert defaults' , async t => {
127
+ t . is ( stablecoin . print ( stablecoin . defaults ) , stablecoin . print ( ) ) ;
128
+ } ) ;
129
+
130
+ test ( 'stablecoin API isAccessControlRequired' , async t => {
131
+ t . is ( stablecoin . isAccessControlRequired ( { mintable : true } ) , true ) ;
132
+ t . is ( stablecoin . isAccessControlRequired ( { pausable : true } ) , true ) ;
133
+ t . is ( stablecoin . isAccessControlRequired ( { limitations : 'allowlist' } ) , true ) ;
134
+ t . is ( stablecoin . isAccessControlRequired ( { limitations : 'blocklist' } ) , true ) ;
135
+ } ) ;
0 commit comments