1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, CrossAccountId, getCreateCollectionResult} from '../util/helpers';6import {IKeyringPair} from '@polkadot/types/types';78describe('nesting check', () => {9 let alice!: IKeyringPair;10 let nestTarget!: CrossAccountId;11 before(async() => {12 await usingApi(async api => {13 alice = privateKey('//Alice');14 const bob = privateKey('//Bob');15 const events = await executeTransaction(api, alice, api.tx.unique.createCollectionEx({16 mode: 'NFT',17 limits: {18 nestingRule: {OwnerRestricted: []},19 },20 }));21 const collection = getCreateCollectionResult(events).collectionId;22 const token = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: bob.address});23 nestTarget = {Ethereum: tokenIdToAddress(collection, token)};24 });25 });26 27 it('called for fungible', async () => {28 await usingApi(async api => {29 const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible',decimalPoints:0}});30 await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {Fungible: {Value: 1}})))31 .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);3233 await createFungibleItemExpectSuccess(alice, collection, {Value:1n}, {Substrate: alice.address});34 await expect(executeTransaction(api, alice, api.tx.unique.transfer(nestTarget, collection, 0, 1n)))35 .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);36 });37 });3839 it('called for nonfungible', async () => {40 await usingApi(async api => {41 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});42 await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {NFT: {ConstData: [], VariableData: {}}})))43 .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);4445 const token = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});46 await expect(executeTransaction(api, alice, api.tx.unique.transfer(nestTarget, collection, token, 1n)))47 .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);48 });49 });5051 it('called for refungible', async () => {52 await usingApi(async api => {53 const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});54 await expect(executeTransaction(api, alice, api.tx.unique.createItem(collection, nestTarget, {ReFungible: {ConstData: [], VariableData: {}}})))55 .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);5657 const token = await createItemExpectSuccess(alice, collection, 'ReFungible', {Substrate: alice.address});58 await expect(executeTransaction(api, alice, api.tx.unique.transfer(nestTarget, collection, token, 1n)))59 .to.be.rejectedWith(/^common\.SourceCollectionIsNotAllowedToNest$/);60 });61 });62});63