git.delta.rocks / unique-network / refs/commits / 3ee9e950e03f

difftreelog

source

tests/src/nesting/migration-check.test.ts4.2 KiBsourcehistory
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';8// Used for polkadot-launch signalling9import find from 'find-process';1011// todo un-skip for migrations12describe.skip('Migration testing for pallet-common', () => {13  let alice: IKeyringPair;1415  before(async() => {16    await usingApi(async () => {17      alice = privateKey('//Alice');18    });19  });2021  it('Preserves collection settings after migration', async () => {22    let oldVersion: number;23    let collectionId: number;24    let collectionOld: any;2526    await usingApi(async api => {27      // Create a collection for comparison before and after the upgrade28      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        constOnChainSchema: '0x333333',40      });41      const events = await submitTransactionAsync(alice, tx);42      const result = getCreateCollectionResult(events);43      collectionId = result.collectionId;4445      // Get the pre-upgrade collection info46      collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4748      // Get the pre-upgrade spec version49      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    // Cooperate with polkadot-launch if it's running (assuming custom name change to 'polkadot-launch'), and send a custom signal58    find('name', 'polkadot-launch', true).then((list) => {59      for (const proc of list) {60        process.kill(proc.pid, 'SIGUSR1');61      }62    });6364    // And wait for the parachain upgrade65    {66      // Catch warnings like 'RPC methods not decorated' and keep the 'waiting' message in front67      const stdlog = console.warn.bind(console);68      let warnCount = 0;69      console.warn = function(...args){70        if (arguments.length <= 2 || !args[2].includes('RPC methods not decorated')) {71          warnCount++;72          stdlog.apply(console, args as any);73        }74      };7576      let oldWarnCount = 0;77      while (newVersion == oldVersion! && connectionFailCounter < 2) {78        try {79          await usingApi(async api => {80            await waitNewBlocks(api);81            newVersion = (api.consts.system.version.toJSON() as any).specVersion;82            if (warnCount > oldWarnCount) {83              console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);84              oldWarnCount = warnCount;85            }86            await new Promise(resolve => setTimeout(resolve, 6000));87          });88        } catch (_) {89          connectionFailCounter++;90          await new Promise(resolve => setTimeout(resolve, 12000));91        }92      }93    }9495    await usingApi(async api => {96      const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;9798      // Make sure the extra fields are what they should be99      const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');100      const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');101102      expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);103      expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);104      expect(collectionNew).to.have.nested.property('limits.nestingRule');105106      // Get rid of extra fields to perform comparison on the rest of the collection107      delete collectionNew.limits.nestingRule;108      delete collectionOld.constOnChainSchema;109      delete collectionOld.offchainSchema;110111      expect(collectionNew).to.be.deep.equal(collectionOld);112    });113  });114});