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;14 15 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 variableOnChainSchema: '0x222222',40 constOnChainSchema: '0x333333',41 metaUpdatePermission: 'Admin',42 });43 const events = await submitTransactionAsync(alice, tx);44 const result = getCreateCollectionResult(events);45 collectionId = result.collectionId;4647 48 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4950 51 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;52 });5354 console.log(`Now waiting for the parachain upgrade from ${oldVersion!}...`);5556 let newVersion = oldVersion!;57 let connectionFailCounter = 0;5859 60 find('name', 'polkadot-launch', true).then((list) => {61 for (const proc of list) {62 process.kill(proc.pid, 'SIGUSR1');63 }64 });6566 67 while (newVersion == oldVersion! && connectionFailCounter < 2) {68 try {69 await usingApi(async api => {70 await waitNewBlocks(api);71 newVersion = (api.consts.system.version.toJSON() as any).specVersion;72 });73 } catch (_) {74 connectionFailCounter++;75 await new Promise(resolve => setTimeout(resolve, 12000));76 }77 }7879 await usingApi(async api => {80 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;81 82 83 const variableOnChainSchema = await api.query.common.collectionData(collectionId, 'VariableOnChainSchema');84 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');85 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');8687 expect(variableOnChainSchema.toHex()).to.be.deep.equal((collectionOld.variableOnChainSchema));88 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);89 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);90 expect(collectionNew).to.have.nested.property('limits.nestingRule');9192 93 delete collectionNew.limits.nestingRule;94 delete collectionOld.constOnChainSchema;95 delete collectionOld.offchainSchema;96 delete collectionOld.variableOnChainSchema;9798 expect(collectionNew).to.be.deep.equal(collectionOld);99 });100 });101});102