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

difftreelog

source

tests/src/nesting/migration-check.test.ts3.6 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 skip12describe('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        metaUpdatePermission: 'Admin',41      });42      const events = await submitTransactionAsync(alice, tx);43      const result = getCreateCollectionResult(events);44      collectionId = result.collectionId;4546      // Get the pre-upgrade collection info47      collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();4849      // Get the pre-upgrade spec version50      oldVersion = (api.consts.system.version.toJSON() as any).specVersion;51    });5253    console.log(`Now waiting for the parachain upgrade from ${oldVersion!}...`);5455    let newVersion = oldVersion!;56    let connectionFailCounter = 0;5758    // Cooperate with polkadot-launch if it's running (assuming custom name change to 'polkadot-launch'), and send a custom signal59    find('name', 'polkadot-launch', true).then((list) => {60      for (const proc of list) {61        process.kill(proc.pid, 'SIGUSR1');62      }63    });6465    // And wait for the parachain upgrade66    while (newVersion == oldVersion! && connectionFailCounter < 2) {67      try {68        await usingApi(async api => {69          await waitNewBlocks(api);70          newVersion = (api.consts.system.version.toJSON() as any).specVersion;71        });72      } catch (_) {73        connectionFailCounter++;74        console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);75        await new Promise(resolve => setTimeout(resolve, 12000));76      }77    }7879    await usingApi(async api => {80      const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;8182      // Make sure the extra fields are what they should be83      const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');84      const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');8586      expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);87      expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);88      expect(collectionNew).to.have.nested.property('limits.nestingRule');8990      // Get rid of extra fields to perform comparison on the rest of the collection91      delete collectionNew.limits.nestingRule;92      delete collectionOld.constOnChainSchema;93      delete collectionOld.offchainSchema;9495      expect(collectionNew).to.be.deep.equal(collectionOld);96    });97  });98});