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';2import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';3import {getCreateCollectionResult} from '../util/helpers';4import {IKeyringPair} from '@polkadot/types/types';5import {strToUTF16} from '../util/util';6import waitNewBlocks from '../substrate/wait-new-blocks';7// Used for polkadot-launch signalling8import find from 'find-process';910// todo un-skip for migrations11describe.skip('Migration testing for pallet-common', () => {12 let alice: IKeyringPair;1314 before(async() => {15 await usingApi(async (api, 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;2425 await usingApi(async api => {26 // Create a collection for comparison before and after the upgrade27 const tx = api.tx.unique.createCollectionEx({28 mode: 'NFT',29 access: 'AllowList',30 name: strToUTF16('Mojave Pictures'),31 description: strToUTF16('$2.2 billion power plant!'),32 tokenPrefix: '0x0002030',33 //offchainSchema: '0x111111',34 //schemaVersion: 'Unique',35 limits: {36 accountTokenOwnershipLimit: 3,37 },38 //constOnChainSchema: '0x333333',39 });40 const events = await submitTransactionAsync(alice, tx);41 const result = getCreateCollectionResult(events);42 collectionId = result.collectionId;4344 // Get the pre-upgrade collection info45 collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4647 // Get the pre-upgrade spec version48 oldVersion = (api.consts.system.version.toJSON() as any).specVersion;49 });5051 console.log(`Now waiting for the parachain upgrade from ${oldVersion!}...`);5253 let newVersion = oldVersion!;54 let connectionFailCounter = 0;5556 // Cooperate with polkadot-launch if it's running (assuming custom name change to 'polkadot-launch'), and send a custom signal57 find('name', 'polkadot-launch', true).then((list) => {58 for (const proc of list) {59 process.kill(proc.pid, 'SIGUSR1');60 }61 });6263 // And wait for the parachain upgrade64 {65 // Catch warnings like 'RPC methods not decorated' and keep the 'waiting' message in front66 const stdlog = console.warn.bind(console);67 let warnCount = 0;68 console.warn = function(...args){69 if (arguments.length <= 2 || !args[2].includes('RPC methods not decorated')) {70 warnCount++;71 stdlog.apply(console, args as any);72 }73 };7475 let oldWarnCount = 0;76 while (newVersion == oldVersion! && connectionFailCounter < 2) {77 try {78 await usingApi(async api => {79 await waitNewBlocks(api);80 newVersion = (api.consts.system.version.toJSON() as any).specVersion;81 if (warnCount > oldWarnCount) {82 console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);83 oldWarnCount = warnCount;84 }85 await new Promise(resolve => setTimeout(resolve, 6000));86 });87 } catch (_) {88 connectionFailCounter++;89 await new Promise(resolve => setTimeout(resolve, 12000));90 }91 }92 }9394 await usingApi(async api => {95 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;9697 // Make sure the extra fields are what they should be98 //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');99 //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');100101 //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);102 //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);103 expect(collectionNew).to.have.nested.property('limits.nestingRule');104105 // Get rid of extra fields to perform comparison on the rest of the collection106 delete collectionNew.limits.nestingRule;107 //delete collectionOld.constOnChainSchema;108 //delete collectionOld.offchainSchema;109110 expect(collectionNew).to.be.deep.equal(collectionOld);111 });112 });113});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';7// Used for polkadot-launch signalling8import find from 'find-process';910// todo un-skip for migrations11describe.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 // ----------- Collection pre-upgrade ------------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 // Get the pre-upgrade collection info48 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();6869 // Get the pre-upgrade spec version70 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 // Cooperate with polkadot-launch if it's running (assuming custom name change to 'polkadot-launch'), and send a custom signal79 find('name', 'polkadot-launch', true).then((list) => {80 for (const proc of list) {81 process.kill(proc.pid, 'SIGUSR1');82 }83 });8485 // And wait for the parachain upgrade86 {87 // Catch warnings like 'RPC methods not decorated' and keep the 'waiting' message in front88 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 // ---------- Collection comparison -----------117 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;118119 // Make sure the extra fields are what they should be120 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 // Get rid of extra fields to perform comparison on the rest of the collection145 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; // todo look into, doesn't migrate154155 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);170 });171 });172});