difftreelog
fix rft admin can unnest
in: master
2 files changed
pallets/refungible/src/lib.rsdiffbeforeafterboth1178 collection.check_allowlist(spender)?;1178 collection.check_allowlist(spender)?;1179 }1179 }11801181 if collection.limits.owner_can_transfer() && collection.is_owner_or_admin(spender) {1182 return Ok(None);1183 }11841180 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?tests/src/nesting/nest.test.tsdiffbeforeafterboth161617import {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';192020describe('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 });144145336 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);337 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);337 });338 });339340 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);353354 const children = await targetNft.getChildren();355356 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 }365366 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 });373374 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});375376 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});377 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});378379 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);380 await checkNestedRft({381 expectedBalance: 5n,382 childrenShouldPresent: true,383 nestedRft,384 targetNft,385 });386387 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);395396 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 });405406 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});414415 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});416417 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});418 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});419420 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);421 await checkNestedRft({422 expectedBalance: 5n,423 childrenShouldPresent: true,424 nestedRft,425 targetNft,426 });427428 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);436437 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 });446447 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 });458459 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});460461 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});462 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});463464 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);465 await checkNestedRft({466 expectedBalance: 5n,467 childrenShouldPresent: true,468 nestedRft,469 targetNft,470 });471472 await nestedRft.burnFrom(alice, targetNft.nestingAccount(), 2n);473 await checkNestedRft({474 expectedBalance: 3n,475 childrenShouldPresent: true,476 nestedRft,477 targetNft,478 });479480 await nestedRft.burnFrom(alice, targetNft.nestingAccount(), 3n);481 await checkNestedRft({482 expectedBalance: 0n,483 childrenShouldPresent: false,484 nestedRft,485 targetNft,486 });487488 // Check if we can burn target NFT when all nested RFTs are gone489 await targetNft.burnFrom(alice, {Substrate: charlie.address});490 });491492 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});505506 await collectionNFT.setPermissions(alice, {nesting: {tokenOwner: true}});507508 const targetNft = await collectionNFT.mintToken(alice, {Substrate: charlie.address});509 const nestedRft = await collectionRFT.mintToken(alice, 5n, {Substrate: charlie.address});510511 await nestedRft.transfer(charlie, targetNft.nestingAccount(), 5n);512 await checkNestedRft({513 expectedBalance: 5n,514 childrenShouldPresent: true,515 nestedRft,516 targetNft,517 });518519 await nestedRft.burnFrom(bob, targetNft.nestingAccount(), 2n);520 await checkNestedRft({521 expectedBalance: 3n,522 childrenShouldPresent: true,523 nestedRft,524 targetNft,525 });526527 await nestedRft.burnFrom(bob, targetNft.nestingAccount(), 3n);528 await checkNestedRft({529 expectedBalance: 0n,530 childrenShouldPresent: false,531 nestedRft,532 targetNft,533 });534535 // Check if we can burn target NFT when all nested RFTs are gone536 await targetNft.burnFrom(bob, {Substrate: charlie.address});537 });338});538});339539340describe('Negative Test: Nesting', () => {540describe('Negative Test: Nesting', () => {