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

difftreelog

source

tests/src/nesting/graphs.test.ts2.3 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'}));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 graph', async () => {37    await usingApi(async api => {38      const alice = privateKey('//Alice');39      const collection = await buildComplexObjectGraph(api, alice);4041      // to self42      await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)))43        .to.be.rejectedWith(/structure\.OuroborosDetected/);44      // to nested part of graph45      await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)))46        .to.be.rejectedWith(/structure\.OuroborosDetected/);47      await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)))48        .to.be.rejectedWith(/structure\.OuroborosDetected/);49    });50  });51});