git.delta.rocks / unique-network / refs/commits / ed591baa5c51

difftreelog

source

tests/src/nesting/migration-check.test.ts4.2 KiBsourcehistory
1import {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});