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('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', 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 while (newVersion == oldVersion! && connectionFailCounter < 2) {67 try {68 await usingApi(async api => {69 await waitNewBlocks(api);70 newVersion = (api.consts.system.version.toJSON() as any).specVersion;71 });72 } catch (_) {73 connectionFailCounter++;74 await new Promise(resolve => setTimeout(resolve, 12000));75 }76 }7778 await usingApi(async api => {79 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;8081 82 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');83 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');8485 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);86 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);87 expect(collectionNew).to.have.nested.property('limits.nestingRule');8889 90 delete collectionNew.limits.nestingRule;91 delete collectionOld.constOnChainSchema;92 delete collectionOld.offchainSchema;9394 expect(collectionNew).to.be.deep.equal(collectionOld);95 });96 });97});