difftreelog
Merge pull request #400 from UniqueNetwork/test/migration-check-update
in: master
Test migration from 921000
2 files changed
tests/package.jsondiffbeforeafterboth1{2 "name": "unique-tests",3 "version": "1.0.0",4 "description": "Unique Chain Tests",5 "main": "",6 "devDependencies": {7 "@polkadot/ts": "0.4.22",8 "@polkadot/typegen": "8.7.2-15",9 "@types/chai": "^4.3.1",10 "@types/chai-as-promised": "^7.1.5",11 "@types/mocha": "^9.1.1",12 "@types/node": "^17.0.35",13 "@typescript-eslint/eslint-plugin": "^5.26.0",14 "@typescript-eslint/parser": "^5.26.0",15 "chai": "^4.3.6",16 "eslint": "^8.16.0",17 "mocha": "^10.0.0",18 "ts-node": "^10.8.0",19 "typescript": "^4.7.2"20 },21 "mocha": {22 "timeout": 9999999,23 "require": "ts-node/register"24 },25 "scripts": {26 "lint": "eslint --ext .ts,.js src/",27 "fix": "eslint --ext .ts,.js src/ --fix",28 "test": "mocha --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",29 "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",30 "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",31 "testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",32 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",33 "loadTransfer": "ts-node src/transfer.nload.ts",34 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",35 "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",36 "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",37 "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",38 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",39 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",40 "testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",41 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",42 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",43 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",44 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",45 "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",46 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",47 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",48 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",49 "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",50 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",51 "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",52 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",53 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",54 "testCreateMultipleItemsEx": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItemsEx.test.ts",55 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",56 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",57 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",58 "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",59 "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",60 "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",61 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",62 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",63 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",64 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",65 "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",66 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",67 "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",68 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",69 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",70 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",71 "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts",72 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",73 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",74 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",75 "testXcmTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/xcmTransfer.test.ts",76 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",77 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",78 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",79 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",80 "testEthCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createCollection.test.ts",81 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",82 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",83 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",84 "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"85 },86 "author": "",87 "license": "SEE LICENSE IN ../LICENSE",88 "homepage": "",89 "dependencies": {90 "@polkadot/api": "8.7.2-15",91 "@polkadot/api-contract": "8.7.2-15",92 "@polkadot/util-crypto": "9.4.1",93 "bignumber.js": "^9.0.2",94 "chai-as-promised": "^7.1.1",95 "find-process": "^1.4.7",96 "solc": "0.8.14-fixed",97 "web3": "^1.7.3"98 },99 "standard": {100 "globals": [101 "it",102 "assert",103 "beforeEach",104 "afterEach",105 "describe",106 "contract",107 "artifacts"108 ]109 },110 "resolutions": {111 "simple-get": "^4.0.1"112 }113}tests/src/nesting/migration-check.test.tsdiffbeforeafterboth--- a/tests/src/nesting/migration-check.test.ts
+++ b/tests/src/nesting/migration-check.test.ts
@@ -1,6 +1,6 @@
import {expect} from 'chai';
-import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import {getCreateCollectionResult} from '../util/helpers';
+import usingApi, {executeTransaction, submitTransactionAsync} from '../substrate/substrate-api';
+import {getCreateCollectionResult, getCreateItemResult, normalizeAccountId} from '../util/helpers';
import {IKeyringPair} from '@polkadot/types/types';
import {strToUTF16} from '../util/util';
import waitNewBlocks from '../substrate/wait-new-blocks';
@@ -8,11 +8,11 @@
import find from 'find-process';
// todo un-skip for migrations
-describe.skip('Migration testing for pallet-common', () => {
+describe.skip('Migration testing', () => {
let alice: IKeyringPair;
before(async() => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingApi(async (_, privateKeyWrapper) => {
alice = privateKeyWrapper('//Alice');
});
});
@@ -21,29 +21,51 @@
let oldVersion: number;
let collectionId: number;
let collectionOld: any;
+ let nftId: number;
+ let nftOld: any;
await usingApi(async api => {
- // Create a collection for comparison before and after the upgrade
- const tx = api.tx.unique.createCollectionEx({
+ // ----------- Collection pre-upgrade ------------
+ const txCollection = api.tx.unique.createCollectionEx({
mode: 'NFT',
access: 'AllowList',
name: strToUTF16('Mojave Pictures'),
description: strToUTF16('$2.2 billion power plant!'),
tokenPrefix: '0x0002030',
- //offchainSchema: '0x111111',
- //schemaVersion: 'Unique',
+ offchainSchema: '0x111111',
+ schemaVersion: 'Unique',
limits: {
accountTokenOwnershipLimit: 3,
},
- //constOnChainSchema: '0x333333',
+ constOnChainSchema: '0x333333',
+ variableOnChainSchema: '0x22222',
});
- const events = await submitTransactionAsync(alice, tx);
- const result = getCreateCollectionResult(events);
- collectionId = result.collectionId;
+ const events0 = await submitTransactionAsync(alice, txCollection);
+ const result0 = getCreateCollectionResult(events0);
+ collectionId = result0.collectionId;
// Get the pre-upgrade collection info
collectionOld = (await api.query.common.collectionById(collectionId)).toJSON();
+ // ---------- NFT pre-upgrade ------------
+ const txNft = api.tx.unique.createItem(
+ collectionId,
+ normalizeAccountId(alice),
+ {
+ NFT: {
+ owner: {substrate: alice.address},
+ constData: '0x0000',
+ variableData: '0x1111',
+ },
+ },
+ );
+ const events1 = await executeTransaction(api, alice, txNft);
+ const result1 = getCreateItemResult(events1);
+ nftId = result1.itemId;
+
+ // Get the pre-upgrade NFT data
+ nftOld = (await api.query.nonfungible.tokenData(collectionId, nftId)).toJSON();
+
// Get the pre-upgrade spec version
oldVersion = (api.consts.system.version.toJSON() as any).specVersion;
});
@@ -73,7 +95,8 @@
};
let oldWarnCount = 0;
- while (newVersion == oldVersion! && connectionFailCounter < 2) {
+ while (newVersion == oldVersion! && connectionFailCounter < 5) {
+ await new Promise(resolve => setTimeout(resolve, 12000));
try {
await usingApi(async api => {
await waitNewBlocks(api);
@@ -82,32 +105,68 @@
console.log(`Still waiting for the parachain upgrade from ${oldVersion!}...`);
oldWarnCount = warnCount;
}
- await new Promise(resolve => setTimeout(resolve, 6000));
});
} catch (_) {
connectionFailCounter++;
- await new Promise(resolve => setTimeout(resolve, 12000));
}
}
}
await usingApi(async api => {
+ // ---------- Collection comparison -----------
const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;
// Make sure the extra fields are what they should be
- //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');
- //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');
+ expect((
+ await api.rpc.unique.collectionProperties(collectionId, ['_old_constOnChainSchema'])
+ )[0].value.toHex()).to.be.equal(collectionOld.constOnChainSchema);
+
+ expect((
+ await api.rpc.unique.collectionProperties(collectionId, ['_old_variableOnChainSchema'])
+ )[0].value.toHex()).to.be.equal(collectionOld.variableOnChainSchema);
+
+ expect((
+ await api.rpc.unique.collectionProperties(collectionId, ['_old_offchainSchema'])
+ )[0].value.toHex()).to.be.equal(collectionOld.offchainSchema);
+
+ expect((
+ await api.rpc.unique.collectionProperties(collectionId, ['_old_schemaVersion'])
+ )[0].value.toHuman()).to.be.equal(collectionOld.schemaVersion);
- //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);
- //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);
- expect(collectionNew).to.have.nested.property('limits.nestingRule');
+ expect(collectionNew.permissions).to.be.deep.equal({
+ access: collectionOld.access,
+ mintMode: collectionOld.mintMode,
+ nesting: null,
+ });
+
+ expect(collectionNew.externalCollection).to.be.equal(false);
// Get rid of extra fields to perform comparison on the rest of the collection
- delete collectionNew.limits.nestingRule;
- //delete collectionOld.constOnChainSchema;
- //delete collectionOld.offchainSchema;
+ delete collectionNew.permissions;
+ delete collectionNew.externalCollection;
+ delete collectionOld.schemaVersion;
+ delete collectionOld.constOnChainSchema;
+ delete collectionOld.variableOnChainSchema;
+ delete collectionOld.offchainSchema;
+ delete collectionOld.mintMode;
+ delete collectionOld.access;
+ delete collectionOld.metaUpdatePermission; // todo look into, doesn't migrate
expect(collectionNew).to.be.deep.equal(collectionOld);
+
+ // ---------- NFT comparison -----------
+ const nftNew = (await api.query.nonfungible.tokenData(collectionId, nftId)).toJSON() as any;
+
+ // Make sure the extra fields are what they should be
+ expect((await api.rpc.unique.tokenProperties(collectionId, nftId, ['_old_constData']))[0].value.toHex()).to.be.equal(nftOld.constData);
+
+ expect((await api.rpc.unique.tokenProperties(collectionId, nftId, ['_old_variableData']))[0].value.toHex()).to.be.equal(nftOld.variableData);
+
+ // Get rid of extra fields to perform comparison on the rest of the NFT
+ delete nftOld.constData;
+ delete nftOld.variableData;
+
+ expect(nftNew).to.be.deep.equal(nftOld);
});
});
});