git.delta.rocks / unique-network / refs/commits / 50ec7473069d

difftreelog

Merge branch 'develop' into feature/CORE-260

Igor Kozyrev2021-11-23parents: #f7cf061 #6e5d305.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;
78 });81 });
79});82});
83
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});
80397
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;
172 });489 });
173});490});
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();
190 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
191
192 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
193 await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address);
194 });
195});
196491