git.delta.rocks / unique-network / refs/commits / 3bd9a5e8383e

difftreelog

test(nesting) extended test suite

Fahrrader2022-04-08parent: #6f234a4.patch.diff
in: master

4 files changed

modifiedtests/package.jsondiffbeforeafterboth
33 "loadTransfer": "ts-node src/transfer.nload.ts",33 "loadTransfer": "ts-node src/transfer.nload.ts",
34 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",34 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",
35 "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",35 "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",
36 "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
36 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",37 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
37 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",38 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
38 "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",39 "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
1import {expect} from 'chai';1import {expect} from 'chai';
2import {tokenIdToAddress} from '../eth/util/helpers';2import {tokenIdToAddress} from '../eth/util/helpers';
3import privateKey from '../substrate/privateKey';3import privateKey from '../substrate/privateKey';
4import usingApi from '../substrate/substrate-api';4import usingApi, {executeTransaction} from '../substrate/substrate-api';
5import {createCollectionExpectSuccess, createItemExpectSuccess, getTokenOwner, getTopmostTokenOwner, setCollectionLimitsExpectSuccess, transferExpectSuccess, transferFromExpectSuccess} from '../util/helpers';5import {
6 addToAllowListExpectSuccess,
7 createCollectionExpectSuccess,
8 createItemExpectFailure,
9 createItemExpectSuccess,
10 enableAllowListExpectSuccess,
11 enablePublicMintingExpectSuccess,
12 getTokenOwner,
13 getTopmostTokenOwner,
14 setCollectionLimitsExpectSuccess,
15 transferExpectFailure,
16 transferExpectSuccess,
17 transferFromExpectSuccess,
18} from '../util/helpers';
19import {IKeyringPair} from '@polkadot/types/types';
620
21let alice: IKeyringPair;
22let bob: IKeyringPair;
23
7describe('nesting', () => {24describe('Integration Test: Nesting', () => {
8 it('allows to nest/unnest token', async () => {25 before(async () => {
26 alice = privateKey('//Alice');
27 bob = privateKey('//Bob');
28 });
29
30 // ---------- Non-Fungible ----------
31
32 // todo refactor names
33 // todo remove excessive bundling, leave it for a single test
34 it('NFT: allows to nest/unnest token if nesting rule is Owner', async () => {
9 await usingApi(async api => {35 await usingApi(async api => {
10 const alice = privateKey('//Alice');36 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
11 const bob = privateKey('//Bob');37 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
38 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
1239
40 // Create a nested token
41 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
42 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
43 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
44
45 // Create a token to be nested
46 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
47
48 // Nest
49 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
50 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
51 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
52
53 // Move bundle to different user
54 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});
55 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});
56 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
57
58 // Unnest
59 await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});
60 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});
61 });
62 });
63
64 it('NFT: allows to nest/unnest token if Owner-Restricted', async () => {
65 await usingApi(async api => {
13 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
14 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule:{OwnerRestricted:[collection]}});67 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
15 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');68 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
1669
17 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT');70 // Create a nested token
71 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
72 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
73 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
1874
75 // Create a token to be nested
76 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
77
19 // Nest78 // Nest
20 await transferExpectSuccess(collection, nestedToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});79 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
21
22 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});80 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});
23 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});81 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
2482
25 // Move bundle to different user83 // Move bundle to different user
26 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});84 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});
27
28 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});85 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});
29 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});86 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
87
88 // Unnest
89 await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});
90 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});
91 });
92 });
3093
94 // ---------- Fungible ----------
95
96 it('Fungible: allows to nest/unnest token if Owner', async () => {
97 await usingApi(async api => {
98 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
99 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
100 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
101 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
102
103 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
104
105 // Create a nested token
106 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
107 collectionFT,
108 targetAddress,
109 {Fungible: {Value: 10}},
110 ))).to.not.be.rejected;
111
112 // Create a token to be nested
113 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
114 // Nest
115 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');
116 // Move bundle to different user
117 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
31 // Unnest118 // Unnest
32 await transferFromExpectSuccess(collection, nestedToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});119 await transferFromExpectSuccess(collectionFT, newToken, bob, targetAddress, {Substrate: bob.address}, 1, 'Fungible');
120 });
121 });
122
123 it('Fungible: allows to nest/unnest token if Owner-Restricted', async () => {
124 await usingApi(async api => {
125 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
126 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
127 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
128
129 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
130
131 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionFT]}});
132
133 // Create a nested token
134 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
135 collectionFT,
136 targetAddress,
137 {Fungible: {Value: 10}},
138 ))).to.not.be.rejected;
139
140 // Create a token to be nested
141 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
142 // Nest
143 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');
144 // Move bundle to different user
145 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
146 // Unnest
147 await transferFromExpectSuccess(collectionFT, newToken, bob, targetAddress, {Substrate: bob.address}, 1, 'Fungible');
148 });
149 });
150
151 // ---------- Re-Fungible ----------
152
153 it('ReFungible: allows to nest/unnest token if Owner', async () => {
154 await usingApi(async api => {
155 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
156 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
157 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
158 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
159
160 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
161
162 // Create a nested token
163 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
164 collectionRFT,
165 targetAddress,
166 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
167 ))).to.not.be.rejected;
168
169 // Create a token to be nested
170 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
171 // Nest
172 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');
173 // Move bundle to different user
174 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
175 // Unnest
176 await transferFromExpectSuccess(collectionRFT, newToken, bob, targetAddress, {Substrate: bob.address}, 100, 'ReFungible');
177 });
178 });
179
180 it('ReFungible: allows to nest/unnest token if Owner-Restricted', async () => {
181 await usingApi(async api => {
182 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
183 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});
184 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
185
186 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
187
188 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionRFT]}});
189
190 // Create a nested token
191 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
192 collectionRFT,
193 targetAddress,
194 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
195 ))).to.not.be.rejected;
196
197 // Create a token to be nested
198 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
199 // Nest
200 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');
201 // Move bundle to different user
202 await transferExpectSuccess(collectionNFT, targetToken, alice, {Substrate: bob.address});
203 // Unnest
204 await transferFromExpectSuccess(collectionRFT, newToken, bob, targetAddress, {Substrate: bob.address}, 100, 'ReFungible');
205 });
206 });
207});
208
209describe('Negative Test: Nesting', async() => {
210 before(async () => {
211 alice = privateKey('//Alice');
212 bob = privateKey('//Bob');
213 });
214
215 // ---------- Non-Fungible ----------
216
217 it('NFT: disallows to nest token if nesting is disabled', async () => {
218 await usingApi(async api => {
219 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
220 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Disabled'});
221 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
222
223 // Try to create a nested token
224 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
225 collection,
226 {Ethereum: tokenIdToAddress(collection, targetToken)},
227 {nft: {const_data: [], variable_data: []}} as any,
228 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);
229
230 // Create a token to be nested
231 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
232 // Try to nest
233 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)}); // todo to.be.rejected
234 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
235 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
236 });
237 });
238
239 it('NFT: disallows to nest token if not Owner', async () => {
240 await usingApi(async api => {
241 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
242 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: 'Owner'});
243
244 await addToAllowListExpectSuccess(alice, collection, bob.address);
245 await enableAllowListExpectSuccess(alice, collection);
246 await enablePublicMintingExpectSuccess(alice, collection);
247
248 // Create a token to attempt to be nested into
249 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');
250
251 // Try to create a nested token in the wrong collection
252 await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
253
254 // Try to create and nest a token in the wrong collection
255 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
256 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
257 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
258 });
259 });
260
261 it('NFT: disallows to nest token if not Owner (Restricted nesting)', async () => {
262 await usingApi(async api => {
263 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
264 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[collection]}});
265
266 await addToAllowListExpectSuccess(alice, collection, bob.address);
267 await enableAllowListExpectSuccess(alice, collection);
268 await enablePublicMintingExpectSuccess(alice, collection);
269
270 // Create a token to attempt to be nested into
271 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');
272
273 // Try to create a nested token in the wrong collection
274 await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
275
276 // Try to create and nest a token in the wrong collection
277 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
278 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
279 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
280 });
281 });
282
283 it('NFT: disallows to nest token to an unlisted collection', async () => {
284 await usingApi(async api => {
285 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
286 await setCollectionLimitsExpectSuccess(alice, collection, {nestingRule: {OwnerRestricted:[]}});
287
288 // Create a token to attempt to be nested into
289 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
290
291 // Try to create a nested token in the wrong collection
292 await createItemExpectFailure(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
293
294 // Try to create and nest a token in the wrong collection
295 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');
296 await transferExpectFailure(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});
297 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});
298 });
299 });
300
301 // ---------- Fungible ----------
302
303 it('Fungible: disallows to nest token if nesting is disabled', async () => {
304 await usingApi(async api => {
305 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
306 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});
307 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
308 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
309
310 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
311
312 // Try to create a nested token
313 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
314 collectionFT,
315 targetAddress,
316 {Fungible: {Value: 10}},
317 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);
318
319 // Create a token to be nested
320 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
321 // Try to nest
322 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
323 });
324 });
325
326 it('Fungible: disallows to nest token if not Owner', async () => {
327 await usingApi(async api => {
328 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
329 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
330
331 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
332 await enableAllowListExpectSuccess(alice, collectionNFT);
333 await enablePublicMintingExpectSuccess(alice, collectionNFT);
334
335 // Create a token to attempt to be nested into
336 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');
337 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
338
339 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
340
341 // Try to create a nested token in the wrong collection
342 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
343 collectionFT,
344 targetAddress,
345 {Fungible: {Value: 10}},
346 ))).to.be.rejected;
347
348 // Try to create and nest a token in the wrong collection
349 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
350 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
351 });
352 });
353
354 it('Fungible: disallows to nest token if not Owner (Restricted nesting)', async () => {
355 await usingApi(async api => {
356 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
357 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}}); // todo clear redundant restrictions
358
359 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
360 await enableAllowListExpectSuccess(alice, collectionNFT);
361 await enablePublicMintingExpectSuccess(alice, collectionNFT);
362
363 // Create a token to attempt to be nested into
364 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');
365 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
366
367 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
368
369 // Try to create a nested token in the wrong collection
370 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
371 collectionFT,
372 targetAddress,
373 {Fungible: {Value: 10}},
374 ))).to.be.rejected;
375
376 // Try to create and nest a token in the wrong collection
377 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
378 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
379 });
380 });
381
382 it('Fungible: disallows to nest token to an unlisted collection', async () => {
383 await usingApi(async api => {
384 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
385 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});
386
387 // Create a token to attempt to be nested into
388 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
389 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
390
391 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
392
393 // Try to create a nested token in the wrong collection
394 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
395 collectionFT,
396 targetAddress,
397 {Fungible: {Value: 10}},
398 ))).to.be.rejected;
399
400 // Try to create and nest a token in the wrong collection
401 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');
402 await transferExpectFailure(collectionFT, newToken, alice, targetAddress, 1);
403 });
404 });
405
406 // ---------- Re-Fungible ----------
407
408 it('ReFungible: disallows to nest token if nesting is disabled', async () => {
409 await usingApi(async api => {
410 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
411 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Disabled'});
412 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
413 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
414
415 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
416
417 // Create a nested token
418 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
419 collectionRFT,
420 targetAddress,
421 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
422 ))).to.be.rejectedWith(/^common\.NestingIsDisabled$/);
423
424 // Create a token to be nested
425 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
426 // Try to nest
427 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
428 });
429 });
430
431 it('ReFungible: disallows to nest token if not Owner', async () => {
432 await usingApi(async api => {
433 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
434 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: 'Owner'});
435
436 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
437 await enableAllowListExpectSuccess(alice, collectionNFT);
438 await enablePublicMintingExpectSuccess(alice, collectionNFT);
439
440 // Create a token to attempt to be nested into
441 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');
442 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
443
444 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
445
446 // Try to create a nested token in the wrong collection
447 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
448 collectionRFT,
449 targetAddress,
450 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
451 ))).to.be.rejected;
452
453 // Try to create and nest a token in the wrong collection
454 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
455 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
456 });
457 });
458
459 it('ReFungible: disallows to nest token if not Owner (Restricted nesting)', async () => {
460 await usingApi(async api => {
461 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
462 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[collectionNFT]}});
463
464 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);
465 await enableAllowListExpectSuccess(alice, collectionNFT);
466 await enablePublicMintingExpectSuccess(alice, collectionNFT);
467
468 // Create a token to attempt to be nested into
469 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');
470 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
471
472 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
473
474 // Try to create a nested token in the wrong collection
475 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
476 collectionRFT,
477 targetAddress,
478 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
479 ))).to.be.rejected;
480
481 // Try to create and nest a token in the wrong collection
482 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
483 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
484 });
485 });
486
487 it('ReFungible: disallows to nest token to an unlisted collection', async () => {
488 await usingApi(async api => {
489 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
490 await setCollectionLimitsExpectSuccess(alice, collectionNFT, {nestingRule: {OwnerRestricted:[]}});
491
492 // Create a token to attempt to be nested into
493 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');
494 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};
495
496 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
497
498 // Try to create a nested token in the wrong collection
499 await expect(executeTransaction(api, alice, api.tx.unique.createItem(
500 collectionRFT,
501 targetAddress,
502 {ReFungible: {const_data: [], variable_data: [], pieces: 100}},
503 ))).to.be.rejected;
33504
34 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});505 // Try to create and nest a token in the wrong collection
506 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');
507 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);
35 });508 });
36 });509 });
37});510});
addedtests/src/nesting/unnest.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/util/helpers.tsdiffbeforeafterboth
943 collectionId: number,943 collectionId: number,
944 tokenId: number,944 tokenId: number,
945 sender: IKeyringPair,945 sender: IKeyringPair,
946 recipient: IKeyringPair,946 recipient: IKeyringPair | CrossAccountId,
947 value: number | bigint = 1,947 value: number | bigint = 1,
948) {948) {
949 await usingApi(async (api: ApiPromise) => {949 await usingApi(async (api: ApiPromise) => {
950 const transferTx = api.tx.unique.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);950 const transferTx = api.tx.unique.transfer(normalizeAccountId(recipient), collectionId, tokenId, value);
951 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;951 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;
952 const result = getGenericResult(events);952 const result = getGenericResult(events);
953 // if (events && Array.isArray(events)) {953 // if (events && Array.isArray(events)) {
1090 return newItemId;1090 return newItemId;
1091}1091}
10921092
1093export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {1093export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {
1094 await usingApi(async (api) => {1094 await usingApi(async (api) => {
1095 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);1095 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);
10961096