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';8910describe('Migration testing for pallet-common', () => {11 let alice: IKeyringPair;12 13 before(async() => {14 await usingApi(async () => {15 alice = privateKey('//Alice');16 });17 });1819 it('Preserves collection settings', async () => {20 let oldVersion: number;21 let collectionId: number;22 let collectionOld: any;2324 await usingApi(async api => {25 26 const tx = api.tx.unique.createCollectionEx({27 mode: 'NFT',28 access: 'AllowList',29 name: strToUTF16('Mojave Pictures'),30 description: strToUTF16('$2.2 billion power plant!'),31 tokenPrefix: '0x0002030',32 offchainSchema: '0x111111',33 schemaVersion: 'Unique',34 limits: {35 accountTokenOwnershipLimit: 3,36 },37 variableOnChainSchema: '0x222222',38 constOnChainSchema: '0x333333',39 metaUpdatePermission: 'Admin',40 });41 const events = await submitTransactionAsync(alice, tx);42 const result = getCreateCollectionResult(events);43 collectionId = result.collectionId;4445 46 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4748 49 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;50 });5152 console.log(`Now waiting for the parachain upgrade from ${oldVersion!}...`);5354 let newVersion = oldVersion!;55 let connectionFailCounter = 0;5657 58 const find = require('find-process');59 find('name', 'polkadot-launch', true).then(function (list: [any]) {60 for (let 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;80 81 82 const variableOnChainSchema = await api.query.common.collectionData(collectionId, 'VariableOnChainSchema');83 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');84 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');8586 expect(variableOnChainSchema.toHex()).to.be.deep.equal((collectionOld.variableOnChainSchema));87 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);88 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);89 expect(collectionNew).to.have.nested.property('limits.nestingRule');9091 92 delete collectionNew.limits.nestingRule;93 delete collectionOld.constOnChainSchema;94 delete collectionOld.offchainSchema;95 delete collectionOld.variableOnChainSchema;9697 expect(collectionNew).to.be.deep.equal(collectionOld);98 });99 });100});101