1import {expect} from 'chai';2import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';3import {getCreateCollectionResult} from '../util/helpers';4import {IKeyringPair} from '@polkadot/types/types';5import {strToUTF16} from '../util/util';6import waitNewBlocks from '../substrate/wait-new-blocks';78import find from 'find-process';91011describe.skip('Migration testing for pallet-common', () => {12 let alice: IKeyringPair;1314 before(async() => {15 await usingApi(async (api, privateKeyWrapper) => {16 alice = privateKeyWrapper('//Alice');17 });18 });1920 it('Preserves collection settings after migration', async () => {21 let oldVersion: number;22 let collectionId: number;23 let collectionOld: any;2425 await usingApi(async api => {26 27 const tx = api.tx.unique.createCollectionEx({28 mode: 'NFT',29 access: 'AllowList',30 name: strToUTF16('Mojave Pictures'),31 description: strToUTF16('$2.2 billion power plant!'),32 tokenPrefix: '0x0002030',33 34 35 limits: {36 accountTokenOwnershipLimit: 3,37 },38 39 });40 const events = await submitTransactionAsync(alice, tx);41 const result = getCreateCollectionResult(events);42 collectionId = result.collectionId;4344 45 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4647 48 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;49 });5051 console.log(`Now waiting for the parachain upgrade from ${oldVersion!}...`);5253 let newVersion = oldVersion!;54 let connectionFailCounter = 0;5556 57 find('name', 'polkadot-launch', true).then((list) => {58 for (const proc of list) {59 process.kill(proc.pid, 'SIGUSR1');60 }61 });6263 64 {65 66 const stdlog = console.warn.bind(console);67 let warnCount = 0;68 console.warn = function(...args){69 if (arguments.length <= 2 || !args[2].includes('RPC methods not decorated')) {70 warnCount++;71 stdlog.apply(console, args as any);72 }73 };7475 let oldWarnCount = 0;76 while (newVersion == oldVersion! && connectionFailCounter < 2) {77 try {78 await usingApi(async api => {79 await waitNewBlocks(api);80 newVersion = (api.consts.system.version.toJSON() as any).specVersion;81 if (warnCount > oldWarnCount) {82 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);83 oldWarnCount = warnCount;84 }85 await new Promise(resolve => setTimeout(resolve, 6000));86 });87 } catch (_) {88 connectionFailCounter++;89 await new Promise(resolve => setTimeout(resolve, 12000));90 }91 }92 }9394 await usingApi(async api => {95 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;9697 98 99 100101 102 103 expect(collectionNew).to.have.nested.property('limits.nestingRule');104105 106 delete collectionNew.limits.nestingRule;107 108 109110 expect(collectionNew).to.be.deep.equal(collectionOld);111 });112 });113});