1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';4import {getCreateCollectionResult} from '../util/helpers';5import {IKeyringPair} from '@polkadot/types/types';6import {strToUTF16} from '../util/util';7import waitNewBlocks from '../substrate/wait-new-blocks';89import find from 'find-process';101112describe.skip('Migration testing for pallet-common', () => {13 let alice: IKeyringPair;1415 before(async() => {16 await usingApi(async () => {17 alice = privateKey('//Alice');18 });19 });2021 it('Preserves collection settings after migration', async () => {22 let oldVersion: number;23 let collectionId: number;24 let collectionOld: any;2526 await usingApi(async api => {27 28 const tx = api.tx.unique.createCollectionEx({29 mode: 'NFT',30 access: 'AllowList',31 name: strToUTF16('Mojave Pictures'),32 description: strToUTF16('$2.2 billion power plant!'),33 tokenPrefix: '0x0002030',34 offchainSchema: '0x111111',35 schemaVersion: 'Unique',36 limits: {37 accountTokenOwnershipLimit: 3,38 },39 constOnChainSchema: '0x333333',40 metaUpdatePermission: 'Admin',41 });42 const events = await submitTransactionAsync(alice, tx);43 const result = getCreateCollectionResult(events);44 collectionId = result.collectionId;4546 47 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4849 50 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;51 });5253 console.log(`Now waiting for the parachain upgrade from ${oldVersion!}...`);5455 let newVersion = oldVersion!;56 let connectionFailCounter = 0;5758 59 find('name', 'polkadot-launch', true).then((list) => {60 for (const proc of list) {61 process.kill(proc.pid, 'SIGUSR1');62 }63 });6465 66 {67 68 const stdlog = console.warn.bind(console);69 let warnCount = 0;70 console.warn = function(...args){71 if (arguments.length <= 2 || !args[2].includes('RPC methods not decorated')) {72 warnCount++;73 stdlog.apply(console, args as any);74 }75 };7677 let oldWarnCount = 0;78 while (newVersion == oldVersion! && connectionFailCounter < 2) {79 try {80 await usingApi(async api => {81 await waitNewBlocks(api);82 newVersion = (api.consts.system.version.toJSON() as any).specVersion;83 if (warnCount > oldWarnCount) {84 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);85 oldWarnCount = warnCount;86 }87 await new Promise(resolve => setTimeout(resolve, 6000));88 });89 } catch (_) {90 connectionFailCounter++;91 await new Promise(resolve => setTimeout(resolve, 12000));92 }93 }94 }9596 await usingApi(async api => {97 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;9899 100 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');101 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');102103 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);104 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);105 expect(collectionNew).to.have.nested.property('limits.nestingRule');106107 108 delete collectionNew.limits.nestingRule;109 delete collectionOld.constOnChainSchema;110 delete collectionOld.offchainSchema;111112 expect(collectionNew).to.be.deep.equal(collectionOld);113 });114 });115});