git.delta.rocks / unique-network / refs/commits / 2332519c8f48

difftreelog

source

js-packages/tests/src/sub/nesting/admin.test.ts4.4 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {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      // Collection has permission for collectionAdmin to nest:42      await collectionA.setPermissions(alice, {nesting:43        {collectionAdmin: true, restricted: testCase.restricted ? [collectionA.collectionId, collectionB.collectionId] : null},44      });45      // Token for nesting in from collectionA:46      const targetTokenA = await collectionA.mintToken(alice, {Substrate: charlie.address});4748      // 1. Create an immediately nested tokens:49      // 1.1 From own collection:50      const nestedTokenA = await collectionA.mintToken(bob, targetTokenA.nestingAccount());51      // 1.2 From different collection: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      // 2. Create a token to be nested and nest:59      const newNestedTokenA = await collectionA.mintToken(bob);60      const newNestedTokenB = await collectionB.mintToken(bob);61      // 2.1 From own collection:62      await newNestedTokenA.nest(bob, targetTokenA);63      // 2.2 From different collection: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    // Admin can create an immediately nested token: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    // Owner can create and and nest: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});