-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.sh
executable file
·449 lines (346 loc) · 10.2 KB
/
demo.sh
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
#!/bin/bash
# set -e
# clear
dfx stop
rm -rf .dfx
ALICE_HOME=$(mktemp -d)
BOB_HOME=$(mktemp -d)
DAN_HOME=$(mktemp -d)
FEE_HOME=$(mktemp -d)
HOME=$ALICE_HOME
ALICE_PUBLIC_KEY="principal \"$( \
HOME=$ALICE_HOME dfx identity get-principal
)\""
BOB_PUBLIC_KEY="principal \"$( \
HOME=$BOB_HOME dfx identity get-principal
)\""
DAN_PUBLIC_KEY="principal \"$( \
HOME=$DAN_HOME dfx identity get-principal
)\""
FEE_PUBLIC_KEY="principal \"$( \
HOME=$FEE_HOME dfx identity get-principal
)\""
echo Alice id = $ALICE_PUBLIC_KEY
echo Bob id = $BOB_PUBLIC_KEY
echo Dan id = $DAN_PUBLIC_KEY
echo Fee id = $FEE_PUBLIC_KEY
dfx start --clean --background
dfx canister create --all
dfx build
TOKENID=$(dfx canister id token)
TOKENID="principal \"$TOKENID\""
echo Token id: $TOKENID
echo
echo == Install token canister
echo
HOME=$ALICE_HOME
eval dfx canister install token --argument="'(\"Test Token Logo\", \"Test Token Name\", \"Test Token Symbol\", 3, 1000000, $ALICE_PUBLIC_KEY, 0)'"
echo
echo == Initial setting for token canister
echo
eval dfx canister call token setFeeTo "'($FEE_PUBLIC_KEY)'"
eval dfx canister call token setFee "'(100)'"
echo
echo == Initial token balances for Alice and Bob, Dan, FeeTo
echo
echo Alice = $( \
eval dfx canister call token balanceOf "'($ALICE_PUBLIC_KEY)'" \
)
echo Bob = $( \
eval dfx canister call token balanceOf "'($BOB_PUBLIC_KEY)'" \
)
echo Dan = $( \
eval dfx canister call token balanceOf "'($DAN_PUBLIC_KEY)'" \
)
echo FeeTo = $( \
eval dfx canister call token balanceOf "'($FEE_PUBLIC_KEY)'" \
)
echo
echo == Transfer 0 tokens from Alice to Bob, should Return false, as value is smaller than fee.
echo
eval dfx canister call token transfer "'($BOB_PUBLIC_KEY, 0)'"
echo
echo == Transfer 0 tokens from Alice to Alice, should Return false, as value is smaller than fee.
echo
eval dfx canister call token transfer "'($ALICE_PUBLIC_KEY, 0)'"
echo
echo == Transfer 0.1 tokens from Alice to Bob, should success, revieve 0, as value = fee.
echo
eval dfx canister call token transfer "'($BOB_PUBLIC_KEY, 100)'"
echo
echo == Transfer 0.1 tokens from Alice to Alice, should success, revieve 0, as value = fee.
echo
eval dfx canister call token transfer "'($ALICE_PUBLIC_KEY, 100)'"
echo
echo == Transfer 100 tokens from Alice to Alice, should success.
echo
eval dfx canister call token transfer "'($ALICE_PUBLIC_KEY, 100_000)'"
echo
echo == Transfer 2000 tokens from Alice to Alice, should Return false, as no enough balance.
echo
eval dfx canister call token transfer "'($ALICE_PUBLIC_KEY, 2_000_000)'"
echo
echo == Transfer 0 tokens from Bob to Bob, should Return false, as value is smaller than fee.
echo
HOME=$BOB_HOME
eval dfx canister call token transfer "'($BOB_PUBLIC_KEY, 0)'"
echo
echo == Transfer 42 tokens from Alice to Bob, should success.
echo
HOME=$ALICE_HOME
eval dfx canister call token transfer "'($BOB_PUBLIC_KEY, 42_000)'"
echo
echo == Alice grants Dan permission to spend 1 of her tokens, should success.
echo
eval dfx canister call token approve "'($DAN_PUBLIC_KEY, 1_000)'"
echo
echo == Alice grants Dan permission to spend 0 of her tokens, should success.
echo
eval dfx canister call token approve "'($DAN_PUBLIC_KEY, 0)'"
echo
echo == Bob grants Dan permission to spend 1 of her tokens, should success.
echo
HOME=$BOB_HOME
eval dfx canister call token approve "'($DAN_PUBLIC_KEY, 1_000)'"
echo
echo == Dan transfer 1 token from Bob to Alice, should success.
echo
HOME=$DAN_HOME
eval dfx canister call token transferFrom "'($BOB_PUBLIC_KEY, $ALICE_PUBLIC_KEY, 1_000)'"
echo
echo == Transfer 40.9 tokens from Bob to Alice, should success.
echo
HOME=$BOB_HOME
eval dfx canister call token transfer "'($ALICE_PUBLIC_KEY, 40_900)'"
echo
echo == token balances for Alice, Bob, Dan and FeeTo.
echo
echo Alice = $( \
eval dfx canister call token balanceOf "'($ALICE_PUBLIC_KEY)'" \
)
echo Bob = $( \
eval dfx canister call token balanceOf "'($BOB_PUBLIC_KEY)'" \
)
echo Dan = $( \
eval dfx canister call token balanceOf "'($DAN_PUBLIC_KEY)'" \
)
echo FeeTo = $( \
eval dfx canister call token balanceOf "'($FEE_PUBLIC_KEY)'" \
)
echo
echo == Alice grants Dan permission to spend 50 of her tokens, should success.
echo
HOME=$ALICE_HOME
eval dfx canister call token approve "'($DAN_PUBLIC_KEY, 50_000)'"
echo
echo == Alices allowances
echo
echo Alices allowance for Dan = $( \
eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY)'" \
)
echo Alices allowance for Bob = $( \
eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $BOB_PUBLIC_KEY)'" \
)
echo
echo == Dan transfers 40 tokens from Alice to Bob, should success.
echo
HOME=$DAN_HOME
eval dfx canister call token transferFrom "'($ALICE_PUBLIC_KEY, $BOB_PUBLIC_KEY, 40_000)'"
echo
echo == Alice transfer 1 tokens To Dan
echo
HOME=$ALICE_HOME
eval dfx canister call token transfer "'($DAN_PUBLIC_KEY, 1_000)'"
echo
echo == Dan transfers 40 tokens from Alice to Bob, should Return false, as allowance remain 10, smaller than 40.
echo
HOME=$DAN_HOME
eval dfx canister call token transferFrom "'($ALICE_PUBLIC_KEY, $BOB_PUBLIC_KEY, 40_000)'"
echo
echo == Token balance for Alice and Bob and Dan
echo
echo Alice = $( \
eval dfx canister call token balanceOf "'($ALICE_PUBLIC_KEY)'" \
)
echo Bob = $( \
eval dfx canister call token balanceOf "'($BOB_PUBLIC_KEY)'" \
)
echo Dan = $( \
eval dfx canister call token balanceOf "'($DAN_PUBLIC_KEY)'" \
)
echo Fee = $( \
eval dfx canister call token balanceOf "'($FEE_PUBLIC_KEY)'" \
)
echo
echo == Alice allowances
echo
echo Alices allowance for Bob = $( \
eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $BOB_PUBLIC_KEY)'" \
)
echo Alices allowance for Dan = $( \
eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY)'" \
)
echo
echo == Alice grants Bob permission to spend 100 of her tokens
echo
HOME=$ALICE_HOME
eval dfx canister call token approve "'($BOB_PUBLIC_KEY, 100_000)'"
echo
echo == Alice allowances
echo
echo Alices allowance for Bob = $( \
eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $BOB_PUBLIC_KEY)'" \
)
echo Alices allowance for Dan = $( \
eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY)'" \
)
echo
echo == Bob transfers 99 tokens from Alice to Dan
echo
HOME=$BOB_HOME
eval dfx canister call token transferFrom "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY, 99_000)'"
echo
echo == Balances
echo
echo Alice = $( \
eval dfx canister call token balanceOf "'($ALICE_PUBLIC_KEY)'" \
)
echo Bob = $( \
eval dfx canister call token balanceOf "'($BOB_PUBLIC_KEY)'" \
)
echo Dan = $( \
eval dfx canister call token balanceOf "'($DAN_PUBLIC_KEY)'" \
)
echo Fee = $( \
eval dfx canister call token balanceOf "'($FEE_PUBLIC_KEY)'" \
)
echo
echo == Alice allowances
echo
echo Alices allowance for Bob = $( eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $BOB_PUBLIC_KEY)'" )
echo Alices allowance for Dan = $( eval dfx canister call token allowance "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY)'" )
echo
echo == Dan grants Bob permission to spend 100 of this tokens, should success.
echo
HOME=$DAN_HOME
eval dfx canister call token approve "'($BOB_PUBLIC_KEY, 100_000)'"
echo
echo == Dan grants Bob permission to spend 50 of this tokens
echo
eval dfx canister call token approve "'($BOB_PUBLIC_KEY, 50_000)'"
echo
echo == Dan allowances
echo
echo Dan allowance for Bob = $( \
eval dfx canister call token allowance "'($DAN_PUBLIC_KEY, $BOB_PUBLIC_KEY)'" \
)
echo Dan allowance for Alice = $( \
eval dfx canister call token allowance "'($DAN_PUBLIC_KEY, $ALICE_PUBLIC_KEY)'" \
)
echo
echo == Dan change Bobs permission to spend 40 of this tokens instead of 50
echo
eval dfx canister call token approve "'($BOB_PUBLIC_KEY, 40_000)'"
echo
echo == Dan allowances
echo
echo Dan allowance for Bob = $( \
eval dfx canister call token allowance "'($DAN_PUBLIC_KEY, $BOB_PUBLIC_KEY)'" \
)
echo Dan allowance for Alice = $( \
eval dfx canister call token allowance "'($DAN_PUBLIC_KEY, $ALICE_PUBLIC_KEY)'" \
)
echo
echo == logo
echo
eval dfx canister call token logo
echo
echo == name
echo
eval dfx canister call token name
echo
echo == symbol
echo
eval dfx canister call token symbol
echo
echo == decimals
echo
eval dfx canister call token decimals
echo
echo == totalSupply
echo
eval dfx canister call token totalSupply
echo
echo == getMetadata
echo
eval dfx canister call token getMetadata
echo
echo == historySize
echo
eval dfx canister call token historySize
echo
echo == getTransaction
echo
eval dfx canister call token getTransaction "'(1)'"
echo
echo == getTransactions
echo
eval dfx canister call token getTransactions "'(0,100)'"
echo
echo == getUserTransactionAmount
echo
eval dfx canister call token getUserTransactionAmount "'($ALICE_PUBLIC_KEY)'"
echo
echo == getUserTransactions
echo
eval dfx canister call token getUserTransactions "'($ALICE_PUBLIC_KEY, 0, 1000)'"
echo
echo == getTokenInfo
echo
eval dfx canister call token getTokenInfo
echo
echo == getHolders
echo
eval dfx canister call token getHolders "'(0,100)'"
echo
echo == getAllowanceSize
echo
eval dfx canister call token getAllowanceSize
echo
echo == getUserApprovals
echo
eval dfx canister call token getUserApprovals "'($ALICE_PUBLIC_KEY)'"
echo
echo == get alice getUserTransactions
echo
eval dfx canister call token getUserTransactions "'($ALICE_PUBLIC_KEY, 0, 1000)'"
echo
echo == get bob History
echo
eval dfx canister call token getUserTransactions "'($BOB_PUBLIC_KEY, 0, 1000)'"
echo
echo == get dan History
echo
eval dfx canister call token getUserTransactions "'($DAN_PUBLIC_KEY, 0, 1000)'"
echo
echo == get fee History
echo
eval dfx canister call token getUserTransactions "'($FEE_PUBLIC_KEY, 0, 1000)'"
echo
echo == Upgrade token
echo
HOME=$ALICE_HOME
eval dfx canister install token --argument="'(\"test\", \"Test Token\", \"TT\", 2, 100, $ALICE_PUBLIC_KEY)'" -m=upgrade
echo
echo == all History
echo
eval dfx canister call token getTransactions "'(0, 1000)'"
echo
echo == getTokenInfo
echo
dfx canister call token getTokenInfo
echo
echo == get alice History
echo
eval dfx canister call token getUserTransactions "'($ALICE_PUBLIC_KEY, 0, 1000)'"
dfx stop