git.delta.rocks / unique-network / refs/commits / 5e6da29cc336

difftreelog

source

tests/src/nesting/migration-check.test.ts3.5 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';89// todo skip10describe.skip('Migration testing for pallet-common', () => {11  let alice: IKeyringPair;12  13  before(async() => {14    await usingApi(async api => {15      alice = privateKey('//Alice');16    });17  });1819  it('Preserves collection settings', async () => {20    let old_version: number;21    let collection_id: number;22    let collection_old: any;2324    await usingApi(async api => {25      // Create a collection for comparison before and after the upgrade26      const tx = api.tx.unique.createCollectionEx({27        mode: 'NFT',28        access: 'AllowList',29        name: strToUTF16("Mojave Pictures"),30        description: strToUTF16("$2.2 billion power plant!"),31        tokenPrefix: '0x0002030',32        offchainSchema: '0x111111',33        schemaVersion: 'Unique',34        limits: {35          accountTokenOwnershipLimit: 3,36        },37        variableOnChainSchema: '0x222222',38        constOnChainSchema: '0x333333',39        metaUpdatePermission: 'Admin',40      });41      const events = await submitTransactionAsync(alice, tx);42      const result = getCreateCollectionResult(events);43      collection_id = result.collectionId;4445      // Get the pre-upgrade collection info46      collection_old = (await api.query.common.collectionById(collection_id)).toJSON();4748      // Get the pre-upgrade spec version49      old_version = (api.consts.system.version.toJSON() as any).specVersion;50    });5152    console.log(`Now waiting for the parachain upgrade from ${old_version!}...`);5354    let new_version = old_version!;55    let connection_fail_counter = 0;5657    // And wait for the parachain upgrade58    while (new_version == old_version! && connection_fail_counter < 2) {59      try {60        await usingApi(async api => {61          await waitNewBlocks(api);62          new_version = (api.consts.system.version.toJSON() as any).specVersion;63        });64      } catch (_) {65        connection_fail_counter++;66        await new Promise( resolve => setTimeout(resolve, 12000) );67      }68    }6970    await usingApi(async api => {71      const collection_new = (await api.query.common.collectionById(collection_id)).toJSON() as any;72      73      // Make sure the extra fields are what they should be74      const variable_on_chain_schema = await api.query.common.collectionData(collection_id, "VariableOnChainSchema");75      const const_on_chain_schema = await api.query.common.collectionData(collection_id, "ConstOnChainSchema");76      const offchain_schema = await api.query.common.collectionData(collection_id, "OffchainSchema");7778      expect(variable_on_chain_schema.toHex()).to.be.deep.equal((collection_old.variableOnChainSchema));79      expect(const_on_chain_schema.toHex()).to.be.deep.equal(collection_old.constOnChainSchema);80      expect(offchain_schema.toHex()).to.be.deep.equal(collection_old.offchainSchema);81      expect(collection_new).to.have.nested.property('limits.nestingRule');8283      // Get rid of extra fields to perform comparison on the rest of the collection84      delete collection_new.limits.nestingRule;85      delete collection_old.constOnChainSchema;86      delete collection_old.offchainSchema;87      delete collection_old.variableOnChainSchema;8889      expect(collection_new).to.be.deep.equal(collection_old);90    });91  });92});93