git.delta.rocks / unique-network / refs/commits / 6bd537d868d3

difftreelog

source

tests/src/nesting/graphs.test.ts2.6 KiBsourcehistory
1import {ApiPromise} from '@polkadot/api';2import {IKeyringPair} from '@polkadot/types/types';3import {expect} from 'chai';4import {tokenIdToCross} from '../eth/util/helpers';5import usingApi, {executeTransaction} from '../substrate/substrate-api';6import {getCreateCollectionResult, transferExpectSuccess, setCollectionLimitsExpectSuccess} from '../util/helpers';78/**9 * ```dot10 * 4 -> 3 -> 2 -> 111 * 7 -> 6 -> 5 -> 212 * 8 -> 513 * ```14 */15async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {16  const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', permissions: {nesting: {tokenOwner: true}}}));17  const {collectionId} = getCreateCollectionResult(events);1819  await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})}));2021  await transferExpectSuccess(collectionId, 8, sender, tokenIdToCross(collectionId, 5));2223  await transferExpectSuccess(collectionId, 7, sender, tokenIdToCross(collectionId, 6));24  await transferExpectSuccess(collectionId, 6, sender, tokenIdToCross(collectionId, 5));25  await transferExpectSuccess(collectionId, 5, sender, tokenIdToCross(collectionId, 2));2627  await transferExpectSuccess(collectionId, 4, sender, tokenIdToCross(collectionId, 3));28  await transferExpectSuccess(collectionId, 3, sender, tokenIdToCross(collectionId, 2));29  await transferExpectSuccess(collectionId, 2, sender, tokenIdToCross(collectionId, 1));3031  return collectionId;32}3334describe('Graphs', () => {35  it('Ouroboros can\'t be created in a complex graph', async () => {36    await usingApi(async (api, privateKeyWrapper) => {37      const alice = privateKeyWrapper('//Alice');38      const collection = await buildComplexObjectGraph(api, alice);39      const tokenTwoParent = tokenIdToCross(collection, 1);4041      // to self42      await expect(43        executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)),44        'first transaction',  45      ).to.be.rejectedWith(/structure\.OuroborosDetected/);46      // to nested part of graph47      await expect(48        executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)),49        'second transaction',50      ).to.be.rejectedWith(/structure\.OuroborosDetected/);51      await expect(52        executeTransaction(api, alice, api.tx.unique.transferFrom(tokenTwoParent, tokenIdToCross(collection, 8), collection, 2, 1)),53        'third transaction',54      ).to.be.rejectedWith(/structure\.OuroborosDetected/);55    });56  });57});