1import {expect} from 'chai';2import usingApi, {executeTransaction, submitTransactionAsync} from '../substrate/substrate-api';3import {getCreateCollectionResult, getCreateItemResult, normalizeAccountId} 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', () => {12 let alice: IKeyringPair;1314 before(async() => {15 await usingApi(async (_, 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;24 let nftId: number;25 let nftOld: any;2627 await usingApi(async api => {28 29 const txCollection = api.tx.unique.createCollectionEx({30 mode: 'NFT',31 access: 'AllowList',32 name: strToUTF16('Mojave Pictures'),33 description: strToUTF16('$2.2 billion power plant!'),34 tokenPrefix: '0x0002030',35 offchainSchema: '0x111111',36 schemaVersion: 'Unique',37 limits: {38 accountTokenOwnershipLimit: 3,39 },40 constOnChainSchema: '0x333333',41 variableOnChainSchema: '0x22222',42 });43 const events0 = await submitTransactionAsync(alice, txCollection);44 const result0 = getCreateCollectionResult(events0);45 collectionId = result0.collectionId;4647 48 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4950 51 const txNft = api.tx.unique.createItem(52 collectionId, 53 normalizeAccountId(alice), 54 {55 NFT: {56 owner: {substrate: alice.address},57 constData: '0x0000',58 variableData: '0x1111',59 },60 },61 );62 const events1 = await executeTransaction(api, alice, txNft);63 const result1 = getCreateItemResult(events1);64 nftId = result1.itemId;6566 67 nftOld = (await api.query.nonfungible.tokenData(collectionId, nftId)).toJSON();6869 70 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;71 });7273 console.log(`Now waiting for the parachain upgrade from ${oldVersion!}...`);7475 let newVersion = oldVersion!;76 let connectionFailCounter = 0;7778 79 find('name', 'polkadot-launch', true).then((list) => {80 for (const proc of list) {81 process.kill(proc.pid, 'SIGUSR1');82 }83 });8485 86 {87 88 const stdlog = console.warn.bind(console);89 let warnCount = 0;90 console.warn = function(...args){91 if (arguments.length <= 2 || !args[2].includes('RPC methods not decorated')) {92 warnCount++;93 stdlog.apply(console, args as any);94 }95 };9697 let oldWarnCount = 0;98 while (newVersion == oldVersion! && connectionFailCounter < 5) {99 await new Promise(resolve => setTimeout(resolve, 12000));100 try {101 await usingApi(async api => {102 await waitNewBlocks(api);103 newVersion = (api.consts.system.version.toJSON() as any).specVersion;104 if (warnCount > oldWarnCount) {105 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);106 oldWarnCount = warnCount;107 }108 });109 } catch (_) {110 connectionFailCounter++;111 }112 }113 }114115 await usingApi(async api => {116 117 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;118119 120 expect((121 await api.rpc.unique.collectionProperties(collectionId, ['_old_constOnChainSchema'])122 )[0].value.toHex()).to.be.equal(collectionOld.constOnChainSchema);123124 expect((125 await api.rpc.unique.collectionProperties(collectionId, ['_old_variableOnChainSchema'])126 )[0].value.toHex()).to.be.equal(collectionOld.variableOnChainSchema);127128 expect((129 await api.rpc.unique.collectionProperties(collectionId, ['_old_offchainSchema'])130 )[0].value.toHex()).to.be.equal(collectionOld.offchainSchema);131132 expect((133 await api.rpc.unique.collectionProperties(collectionId, ['_old_schemaVersion'])134 )[0].value.toHuman()).to.be.equal(collectionOld.schemaVersion);135136 expect(collectionNew.permissions).to.be.deep.equal({137 access: collectionOld.access,138 mintMode: collectionOld.mintMode,139 nesting: null,140 });141142 expect(collectionNew.externalCollection).to.be.equal(false);143144 145 delete collectionNew.permissions;146 delete collectionNew.externalCollection;147 delete collectionOld.schemaVersion;148 delete collectionOld.constOnChainSchema;149 delete collectionOld.variableOnChainSchema;150 delete collectionOld.offchainSchema;151 delete collectionOld.mintMode;152 delete collectionOld.access;153 delete collectionOld.metaUpdatePermission; 154155 expect(collectionNew).to.be.deep.equal(collectionOld);156157 158 const nftNew = (await api.query.nonfungible.tokenData(collectionId, nftId)).toJSON() as any;159160 161 expect((await api.rpc.unique.tokenProperties(collectionId, nftId, ['_old_constData']))[0].value.toHex()).to.be.equal(nftOld.constData);162163 expect((await api.rpc.unique.tokenProperties(collectionId, nftId, ['_old_variableData']))[0].value.toHex()).to.be.equal(nftOld.variableData);164165 166 delete nftOld.constData;167 delete nftOld.variableData;168169 expect(nftNew).to.be.deep.equal(nftOld);170 });171 });172});