difftreelog
Merge pull request #400 from UniqueNetwork/test/migration-check-update
in: master
Test migration from 921000
2 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -37,7 +37,7 @@
"testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
"testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
"testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",
- "testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
+ "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
"testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",
"testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
"testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
tests/src/nesting/migration-check.test.tsdiffbeforeafterboth1import {expect} from 'chai';1import {expect} from 'chai';2import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';2import usingApi, {executeTransaction, submitTransactionAsync} from '../substrate/substrate-api';3import {getCreateCollectionResult} from '../util/helpers';3import {getCreateCollectionResult, getCreateItemResult, normalizeAccountId} from '../util/helpers';4import {IKeyringPair} from '@polkadot/types/types';4import {IKeyringPair} from '@polkadot/types/types';5import {strToUTF16} from '../util/util';5import {strToUTF16} from '../util/util';6import waitNewBlocks from '../substrate/wait-new-blocks';6import waitNewBlocks from '../substrate/wait-new-blocks';7// Used for polkadot-launch signalling7// Used for polkadot-launch signalling8import find from 'find-process';8import find from 'find-process';9910// todo un-skip for migrations10// todo un-skip for migrations11describe.skip('Migration testing for pallet-common', () => {11describe.skip('Migration testing', () => {12 let alice: IKeyringPair;12 let alice: IKeyringPair;131314 before(async() => {14 before(async() => {15 await usingApi(async (api, privateKeyWrapper) => {15 await usingApi(async (_, privateKeyWrapper) => {16 alice = privateKeyWrapper('//Alice');16 alice = privateKeyWrapper('//Alice');17 });17 });18 });18 });21 let oldVersion: number;21 let oldVersion: number;22 let collectionId: number;22 let collectionId: number;23 let collectionOld: any;23 let collectionOld: any;24 let nftId: number;25 let nftOld: any;242625 await usingApi(async api => {27 await usingApi(async api => {26 // Create a collection for comparison before and after the upgrade28 // ----------- Collection pre-upgrade ------------27 const tx = api.tx.unique.createCollectionEx({29 const txCollection = api.tx.unique.createCollectionEx({28 mode: 'NFT',30 mode: 'NFT',29 access: 'AllowList',31 access: 'AllowList',30 name: strToUTF16('Mojave Pictures'),32 name: strToUTF16('Mojave Pictures'),31 description: strToUTF16('$2.2 billion power plant!'),33 description: strToUTF16('$2.2 billion power plant!'),32 tokenPrefix: '0x0002030',34 tokenPrefix: '0x0002030',33 //offchainSchema: '0x111111',35 offchainSchema: '0x111111',34 //schemaVersion: 'Unique',36 schemaVersion: 'Unique',35 limits: {37 limits: {36 accountTokenOwnershipLimit: 3,38 accountTokenOwnershipLimit: 3,37 },39 },38 //constOnChainSchema: '0x333333',40 constOnChainSchema: '0x333333',41 variableOnChainSchema: '0x22222',39 });42 });40 const events = await submitTransactionAsync(alice, tx);43 const events0 = await submitTransactionAsync(alice, txCollection);41 const result = getCreateCollectionResult(events);44 const result0 = getCreateCollectionResult(events0);42 collectionId = result.collectionId;45 collectionId = result0.collectionId;434644 // Get the pre-upgrade collection info47 // Get the pre-upgrade collection info45 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();48 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4950 // ---------- NFT pre-upgrade ------------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 // Get the pre-upgrade NFT data67 nftOld = (await api.query.nonfungible.tokenData(collectionId, nftId)).toJSON();466847 // Get the pre-upgrade spec version69 // Get the pre-upgrade spec version48 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;70 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;73 };95 };749675 let oldWarnCount = 0;97 let oldWarnCount = 0;76 while (newVersion == oldVersion! && connectionFailCounter < 2) {98 while (newVersion == oldVersion! && connectionFailCounter < 5) {99 await new Promise(resolve => setTimeout(resolve, 12000));77 try {100 try {78 await usingApi(async api => {101 await usingApi(async api => {79 await waitNewBlocks(api);102 await waitNewBlocks(api);82 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);105 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);83 oldWarnCount = warnCount;106 oldWarnCount = warnCount;84 }107 }85 await new Promise(resolve => setTimeout(resolve, 6000));86 });108 });87 } catch (_) {109 } catch (_) {88 connectionFailCounter++;110 connectionFailCounter++;89 await new Promise(resolve => setTimeout(resolve, 12000));90 }111 }91 }112 }92 }113 }9311494 await usingApi(async api => {115 await usingApi(async api => {116 // ---------- Collection comparison -----------95 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;117 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;9611897 // Make sure the extra fields are what they should be119 // Make sure the extra fields are what they should be98 //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');120 expect((99 //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');121 await api.rpc.unique.collectionProperties(collectionId, ['_old_constOnChainSchema'])100122 )[0].value.toHex()).to.be.equal(collectionOld.constOnChainSchema);101 //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);123102 //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);124 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);135103 expect(collectionNew).to.have.nested.property('limits.nestingRule');136 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);104143105 // Get rid of extra fields to perform comparison on the rest of the collection144 // Get rid of extra fields to perform comparison on the rest of the collection106 delete collectionNew.limits.nestingRule;145 delete collectionNew.permissions;107 //delete collectionOld.constOnChainSchema;146 delete collectionNew.externalCollection;108 //delete collectionOld.offchainSchema;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; // todo look into, doesn't migrate109154110 expect(collectionNew).to.be.deep.equal(collectionOld);155 expect(collectionNew).to.be.deep.equal(collectionOld);156157 // ---------- NFT comparison -----------158 const nftNew = (await api.query.nonfungible.tokenData(collectionId, nftId)).toJSON() as any;159160 // Make sure the extra fields are what they should be161 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 // Get rid of extra fields to perform comparison on the rest of the NFT166 delete nftOld.constData;167 delete nftOld.variableData;168169 expect(nftNew).to.be.deep.equal(nftOld);111 });170 });112 });171 });113});172});