git.delta.rocks / unique-network / refs/commits / 727b395482d9

difftreelog

test(nesting-admin) use bob as admin, charlie as mere recipient, revert charlie reshuffle

Fahrrader2022-06-14parent: #3a12417.patch.diff
in: master

1 file changed

modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
162 await usingApi(async api => {162 await usingApi(async api => {
163 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});163 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
164 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});164 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});
165 await addCollectionAdminExpectSuccess(alice, collection, charlie.address);165 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
166 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');166 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT', charlie.address);
167167
168 // Create a nested token168 // Create a nested token
169 const nestedToken = await createItemExpectSuccess(charlie, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});169 const nestedToken = await createItemExpectSuccess(bob, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
170 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});170 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: charlie.address});
171 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});171 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
172172
173 // Create a token to be nested and nest173 // Create a token to be nested and nest
174 const newToken = await createItemExpectSuccess(charlie, collection, 'NFT');174 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');
175 await transferExpectSuccess(collection, newToken, charlie, {Ethereum: tokenIdToAddress(collection, targetToken)});175 await transferExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)});
176 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});176 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});
177 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});177 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
178 });178 });
179 });179 });
180
181 it('Admin (NFT): Admin and Token Owner can operate together', async () => {
182 await usingApi(async api => {
183 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
184 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, collectionAdmin: true}});
185 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
186 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT', charlie.address);
187
188 // Create a nested token by an administrator
189 const nestedToken = await createItemExpectSuccess(bob, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});
190 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: charlie.address});
191 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});
192
193 // Create a token and allow the owner to nest too
194 const newToken = await createItemExpectSuccess(alice, collection, 'NFT', charlie.address);
195 await transferExpectSuccess(collection, newToken, charlie, {Ethereum: tokenIdToAddress(collection, nestedToken)});
196 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});
197 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, nestedToken).toLowerCase()});
198 });
199 });
180200
181 it('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async () => {201 it('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async () => {
182 await usingApi(async api => {202 await usingApi(async api => {
183 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});203 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
184 await addCollectionAdminExpectSuccess(alice, collectionA, charlie.address);204 await addCollectionAdminExpectSuccess(alice, collectionA, bob.address);
185 const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});205 const collectionB = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
186 await addCollectionAdminExpectSuccess(alice, collectionB, charlie.address);206 await addCollectionAdminExpectSuccess(alice, collectionB, bob.address);
187 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {collectionAdmin: true, restricted:[collectionA, collectionB]}});207 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {collectionAdmin: true, restricted:[collectionA, collectionB]}});
188 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');208 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT', charlie.address);
189209
190 // Create a nested token210 // Create a nested token
191 const nestedToken = await createItemExpectSuccess(charlie, collectionB, 'NFT', {Ethereum: tokenIdToAddress(collectionA, targetToken)});211 const nestedToken = await createItemExpectSuccess(bob, collectionB, 'NFT', {Ethereum: tokenIdToAddress(collectionA, targetToken)});
192 expect(await getTopmostTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Substrate: alice.address});212 expect(await getTopmostTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Substrate: charlie.address});
193 expect(await getTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});213 expect(await getTokenOwner(api, collectionB, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});
194214
195 // Create a token to be nested and nest215 // Create a token to be nested and nest
196 const newToken = await createItemExpectSuccess(charlie, collectionB, 'NFT');216 const newToken = await createItemExpectSuccess(bob, collectionB, 'NFT');
197 await transferExpectSuccess(collectionB, newToken, charlie, {Ethereum: tokenIdToAddress(collectionA, targetToken)});217 await transferExpectSuccess(collectionB, newToken, bob, {Ethereum: tokenIdToAddress(collectionA, targetToken)});
198 expect(await getTopmostTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Substrate: alice.address});218 expect(await getTopmostTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Substrate: charlie.address});
199 expect(await getTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});219 expect(await getTokenOwner(api, collectionB, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collectionA, targetToken).toLowerCase()});
200 });220 });
201 });221 });
340 await usingApi(async (_, privateKeyWrapper) => {360 await usingApi(async (_, privateKeyWrapper) => {
341 alice = privateKeyWrapper('//Alice');361 alice = privateKeyWrapper('//Alice');
342 bob = privateKeyWrapper('//Bob');362 bob = privateKeyWrapper('//Bob');
343 charlie = privateKeyWrapper('//Charlie');
344 });363 });
345 });364 });
346365
382 await usingApi(async api => {401 await usingApi(async api => {
383 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});402 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
384 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});403 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});
385 await addCollectionAdminExpectSuccess(alice, collection, charlie.address);404 await addCollectionAdminExpectSuccess(alice, collection, bob.address);
386 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');405 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
387406
388 // Try to create a nested token as collection admin when it's disallowed407 // Try to create a nested token as collection admin when it's disallowed
389 await expect(executeTransaction(api, charlie, api.tx.unique.createItem(408 await expect(executeTransaction(api, bob, api.tx.unique.createItem(
390 collection,409 collection,
391 {Ethereum: tokenIdToAddress(collection, targetToken)},410 {Ethereum: tokenIdToAddress(collection, targetToken)},
392 {nft: {const_data: [], variable_data: []}} as any,411 {nft: {const_data: [], variable_data: []}} as any,
393 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);412 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
394413
395 // Try to create and nest a token in the wrong collection414 // Try to create and nest a token in the wrong collection
396 const newToken = await createItemExpectSuccess(charlie, collection, 'NFT');415 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');
397 await expect(executeTransaction(416 await expect(executeTransaction(
398 api, 417 api,
399 charlie, 418 bob,
400 api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1),419 api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1),
401 ), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);420 ), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
402 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});421 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});
403 });422 });
404 });423 });
405424
406 it('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async () => {425 it('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async () => {
407 await usingApi(async api => {426 await usingApi(async api => {
408 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});427 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
409 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});428 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});
410 await addToAllowListExpectSuccess(alice, collection, charlie.address);429 await addToAllowListExpectSuccess(alice, collection, bob.address);
411 await enableAllowListExpectSuccess(alice, collection);430 await enableAllowListExpectSuccess(alice, collection);
412 await enablePublicMintingExpectSuccess(alice, collection);431 await enablePublicMintingExpectSuccess(alice, collection);
413 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');432 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');
414433
415 // Try to create a nested token as collection admin when it's disallowed434 // Try to create a nested token as collection admin when it's disallowed
416 await expect(executeTransaction(api, charlie, api.tx.unique.createItem(435 await expect(executeTransaction(api, bob, api.tx.unique.createItem(
417 collection,436 collection,
418 {Ethereum: tokenIdToAddress(collection, targetToken)},437 {Ethereum: tokenIdToAddress(collection, targetToken)},
419 {nft: {const_data: [], variable_data: []}} as any,438 {nft: {const_data: [], variable_data: []}} as any,
420 )), 'while creating nested token').to.be.rejectedWith(/common\.AddressNotInAllowlist/); // todo is this right?439 )), 'while creating nested token').to.be.rejectedWith(/common\.AddressNotInAllowlist/); // todo is this right?
421440
422 // Try to create and nest a token in the wrong collection441 // Try to create and nest a token in the wrong collection
423 const newToken = await createItemExpectSuccess(charlie, collection, 'NFT');442 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');
424 await expect(executeTransaction(443 await expect(executeTransaction(
425 api, 444 api,
426 charlie, 445 bob,
427 api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1),446 api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1),
428 ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);447 ), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
429 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});448 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});
430 });449 });
431 });450 });
432451
435 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});454 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
436 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});455 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {collectionAdmin: true}});
437456
438 await addToAllowListExpectSuccess(alice, collection, charlie.address);457 await addToAllowListExpectSuccess(alice, collection, bob.address);
439 await enableAllowListExpectSuccess(alice, collection);458 await enableAllowListExpectSuccess(alice, collection);
440 await enablePublicMintingExpectSuccess(alice, collection);459 await enablePublicMintingExpectSuccess(alice, collection);
441460
442 // Create a token to attempt to be nested into461 // Create a token to attempt to be nested into
443 const targetToken = await createItemExpectSuccess(charlie, collection, 'NFT');462 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');
444 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()};463 const targetAddress = {Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()};
445464
446 // Try to nest somebody else's token465 // Try to nest somebody else's token
447 const newToken = await createItemExpectSuccess(charlie, collection, 'NFT');466 const newToken = await createItemExpectSuccess(bob, collection, 'NFT');
448 await expect(executeTransaction(467 await expect(executeTransaction(
449 api, 468 api,
450 alice, 469 alice,
451 api.tx.unique.transfer(targetAddress, collection, newToken, 1),470 api.tx.unique.transfer(targetAddress, collection, newToken, 1),
452 ), 'while nesting another\'s token token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);471 ), 'while nesting another\'s token token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
453 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: charlie.address});472 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});
454473
455 // Nest a token as admin and try to unnest it, now belonging to someone else474 // Nest a token as admin and try to unnest it, now belonging to someone else
456 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);475 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', targetAddress);
460 api.tx.unique.transferFrom(targetAddress, normalizeAccountId(alice), collection, nestedToken, 1),479 api.tx.unique.transferFrom(targetAddress, normalizeAccountId(alice), collection, nestedToken, 1),
461 ), 'while unnesting another\'s token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);480 ), 'while unnesting another\'s token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);
462 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal(targetAddress);481 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal(targetAddress);
463 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: charlie.address});482 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});
464 });483 });
465 });484 });
466485