git.delta.rocks / unique-network / refs/commits / 012b227bf9e4

difftreelog

CORE-168

str-mv2021-11-12parent: #516bf2b.patch.diff
in: master

1 file changed

modifiedtests/src/approve.test.tsdiffbeforeafterboth
18 transferExpectSuccess,18 transferExpectSuccess,
19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,
20 adminApproveFromExpectSuccess,20 adminApproveFromExpectSuccess,
21 transferFromExpectSuccess,
22 transferFromExpectFail,
21} from './util/helpers';23} from './util/helpers';
2224
23chai.use(chaiAsPromised);25chai.use(chaiAsPromised);
26const expect = chai.expect;
2427
25describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {28describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
26 let alice: IKeyringPair;29 let Alice: IKeyringPair;
27 let bob: IKeyringPair;30 let Bob: IKeyringPair;
28 let charlie: IKeyringPair;31 let Charlie: IKeyringPair;
2932
30 before(async () => {33 before(async () => {
31 await usingApi(async () => {34 await usingApi(async () => {
32 alice = privateKey('//Alice');35 Alice = privateKey('//Alice');
33 bob = privateKey('//Bob');36 Bob = privateKey('//Bob');
34 charlie = privateKey('//Charlie');37 Charlie = privateKey('//Charlie');
35 });38 });
36 });39 });
3740
38 it('Execute the extrinsic and check approvedList', async () => {41 it('Execute the extrinsic and check approvedList', async () => {
39 const nftCollectionId = await createCollectionExpectSuccess();42 const nftCollectionId = await createCollectionExpectSuccess();
40 // nft43 // nft
41 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');44 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
42 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);45 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address);
43 // fungible46 // fungible
44 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});47 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
45 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');48 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
46 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);49 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address);
47 // reFungible50 // reFungible
48 const reFungibleCollectionId =51 const reFungibleCollectionId =
49 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});52 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
50 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');53 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
51 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);54 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address);
52 });55 });
5356
54 it('Remove approval by using 0 amount', async () => {57 it('Remove approval by using 0 amount', async () => {
55 const nftCollectionId = await createCollectionExpectSuccess();58 const nftCollectionId = await createCollectionExpectSuccess();
56 // nft59 // nft
57 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');60 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
58 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);61 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address, 1);
59 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);62 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address, 0);
60 // fungible63 // fungible
61 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});64 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
62 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');65 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
63 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);66 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 1);
64 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);67 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 0);
65 // reFungible68 // reFungible
66 const reFungibleCollectionId =69 const reFungibleCollectionId =
67 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});70 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
68 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');71 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
69 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);72 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 1);
70 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);73 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 0);
71 });74 });
7275
73 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {76 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
74 const collectionId = await createCollectionExpectSuccess();77 const collectionId = await createCollectionExpectSuccess();
75 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);78 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
7679
77 await adminApproveFromExpectSuccess(collectionId, itemId, alice, bob.address, charlie.address);80 await adminApproveFromExpectSuccess(collectionId, itemId, Alice, Bob.address, Charlie.address);
78 });81 });
79});82});
8083
84describe('Normal user can approve other users to transfer:', () => {
85 let Alice: IKeyringPair;
86 let Bob: IKeyringPair;
87 let Charlie: IKeyringPair;
88
89 before(async () => {
90 await usingApi(async () => {
91 Alice = privateKey('//Alice');
92 Bob = privateKey('//Bob');
93 Charlie = privateKey('//Charlie');
94 });
95 });
96
97 it('NFT', async () => {
98 const collectionId = await createCollectionExpectSuccess();
99 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
100 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
101 });
102
103 it('Fungible up to an approved amount', async () => {
104 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
105 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address);
106 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
107 });
108
109 it('ReFungible up to an approved amount', async () => {
110 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
111 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address);
112 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
113 });
114});
115
116describe('Approved users can transferFrom up to approved amount:', () => {
117 let Alice: IKeyringPair;
118 let Bob: IKeyringPair;
119 let Charlie: IKeyringPair;
120
121 before(async () => {
122 await usingApi(async () => {
123 Alice = privateKey('//Alice');
124 Bob = privateKey('//Bob');
125 Charlie = privateKey('//Charlie');
126 });
127 });
128
129 it('NFT', async () => {
130 const collectionId = await createCollectionExpectSuccess();
131 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
132 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
133 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'NFT');
134 });
135
136 it('Fungible up to an approved amount', async () => {
137 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
138 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address);
139 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
140 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'Fungible');
141 });
142
143 it('ReFungible up to an approved amount', async () => {
144 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
145 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address);
146 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
147 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'ReFungible');
148 });
149});
150
151describe('Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:', () => {
152 let Alice: IKeyringPair;
153 let Bob: IKeyringPair;
154 let Charlie: IKeyringPair;
155
156 before(async () => {
157 await usingApi(async () => {
158 Alice = privateKey('//Alice');
159 Bob = privateKey('//Bob');
160 Charlie = privateKey('//Charlie');
161 });
162 });
163
164 it('NFT', async () => {
165 const collectionId = await createCollectionExpectSuccess();
166 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
167 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
168 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'NFT');
169 await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1);
170 });
171
172 it('Fungible up to an approved amount', async () => {
173 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
174 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address);
175 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
176 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'Fungible');
177 await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1);
178 });
179
180 it('ReFungible up to an approved amount', async () => {
181 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
182 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address);
183 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);
184 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'ReFungible');
185 await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1);
186 });
187});
188
189describe('Approved amount decreases by the transferred amount.:', () => {
190 let Alice: IKeyringPair;
191 let Bob: IKeyringPair;
192 let Charlie: IKeyringPair;
193 let Dave: IKeyringPair;
194
195 before(async () => {
196 await usingApi(async () => {
197 Alice = privateKey('//Alice');
198 Bob = privateKey('//Bob');
199 Charlie = privateKey('//Charlie');
200 Dave = privateKey('//Dave');
201 });
202 });
203
204 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {
205 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
206 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Alice.address);
207 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 10);
208 await transferFromExpectSuccess(collectionId, itemId, Bob, Alice, Charlie, 2, 'Fungible');
209 await transferFromExpectSuccess(collectionId, itemId, Bob, Alice, Dave, 8, 'Fungible');
210 });
211});
212
213describe('User may clear the approvals to approving for 0 amount:', () => {
214 let Alice: IKeyringPair;
215 let Bob: IKeyringPair;
216 let Charlie: IKeyringPair;
217
218 before(async () => {
219 await usingApi(async () => {
220 Alice = privateKey('//Alice');
221 Bob = privateKey('//Bob');
222 Charlie = privateKey('//Charlie');
223 });
224 });
225
226 it('NFT', async () => {
227 const collectionId = await createCollectionExpectSuccess();
228 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT');
229 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 1);
230 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 0);
231 await transferFromExpectFail(collectionId, itemId, Bob, Bob, Charlie, 1);
232 });
233
234 it('Fungible', async () => {
235 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
236 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
237 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 1);
238 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 0);
239 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Bob, Charlie, 1);
240 });
241
242 it('ReFungible', async () => {
243 const reFungibleCollectionId =
244 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
245 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
246 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 1);
247 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 0);
248 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Bob, Charlie, 1);
249 });
250});
251
252describe('User cannot approve for the amount greater than they own:', () => {
253 let Alice: IKeyringPair;
254 let Bob: IKeyringPair;
255 let Charlie: IKeyringPair;
256
257 before(async () => {
258 await usingApi(async () => {
259 Alice = privateKey('//Alice');
260 Bob = privateKey('//Bob');
261 Charlie = privateKey('//Charlie');
262 });
263 });
264
265 it('1 for NFT', async () => {
266 const collectionId = await createCollectionExpectSuccess();
267 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
268 await approveExpectFail(collectionId, itemId, Bob, Charlie, 2);
269 });
270
271 it('Fungible', async () => {
272 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
273 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
274 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Charlie, 11);
275 });
276
277 it('ReFungible', async () => {
278 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
279 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
280 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Charlie, 101);
281 });
282});
283
284describe('Administrator and collection owner do not need approval in order to execute TransferFrom:', () => {
285 let Alice: IKeyringPair;
286 let Bob: IKeyringPair;
287 let Charlie: IKeyringPair;
288 let Dave: IKeyringPair;
289
290 before(async () => {
291 await usingApi(async () => {
292 Alice = privateKey('//Alice');
293 Bob = privateKey('//Bob');
294 Charlie = privateKey('//Charlie');
295 Dave = privateKey('//Dave');
296 });
297 });
298
299 it('NFT', async () => {
300 const collectionId = await createCollectionExpectSuccess();
301 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Charlie.address);
302 await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'NFT');
303 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);
304 await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'NFT');
305 });
306
307 it('Fungible up to an approved amount', async () => {
308 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
309 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Charlie.address);
310 await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'Fungible');
311 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);
312 await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'Fungible');
313 });
314
315 it('ReFungible up to an approved amount', async () => {
316 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
317 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Charlie.address);
318 await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'ReFungible');
319 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);
320 await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'ReFungible');
321 });
322});
323
324describe('Repeated approvals add up', () => {
325 let Alice: IKeyringPair;
326 let Bob: IKeyringPair;
327 let Charlie: IKeyringPair;
328 let Dave: IKeyringPair;
329
330 before(async () => {
331 await usingApi(async () => {
332 Alice = privateKey('//Alice');
333 Bob = privateKey('//Bob');
334 Charlie = privateKey('//Charlie');
335 Dave = privateKey('//Dave');
336 });
337 });
338
339 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {
340 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
341 await createItemExpectSuccess(Alice, collectionId, 'Fungible', Alice.address);
342 await approveExpectSuccess(collectionId, 0, Alice, Bob.address, 1);
343 await approveExpectSuccess(collectionId, 0, Alice, Charlie.address, 1);
344 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);
345 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);
346 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));
347 });
348
349 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async () => {
350 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
351 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Alice.address);
352 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 1);
353 await approveExpectSuccess(collectionId, itemId, Alice, Charlie.address, 1);
354 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);
355 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);
356 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));
357 });
358
359 // Canceled by changing approve logic
360 it.skip('Cannot approve for more than total user`s amount (owned: 10, approval 1: 5 - should succeed, approval 2: 6 - should fail). Fungible', async () => {
361 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
362 await createItemExpectSuccess(Alice, collectionId, 'Fungible', Dave.address);
363 await approveExpectSuccess(collectionId, 0, Dave, Bob.address, 5);
364 await approveExpectFail(collectionId, 0, Dave, Charlie, 6);
365 });
366
367 // Canceled by changing approve logic
368 it.skip('Cannot approve for more than total users amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async () => {
369 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
370 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Dave.address);
371 await approveExpectSuccess(collectionId, itemId, Dave, Bob.address, 50);
372 await approveExpectFail(collectionId, itemId, Dave, Charlie, 51);
373 });
374});
375
376describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {
377 let Alice: IKeyringPair;
378 let Bob: IKeyringPair;
379 let Charlie: IKeyringPair;
380
381 before(async () => {
382 await usingApi(async () => {
383 Alice = privateKey('//Alice');
384 Bob = privateKey('//Bob');
385 Charlie = privateKey('//Charlie');
386 });
387 });
388
389 it('can be called by collection admin on non-owned item', async () => {
390 const collectionId = await createCollectionExpectSuccess();
391 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
392
393 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);
394 await adminApproveFromExpectSuccess(collectionId, itemId, Bob, Alice.address, Charlie.address);
395 });
396});
397
81describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {398describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
82 let alice: IKeyringPair;399 let Alice: IKeyringPair;
83 let bob: IKeyringPair;400 let Bob: IKeyringPair;
84 let charlie: IKeyringPair;401 let Charlie: IKeyringPair;
85402
86 before(async () => {403 before(async () => {
87 await usingApi(async () => {404 await usingApi(async () => {
88 alice = privateKey('//Alice');405 Alice = privateKey('//Alice');
89 bob = privateKey('//Bob');406 Bob = privateKey('//Bob');
90 charlie = privateKey('//Charlie');407 Charlie = privateKey('//Charlie');
91 });408 });
92 });409 });
93410
94 it('Approve for a collection that does not exist', async () => {411 it('Approve for a collection that does not exist', async () => {
95 await usingApi(async (api: ApiPromise) => {412 await usingApi(async (api: ApiPromise) => {
96 // nft413 // nft
97 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();414 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
98 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);415 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);
99 // fungible416 // fungible
100 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();417 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
101 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);418 await approveExpectFail(fungibleCollectionCount + 1, 0, Alice, Bob);
102 // reFungible419 // reFungible
103 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();420 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
104 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);421 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);
105 });422 });
106 });423 });
107424
108 it('Approve for a collection that was destroyed', async () => {425 it('Approve for a collection that was destroyed', async () => {
109 // nft426 // nft
110 const nftCollectionId = await createCollectionExpectSuccess();427 const nftCollectionId = await createCollectionExpectSuccess();
111 await destroyCollectionExpectSuccess(nftCollectionId);428 await destroyCollectionExpectSuccess(nftCollectionId);
112 await approveExpectFail(nftCollectionId, 1, alice, bob);429 await approveExpectFail(nftCollectionId, 1, Alice, Bob);
113 // fungible430 // fungible
114 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});431 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
115 await destroyCollectionExpectSuccess(fungibleCollectionId);432 await destroyCollectionExpectSuccess(fungibleCollectionId);
116 await approveExpectFail(fungibleCollectionId, 0, alice, bob);433 await approveExpectFail(fungibleCollectionId, 0, Alice, Bob);
117 // reFungible434 // reFungible
118 const reFungibleCollectionId =435 const reFungibleCollectionId =
119 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});436 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
120 await destroyCollectionExpectSuccess(reFungibleCollectionId);437 await destroyCollectionExpectSuccess(reFungibleCollectionId);
121 await approveExpectFail(reFungibleCollectionId, 1, alice, bob);438 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);
122 });439 });
123440
124 it('Approve transfer of a token that does not exist', async () => {441 it('Approve transfer of a token that does not exist', async () => {
125 // nft442 // nft
126 const nftCollectionId = await createCollectionExpectSuccess();443 const nftCollectionId = await createCollectionExpectSuccess();
127 await approveExpectFail(nftCollectionId, 2, alice, bob);444 await approveExpectFail(nftCollectionId, 2, Alice, Bob);
128 // reFungible445 // reFungible
129 const reFungibleCollectionId =446 const reFungibleCollectionId =
130 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});447 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
131 await approveExpectFail(reFungibleCollectionId, 2, alice, bob);448 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);
132 });449 });
133450
134 it('Approve using the address that does not own the approved token', async () => {451 it('Approve using the address that does not own the approved token', async () => {
135 const nftCollectionId = await createCollectionExpectSuccess();452 const nftCollectionId = await createCollectionExpectSuccess();
136 // nft453 // nft
137 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');454 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
138 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);455 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);
139 // fungible456 // fungible
140 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});457 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
141 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');458 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
142 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);459 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);
143 // reFungible460 // reFungible
144 const reFungibleCollectionId =461 const reFungibleCollectionId =
145 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});462 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
146 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');463 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
147 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);464 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);
148 });465 });
149466
150 it('should fail if approved more ReFungibles than owned', async () => {467 it('should fail if approved more ReFungibles than owned', async () => {
151 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});468 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
152 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');469 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible');
153 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');470 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible');
154 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);471 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice.address, 100);
155 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);472 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 101);
156 });473 });
157474
158 it('should fail if approved more Fungibles than owned', async () => {475 it('should fail if approved more Fungibles than owned', async () => {
159 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});476 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
160 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');477 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible');
161 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');478 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible');
162 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);479 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice.address, 10);
163 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);480 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 11);
164 });481 });
165482
166 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {483 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
167 const collectionId = await createCollectionExpectSuccess();
168 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
169 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});
170
171 await approveExpectFail(collectionId, itemId, alice, charlie);
172 });
173});
174
175describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {
176 let alice: IKeyringPair;
177 let bob: IKeyringPair;
178 let charlie: IKeyringPair;
179
180 before(async () => {
181 await usingApi(async () => {
182 alice = privateKey('//Alice');
183 bob = privateKey('//Bob');
184 charlie = privateKey('//Charlie');
185 });
186 });
187
188 it('can be called by collection admin on non-owned item', async () => {
189 const collectionId = await createCollectionExpectSuccess();484 const collectionId = await createCollectionExpectSuccess();
190 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);485 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);
486 await setCollectionLimitsExpectSuccess(Alice, collectionId, {ownerCanTransfer: false});
191487
192 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);488 await approveExpectFail(collectionId, itemId, Alice, Charlie);
193 await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address);
194 });489 });
195});490});
196491