git.delta.rocks / unique-network / refs/commits / f78f490e83cf

difftreelog

source

js-packages/tests/sub/nesting/graphs.test.ts3.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 type {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '@unique/test-utils/util.js';19import {UniqueHelper, UniqueNFTCollection, UniqueNFToken} from '@unique-nft/playgrounds/unique.js';2021/**22 * ```dot23 * 4 -> 3 -> 2 -> 124 * 7 -> 6 -> 5 -> 225 * 8 -> 526 * ```27 */28async function buildComplexObjectGraph(helper: UniqueHelper, sender: IKeyringPair): Promise<[UniqueNFTCollection,UniqueNFToken[]]> {29  const collection = await helper.nft.mintCollection(sender, {permissions: {nesting: {tokenOwner: true}}});30  const tokens = await collection.mintMultipleTokens(sender, Array(8).fill({owner: {Substrate: sender.address}}));3132  await tokens[7].nest(sender, tokens[4]);33  await tokens[6].nest(sender, tokens[5]);34  await tokens[5].nest(sender, tokens[4]);35  await tokens[4].nest(sender, tokens[1]);36  await tokens[3].nest(sender, tokens[2]);37  await tokens[2].nest(sender, tokens[1]);38  await tokens[1].nest(sender, tokens[0]);3940  return [collection, tokens];41}4243describe('Graphs', () => {44  let alice: IKeyringPair;4546  before(async () => {47    await usingPlaygrounds(async (helper, privateKey) => {48      const donor = await privateKey({url: import.meta.url});49      [alice] = await helper.arrange.createAccounts([10n], donor);50    });51  });5253  itSub('Ouroboros can\'t be created in a complex graph', async ({helper}) => {54    const [collection, tokens] = await buildComplexObjectGraph(helper, alice);5556    await collection.setPermissions(alice, {nesting: {collectionAdmin: false, tokenOwner: true}});5758    // [token owner] to self59    await expect(60      tokens[0].nest(alice, tokens[0]),61      '[token owner] self-nesting is forbidden',62    ).to.be.rejectedWith(/structure\.OuroborosDetected/);63    // [token owner] to nested part of graph64    await expect(65      tokens[0].nest(alice, tokens[4]),66      '[token owner] cannot nest the root node into an internal node',67    ).to.be.rejectedWith(/structure\.OuroborosDetected/);68    await expect(69      tokens[1].transferFrom(alice, tokens[0].nestingAccount(), tokens[7].nestingAccount()),70      '[token owner] cannot nest higher internal node into lower internal node',71    ).to.be.rejectedWith(/structure\.OuroborosDetected/);7273    await collection.setPermissions(alice, {nesting: {collectionAdmin: true, tokenOwner: false}});7475    // [collection owner] to self76    await expect(77      tokens[0].nest(alice, tokens[0]),78      '[collection owner] self-nesting is forbidden',79    ).to.be.rejectedWith(/structure\.OuroborosDetected/);80    // [collection owner] to nested part of graph81    await expect(82      tokens[0].nest(alice, tokens[4]),83      '[collection owner] cannot nest the root node into an internal node',84    ).to.be.rejectedWith(/structure\.OuroborosDetected/);85  });86});