1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '../../util';1920describe('Nesting by collection admin', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;23 let charlie: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = await privateKey({url: import.meta.url});28 [alice, bob, charlie] = await helper.arrange.createAccounts([200n, 10n, 10n], donor);29 });30 });3132 [33 {restricted: true},34 {restricted: false},35 ].map(testCase => {36 itSub(`can nest tokens if "collectionAdmin" permission set ${testCase.restricted ? ', in restricted mode' : ''}`, async ({helper}) => {37 const collectionA = await helper.nft.mintCollection(alice);38 await collectionA.addAdmin(alice, {Substrate: bob.address});39 const collectionB = await helper.nft.mintCollection(alice);40 await collectionB.addAdmin(alice, {Substrate: bob.address});41 42 await collectionA.setPermissions(alice, {nesting:43 {collectionAdmin: true, restricted: testCase.restricted ? [collectionA.collectionId, collectionB.collectionId] : null},44 });45 46 const targetTokenA = await collectionA.mintToken(alice, {Substrate: charlie.address});4748 49 50 const nestedTokenA = await collectionA.mintToken(bob, targetTokenA.nestingAccount());51 52 const nestedTokenB = await collectionB.mintToken(bob, targetTokenA.nestingAccount());53 expect(await nestedTokenA.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});54 expect(await nestedTokenA.getOwner()).to.be.deep.equal(targetTokenA.nestingAccount().toLowerCase());55 expect(await nestedTokenB.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});56 expect(await nestedTokenB.getOwner()).to.be.deep.equal(targetTokenA.nestingAccount().toLowerCase());5758 59 const newNestedTokenA = await collectionA.mintToken(bob);60 const newNestedTokenB = await collectionB.mintToken(bob);61 62 await newNestedTokenA.nest(bob, targetTokenA);63 64 await newNestedTokenB.nest(bob, targetTokenA);65 expect(await newNestedTokenB.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});66 expect(await newNestedTokenB.getOwner()).to.be.deep.equal(targetTokenA.nestingAccount().toLowerCase());67 });68 });6970 itSub('can operate together with token owner if "collectionAdmin" and "tokenOwner" permissions set', async ({helper}) => {71 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true}}});72 await collection.addAdmin(alice, {Substrate: bob.address});73 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});7475 76 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());77 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});78 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());7980 81 const newToken = await collection.mintToken(alice, {Substrate: charlie.address});82 await newToken.nest(charlie, targetToken);83 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});84 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());85 });86});