-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.sh
executable file
·321 lines (258 loc) · 16.3 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
#!/bin/bash
# set -e
# clear
dfx stop
rm -rf .dfx
ALICE_HOME=$(mktemp -d -t alice-temp)
BOB_HOME=$(mktemp -d -t bob-temp)
DAN_HOME=$(mktemp -d -t dan-temp)
FEE_HOME=$(mktemp -d -t fee-temp)
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
)\""
dfx start --background
dfx canister --no-wallet create token_ERC721
dfx canister --no-wallet create token_ERC20
dfx build
eval dfx canister --no-wallet install token_ERC721 --argument="'(\"Test NFT 1\", \"NFT1\",$ALICE_PUBLIC_KEY)'" -m=reinstall
eval dfx canister --no-wallet install token_ERC20 --argument="'(\"Test token\", \"tst\", 3, 1_000_000_000, $ALICE_PUBLIC_KEY)'" -m=reinstall
echo Alice id = $ALICE_PUBLIC_KEY
echo Bob id = $BOB_PUBLIC_KEY
echo Dan id = $DAN_PUBLIC_KEY
echo Fee id = $FEE_PUBLIC_KEY
NFT_ID=$(dfx canister --no-wallet id token_ERC721)
NFT_ID="principal \"$NFT_ID\""
TOKENID=$(dfx canister --no-wallet id token_ERC20)
TOKENID="principal \"$TOKENID\""
echo token_erc721 principal: $NFT_ID
echo token_erc20 principal: $TOKENID
echo == admin Alice set NFT Mint price and Mint fee
eval dfx canister --no-wallet call token_ERC721 setFeePrice "'(1000)'"
eval dfx canister --no-wallet call token_ERC721 setErc20 "'($TOKENID)'"
eval dfx canister --no-wallet call token_ERC721 setFeePool "'($FEE_PUBLIC_KEY)'"
echo == admin Alice Approve NFT canister transferFrom her ERC20 Token
eval dfx canister --no-wallet call token_ERC20 approve "'($NFT_ID, 1_000_000)'"
echo == Alice is admins, True
eval dfx canister --no-wallet call token_ERC721 isAdmin "'($ALICE_PUBLIC_KEY)'"
echo == Bob isnot admins, False
eval dfx canister --no-wallet call token_ERC721 isAdmin "'($BOB_PUBLIC_KEY)'"
echo == Set bob admin
eval dfx canister --no-wallet call token_ERC721 setAdmin "'($BOB_PUBLIC_KEY, true)'"
echo == Bob is admins, true
eval dfx canister --no-wallet call token_ERC721 isAdmin "'($BOB_PUBLIC_KEY)'"
echo == Get name, symbol
eval dfx canister --no-wallet call token_ERC721 name
eval dfx canister --no-wallet call token_ERC721 symbol
echo == Alice Mint 3 NFT to self, 3 NFT to Bob, all True
eval dfx canister --no-wallet call token_ERC721 mint "'($ALICE_PUBLIC_KEY, \"a.link/1\", \"token 1\", \"the 1 nft in here\")'"
eval dfx canister --no-wallet call token_ERC721 mint "'($BOB_PUBLIC_KEY, \"a.link/2\", \"token 2\", \"the 2 nft in here\")'"
eval dfx canister --no-wallet call token_ERC721 mint "'($ALICE_PUBLIC_KEY, \"a.link/3\", \"token 3\", \"the 3 nft in here\")'"
eval dfx canister --no-wallet call token_ERC721 mint "'($BOB_PUBLIC_KEY, \"a.link/4\", \"token 4\", \"the 4 nft in here\")'"
eval dfx canister --no-wallet call token_ERC721 mint "'($ALICE_PUBLIC_KEY, \"a.link/5\", \"token 5\", \"the 5 nft in here\")'"
eval dfx canister --no-wallet call token_ERC721 mint "'($BOB_PUBLIC_KEY, \"a.link/6\", \"token 6\", \"the 6 nft in here\")'"
echo == get token info
eval dfx canister --no-wallet call token_ERC721 tokenInfo "'(1)'"
eval dfx canister --no-wallet call token_ERC721 tokenInfo "'(2)'"
eval dfx canister --no-wallet call token_ERC721 tokenInfo "'(3)'"
eval dfx canister --no-wallet call token_ERC721 tokenInfo "'(4)'"
eval dfx canister --no-wallet call token_ERC721 tokenInfo "'(5)'"
eval dfx canister --no-wallet call token_ERC721 tokenInfo "'(6)'"
echo == alice change the token info of 1, true
eval dfx canister --no-wallet call token_ERC721 setTokenInfo "'(1, \"nft.com/1/\", \"nft token 1\", \"nft 1 in Dfinity/\")'"
eval dfx canister --no-wallet call token_ERC721 tokenInfo "'(1)'"
echo == alice change the token info of 2, false, not the owner
eval dfx canister --no-wallet call token_ERC721 setTokenInfo "'(2, \"nft.com/2/\", \"nft token 2\", \"nft 2 in Dfinity/\")'"
echo == fee pool balance
eval dfx canister --no-wallet call token_ERC20 balanceOf "'($FEE_PUBLIC_KEY)'"
echo == Alice Mint exists token, False
eval dfx canister --no-wallet call token_ERC721 mint "'($ALICE_PUBLIC_KEY, 0)'"
echo == Bob Mint new NFT, False, no erc20 token
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 mint "'($ALICE_PUBLIC_KEY, 6)'"
echo == Dan Mint new NFT, False, no erc20 token
eval HOME=$DAN_HOME dfx canister --no-wallet call token_ERC721 mint "'($ALICE_PUBLIC_KEY, 7)'"
echo == Get all tokens, Success
eval dfx canister --no-wallet call token_ERC721 getAllTokens
echo == Get Alice Bob Dan tokensList, Alice, Bob Success, Dan False.
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($BOB_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($DAN_PUBLIC_KEY)'"
echo == Get totalSupply 6
eval dfx canister --no-wallet call token_ERC721 totalSupply
echo == Alice and Bob Set Token URI, Success, False
eval HOME=$ALICE_HOME dfx canister --no-wallet call token_ERC721 setTokenURI "'(0, \"google.com/0\")'"
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 setTokenURI "'(2, \"google.com/2\")'"
echo == get token URI
eval dfx canister --no-wallet call token_ERC721 tokenURI "'(0)'"
eval dfx canister --no-wallet call token_ERC721 tokenURI "'(1)'"
echo == get token owner
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(0)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(1)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(2)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(3)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(4)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(5)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(6)'"
echo == get token by owner by index
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 2)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 3)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 2)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 3)'"
echo == get token by index
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(0)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(1)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(2)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(3)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(4)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(5)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(6)'"
echo == get balance 3,3, 0
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($BOB_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($DAN_PUBLIC_KEY)'"
echo == Alice transfer self NFT to Bob, Dan, 0,2,True; 1,4,5 False
eval dfx canister --no-wallet call token_ERC721 transferFrom "'($ALICE_PUBLIC_KEY, $BOB_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 transferFrom "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY, 2)'"
eval dfx canister --no-wallet call token_ERC721 transferFrom "'($BOB_PUBLIC_KEY, $DAN_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 transferFrom "'($BOB_PUBLIC_KEY, $DAN_PUBLIC_KEY, 4)'"
eval dfx canister --no-wallet call token_ERC721 transferFrom "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY, 5)'"
echo == Bob approve Alice token 1
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 approve "'($ALICE_PUBLIC_KEY, 1)'"
echo == get approved
eval dfx canister --no-wallet call token_ERC721 getApproved "'(1)'"
eval dfx canister --no-wallet call token_ERC721 getApproved "'(2)'"
echo == Alice transfer Bob token 1 to Alice
eval dfx canister --no-wallet call token_ERC721 safeTransferFrom "'($BOB_PUBLIC_KEY, $ALICE_PUBLIC_KEY, 1)'"
echo == get approved
eval dfx canister --no-wallet call token_ERC721 getApproved "'(1)'"
echo == get token owner
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(1)'"
echo == Alice Set Token URI, Success
eval dfx canister --no-wallet call token_ERC721 setTokenURI "'(1, \"baidu.com/1\")'"
echo == get token URI 1
eval dfx canister --no-wallet call token_ERC721 tokenURI "'(1)'"
echo == Bob set Dan approval For All
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 setApprovalForAll "'($DAN_PUBLIC_KEY, true)'"
echo == get isApprovedForAll
eval dfx canister --no-wallet call token_ERC721 isApprovedForAll "'($BOB_PUBLIC_KEY, $DAN_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 isApprovedForAll "'($BOB_PUBLIC_KEY, $ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 isApprovedForAll "'($ALICE_PUBLIC_KEY, $DAN_PUBLIC_KEY)'"
echo == Bob set self approved For All, False
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 setApprovalForAll "'($BOB_PUBLIC_KEY, true)'"
echo == get bob approved bob
eval dfx canister --no-wallet call token_ERC721 isApprovedForAll "'($BOB_PUBLIC_KEY, $BOB_PUBLIC_KEY)'"
echo == Dan transfer Bob NFT to Dan
eval HOME=$DAN_HOME dfx canister --no-wallet call token_ERC721 safeTransferFromWithData "'($BOB_PUBLIC_KEY, $DAN_PUBLIC_KEY, 3, \"safetransfer\")'"
echo == Get Alice Bob Dan tokensList, Success
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($BOB_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($DAN_PUBLIC_KEY)'"
echo == get token owner
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(0)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(1)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(2)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(3)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(4)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(5)'"
echo == get token by owner by index
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 2)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 3)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 2)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 3)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($DAN_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($DAN_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 2)'"
echo == get token by index
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(0)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(1)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(2)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(3)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(4)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(5)'"
echo == get balance 3,3, 0
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($BOB_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($DAN_PUBLIC_KEY)'"
echo == owner of token 3
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(3)'"
echo == Dan transfer nft 3 to canister
eval HOME=$DAN_HOME dfx canister --no-wallet call token_ERC721 transferFrom "'($DAN_PUBLIC_KEY, $NFT_ID, 3)'"
echo == owner of token3
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(3)'"
echo == admin alice withdraw token 3 to Dan
eval dfx canister --no-wallet call token_ERC721 withdraw "'(3, $DAN_PUBLIC_KEY)'"
echo == owner of token3
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(3)'"
echo == admin bob burn token 2
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 burn "'(2)'"
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 burn "'(7)'"
echo == Get allTokens
eval dfx canister --no-wallet call token_ERC721 getAllTokens
echo == Get Alice Bob Dan tokensList, Success
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($BOB_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 getTokenList "'($DAN_PUBLIC_KEY)'"
echo == get token owner
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(0)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(1)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(2)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(3)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(4)'"
eval dfx canister --no-wallet call token_ERC721 ownerOf "'(5)'"
echo == get token by owner by index
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 2)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($ALICE_PUBLIC_KEY, 3)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 0)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 1)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 2)'"
eval dfx canister --no-wallet call token_ERC721 tokenOfOwnerByIndex "'($BOB_PUBLIC_KEY, 3)'"
echo == get token by index
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(0)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(1)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(2)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(3)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(4)'"
eval dfx canister --no-wallet call token_ERC721 tokenByIndex "'(5)'"
echo == get balance
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($BOB_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 balanceOf "'($DAN_PUBLIC_KEY)'"
echo == Alice favourite 1,2,3 NFT token, 2 false
eval HOME=$ALICE_HOME dfx canister --no-wallet call token_ERC721 favourite "'(1)'"
eval HOME=$ALICE_HOME dfx canister --no-wallet call token_ERC721 favourite "'(2)'"
eval HOME=$ALICE_HOME dfx canister --no-wallet call token_ERC721 favourite "'(3)'"
echo == Bob favourite 2,3,5,6 NFT token 3,5 success, 2,6 Failed
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 favourite "'(2)'"
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 favourite "'(3)'"
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 favourite "'(5)'"
eval HOME=$BOB_HOME dfx canister --no-wallet call token_ERC721 favourite "'(6)'"
echo == get ALICE, BOB favourites,1,2,3 2,3,5
eval dfx canister --no-wallet call token_ERC721 getFavourites "'($ALICE_PUBLIC_KEY)'"
eval dfx canister --no-wallet call token_ERC721 getFavourites "'($BOB_PUBLIC_KEY)'"
echo == get 1,2,3,5, 0 favouritedBy, 1,2,2,1,0
eval dfx canister --no-wallet call token_ERC721 getFavouritedBy "'(1)'"
eval dfx canister --no-wallet call token_ERC721 getFavouritedBy "'(2)'"
eval dfx canister --no-wallet call token_ERC721 getFavouritedBy "'(3)'"
eval dfx canister --no-wallet call token_ERC721 getFavouritedBy "'(5)'"
eval dfx canister --no-wallet call token_ERC721 getFavouritedBy "'(0)'"
echo
dfx stop