git.delta.rocks / unique-network / refs/commits / 670ea143e393

difftreelog

fix rft admin can unnest

Daniel Shiposha2023-01-13parent: #5c9ffb7.patch.diff
in: master

2 files changed

modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
1178 collection.check_allowlist(spender)?;1178 collection.check_allowlist(spender)?;
1179 }1179 }
1180
1181 if collection.limits.owner_can_transfer() && collection.is_owner_or_admin(spender) {
1182 return Ok(None);
1183 }
1184
1180 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {1185 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {
1181 // TODO: should collection owner be allowed to perform this transfer?1186 // TODO: should collection owner be allowed to perform this transfer?
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {expect, itSub, Pallets, usingPlaygrounds} from '../util';18import {expect, itSub, Pallets, usingPlaygrounds} from '../util';
19import {UniqueNFToken, UniqueRFToken} from '../util/playgrounds/unique';
1920
20describe('Integration Test: Composite nesting tests', () => {21describe('Integration Test: Composite nesting tests', () => {
21 let alice: IKeyringPair;22 let alice: IKeyringPair;
138 before(async () => {139 before(async () => {
139 await usingPlaygrounds(async (helper, privateKey) => {140 await usingPlaygrounds(async (helper, privateKey) => {
140 const donor = await privateKey({filename: __filename});141 const donor = await privateKey({filename: __filename});
141 [alice, bob, charlie] = await helper.arrange.createAccounts([50n, 10n, 10n], donor);142 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 20n, 20n], donor);
142 });143 });
143 });144 });
144145
336 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);337 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
337 });338 });
339
340 async function checkNestedRft({
341 expectedBalance,
342 childrenShouldPresent,
343 nestedRft,
344 targetNft,
345 }: {
346 expectedBalance: bigint,
347 childrenShouldPresent: boolean,
348 nestedRft: UniqueRFToken,
349 targetNft: UniqueNFToken,
350 }) {
351 const balance = await nestedRft.getBalance(targetNft.nestingAccount());
352 expect(balance).to.be.equal(expectedBalance);
353
354 const children = await targetNft.getChildren();
355
356 if (childrenShouldPresent) {
357 expect(children[0]).to.be.deep.equal({
358 collectionId: nestedRft.collectionId,
359 tokenId: nestedRft.tokenId,
360 });
361 } else {
362 expect(children.length).to.be.equal(0);
363 }
364 }
365
366 itSub.ifWithPallets('ReFungible: allows a collection owner to transfer nested token', [Pallets.ReFungible], async ({helper}) => {
367 const collectionNFT = await helper.nft.mintCollection(alice);
368 const collectionRFT = await helper.rft.mintCollection(alice, {
369 limits: {
370 ownerCanTransfer: true,
371 },
372 });
373
374 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});
375
376 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
377 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});
378
379 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);
380 await checkNestedRft({
381 expectedBalance: 5n,
382 childrenShouldPresent: true,
383 nestedRft,
384 targetNft,
385 });
386
387 await nestedRft.transferFrom(alice, targetNft.nestingAccount(), {Substrate: bob.address}, 2n);
388 await checkNestedRft({
389 expectedBalance: 3n,
390 childrenShouldPresent: true,
391 nestedRft,
392 targetNft,
393 });
394 expect(await nestedRft.getBalance({Substrate: bob.address})).to.be.equal(2n);
395
396 await nestedRft.transferFrom(alice, targetNft.nestingAccount(), {Substrate: bob.address}, 3n);
397 await checkNestedRft({
398 expectedBalance: 0n,
399 childrenShouldPresent: false,
400 nestedRft,
401 targetNft,
402 });
403 expect(await nestedRft.getBalance({Substrate: bob.address})).to.be.equal(5n);
404 });
405
406 itSub.ifWithPallets('ReFungible: allows a collection admin to transfer nested token', [Pallets.ReFungible], async ({helper}) => {
407 const collectionNFT = await helper.nft.mintCollection(alice);
408 const collectionRFT = await helper.rft.mintCollection(alice, {
409 limits: {
410 ownerCanTransfer: true,
411 },
412 });
413 await collectionRFT.addAdmin(alice, {Substrate: bob.address});
414
415 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});
416
417 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
418 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});
419
420 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);
421 await checkNestedRft({
422 expectedBalance: 5n,
423 childrenShouldPresent: true,
424 nestedRft,
425 targetNft,
426 });
427
428 await nestedRft.transferFrom(bob, targetNft.nestingAccount(), {Substrate: bob.address}, 2n);
429 await checkNestedRft({
430 expectedBalance: 3n,
431 childrenShouldPresent: true,
432 nestedRft,
433 targetNft,
434 });
435 expect(await nestedRft.getBalance({Substrate: bob.address})).to.be.equal(2n);
436
437 await nestedRft.transferFrom(bob, targetNft.nestingAccount(), {Substrate: bob.address}, 3n);
438 await checkNestedRft({
439 expectedBalance: 0n,
440 childrenShouldPresent: false,
441 nestedRft,
442 targetNft,
443 });
444 expect(await nestedRft.getBalance({Substrate: bob.address})).to.be.equal(5n);
445 });
446
447 itSub.ifWithPallets('ReFungible: allows a collection owner to burn nested token', [Pallets.ReFungible], async ({helper}) => {
448 const collectionNFT = await helper.nft.mintCollection(alice, {
449 limits: {
450 ownerCanTransfer: true,
451 },
452 });
453 const collectionRFT = await helper.rft.mintCollection(alice, {
454 limits: {
455 ownerCanTransfer: true,
456 },
457 });
458
459 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});
460
461 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
462 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});
463
464 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);
465 await checkNestedRft({
466 expectedBalance: 5n,
467 childrenShouldPresent: true,
468 nestedRft,
469 targetNft,
470 });
471
472 await nestedRft.burnFrom(alice, targetNft.nestingAccount(), 2n);
473 await checkNestedRft({
474 expectedBalance: 3n,
475 childrenShouldPresent: true,
476 nestedRft,
477 targetNft,
478 });
479
480 await nestedRft.burnFrom(alice, targetNft.nestingAccount(), 3n);
481 await checkNestedRft({
482 expectedBalance: 0n,
483 childrenShouldPresent: false,
484 nestedRft,
485 targetNft,
486 });
487
488 // Check if we can burn target NFT when all nested RFTs are gone
489 await targetNft.burnFrom(alice, {Substrate: charlie.address});
490 });
491
492 itSub.ifWithPallets('ReFungible: allows a collection admin to burn nested token', [Pallets.ReFungible], async ({helper}) => {
493 const collectionNFT = await helper.nft.mintCollection(alice, {
494 limits: {
495 ownerCanTransfer: true,
496 },
497 });
498 const collectionRFT = await helper.rft.mintCollection(alice, {
499 limits: {
500 ownerCanTransfer: true,
501 },
502 });
503 await collectionNFT.addAdmin(alice, {Substrate: bob.address});
504 await collectionRFT.addAdmin(alice, {Substrate: bob.address});
505
506 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});
507
508 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
509 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});
510
511 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);
512 await checkNestedRft({
513 expectedBalance: 5n,
514 childrenShouldPresent: true,
515 nestedRft,
516 targetNft,
517 });
518
519 await nestedRft.burnFrom(bob, targetNft.nestingAccount(), 2n);
520 await checkNestedRft({
521 expectedBalance: 3n,
522 childrenShouldPresent: true,
523 nestedRft,
524 targetNft,
525 });
526
527 await nestedRft.burnFrom(bob, targetNft.nestingAccount(), 3n);
528 await checkNestedRft({
529 expectedBalance: 0n,
530 childrenShouldPresent: false,
531 nestedRft,
532 targetNft,
533 });
534
535 // Check if we can burn target NFT when all nested RFTs are gone
536 await targetNft.burnFrom(bob, {Substrate: charlie.address});
537 });
338});538});
339539
340describe('Negative Test: Nesting', () => {540describe('Negative Test: Nesting', () => {