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} from '../util/helpers';789101112131415async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {16 const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT', permissions: {nesting: 'Owner'}}));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);3940 41 await expect(42 executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)),43 'first transaction', 44 ).to.be.rejectedWith(/structure\.OuroborosDetected/);45 46 await expect(47 executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)),48 'second transaction',49 ).to.be.rejectedWith(/structure\.OuroborosDetected/);50 await expect(51 executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)),52 'third transaction',53 ).to.be.rejectedWith(/structure\.OuroborosDetected/);54 });55 });56});