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

difftreelog

source

tests/src/nesting/graphs.test.ts2.5 KiBsourcehistory
1import {ApiPromise} from '@polkadot/api';2import {IKeyringPair} from '@polkadot/types/types';3import {expect} from 'chai';4import {tokenIdToCross} from '../eth/util/helpers';5import privateKey from '../substrate/privateKey';6import usingApi, {executeTransaction} from '../substrate/substrate-api';7import {getCreateCollectionResult, transferExpectSuccess} from '../util/helpers';89/**10 * ```dot11 * 4 -> 3 -> 2 -> 112 * 7 -> 6 -> 5 -> 213 * 8 -> 514 * ```15 */16async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {17  const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', limits: {nestingRule: 'Owner'}}));18  const {collectionId} = getCreateCollectionResult(events);1920  await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})}));2122  await transferExpectSuccess(collectionId, 8, sender, tokenIdToCross(collectionId, 5));2324  await transferExpectSuccess(collectionId, 7, sender, tokenIdToCross(collectionId, 6));25  await transferExpectSuccess(collectionId, 6, sender, tokenIdToCross(collectionId, 5));26  await transferExpectSuccess(collectionId, 5, sender, tokenIdToCross(collectionId, 2));2728  await transferExpectSuccess(collectionId, 4, sender, tokenIdToCross(collectionId, 3));29  await transferExpectSuccess(collectionId, 3, sender, tokenIdToCross(collectionId, 2));30  await transferExpectSuccess(collectionId, 2, sender, tokenIdToCross(collectionId, 1));3132  return collectionId;33}3435describe('Graphs', () => {36  it('Ouroboros can\'t be created in a complex graph', async () => {37    await usingApi(async api => {38      const alice = privateKey('//Alice');39      const collection = await buildComplexObjectGraph(api, alice);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.transfer(tokenIdToCross(collection, 8), collection, 2, 1)),53        'third transaction',54      ).to.be.rejectedWith(/structure\.OuroborosDetected/);55    });56  });57});