Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata compare update for v14 #272

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^5.9.1",
"@polkadot/api-derive": "^5.9.1",
"@polkadot/keyring": "^7.3.1",
"@polkadot/types": "^5.9.1",
"@polkadot/util": "^7.3.1",
"@polkadot/util-crypto": "^7.3.1",
"@polkadot/api": "^6.0.4-1",
"@polkadot/api-derive": "^6.0.4-1",
"@polkadot/keyring": "^7.4.1",
"@polkadot/types": "^6.0.4-1",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"typescript": "^4.4.3"
},
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions packages/api-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/api": "^5.9.1",
"@polkadot/keyring": "^7.3.1",
"@polkadot/types": "^5.9.1",
"@polkadot/util": "^7.3.1",
"@polkadot/api": "^6.0.4-1",
"@polkadot/keyring": "^7.4.1",
"@polkadot/types": "^6.0.4-1",
"@polkadot/util": "^7.4.1",
"yargs": "^17.1.1"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/json-serve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/api": "^5.9.1",
"@polkadot/api-derive": "^5.9.1",
"@polkadot/types": "^5.9.1",
"@polkadot/api": "^6.0.4-1",
"@polkadot/api-derive": "^6.0.4-1",
"@polkadot/types": "^6.0.4-1",
"koa": "^2.13.1",
"koa-route": "^3.2.0",
"yargs": "^17.1.1"
Expand Down
8 changes: 4 additions & 4 deletions packages/metadata-cmp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/api": "^5.9.1",
"@polkadot/keyring": "^7.3.1",
"@polkadot/types": "^5.9.1",
"@polkadot/util": "^7.3.1",
"@polkadot/api": "^6.0.4-1",
"@polkadot/keyring": "^7.4.1",
"@polkadot/types": "^6.0.4-1",
"@polkadot/util": "^7.4.1",
"yargs": "^17.1.1"
},
"devDependencies": {
Expand Down
72 changes: 31 additions & 41 deletions packages/metadata-cmp/src/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import yargs from 'yargs';

import { ApiPromise, WsProvider } from '@polkadot/api';
import { expandMetadata, Metadata } from '@polkadot/types';
import { getSiName } from '@polkadot/types/metadata/util';
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
import { assert, stringCamelCase } from '@polkadot/util';

type ArgV = { _: [string, string] };
Expand Down Expand Up @@ -79,8 +81,8 @@ async function main (): Promise<number> {
log(lvl1, 'Spec', 'version:', createCompare(verA.specVersion.toNumber(), verB.specVersion.toNumber()));
log(lvl1, 'Metadata', 'version:', createCompare(metaA.version, metaB.version));

const mA = a.modules.map(({ name }) => name.toString());
const mB = b.modules.map(({ name }) => name.toString());
const mA = a.pallets.map(({ name }) => name.toString());
const mB = b.pallets.map(({ name }) => name.toString());

log(lvl1, 'Modules', 'num:', createCompare(mA.length, mB.length));

Expand Down Expand Up @@ -156,66 +158,54 @@ async function main (): Promise<number> {
.forEach((c): void => {
const cA = decA.query[n][c];
const cB = decB.query[n][c];
const tA = unwrapStorageType(metaA.registry, cA.meta.type, cA.meta.modifier.isOptional);
const tB = unwrapStorageType(metaB.registry, cB.meta.type, cB.meta.modifier.isOptional);

// storage types differ
if (!cA.meta.type.eq(cB.meta.type)) {
if (tA !== tB) {
if (cA.meta.type.isMap && cB.meta.type.isMap) {
// diff map
const mapA = cA.meta.type.asMap;
const mapB = cB.meta.type.asMap;
const diffs = [];
const hA = mapA.hashers.map((h) => h.toString()).join(', ');
const hB = mapB.hashers.map((h) => h.toString()).join(', ');

if (!mapA.hasher.eq(mapB.hasher)) {
diffs.push(`hasher: ${createCompare(mapA.hasher.toString(), mapB.hasher.toString())}`);
if (hA !== hB) {
diffs.push(`hashers: ${createCompare(hA, hB)}`);
}

if (!mapA.key.eq(mapB.key)) {
diffs.push(`key: ${createCompare(mapA.key.toString(), mapB.key.toString())}`);
const kA = (
mapA.hashers.length === 1
? [mapA.key]
: metaA.registry.lookup.getSiType(mapA.key).def.asTuple
).map((t) => getSiName(metaA.registry.lookup, t)).join(', ');
const kB = (
mapB.hashers.length === 1
? [mapB.key]
: metaB.registry.lookup.getSiType(mapB.key).def.asTuple
).map((t) => getSiName(metaB.registry.lookup, t)).join(', ');

if (kA !== kB) {
diffs.push(`keys: ${createCompare(kA, kB)}`);
}

if (!mapA.value.eq(mapB.value)) {
diffs.push(`value: ${createCompare(mapA.value.toString(), mapB.value.toString())}`);
}

logArray(lvl3, c, '', diffs, 1);
} else if (cA.meta.type.isDoubleMap && cB.meta.type.isDoubleMap) {
// diff double map
const mapA = cA.meta.type.asDoubleMap;
const mapB = cB.meta.type.asDoubleMap;
const diffs = [];
const vA = getSiName(metaA.registry.lookup, mapA.value);
const vB = getSiName(metaB.registry.lookup, mapB.value);

if (!mapA.hasher.eq(mapB.hasher)) {
diffs.push(`hasher: ${createCompare(mapA.hasher.toString(), mapB.hasher.toString())}`);
}

if (!mapA.key1.eq(mapB.key1)) {
diffs.push(`key1: ${createCompare(mapA.key1.toString(), mapB.key1.toString())}`);
}

if (!mapA.key2Hasher.eq(mapB.key2Hasher)) {
diffs.push(`key2Hasher: ${createCompare(mapA.key2Hasher.toString(), mapB.key2Hasher.toString())}`);
}

if (!mapA.key2.eq(mapB.key2)) {
diffs.push(`key2: ${createCompare(mapA.key2.toString(), mapB.key2.toString())}`);
}

if (!mapA.value.eq(mapB.value)) {
diffs.push(`value: ${createCompare(mapA.value.toString(), mapB.value.toString())}`);
if (vA !== vB) {
diffs.push(`value: ${createCompare(vA, vB)}`);
}

logArray(lvl3, c, '', diffs, 1);
} else if (cA.meta.type.isPlain && cB.meta.type.isPlain) {
// diff plain type
const tA = cA.meta.type.asPlain;
const tB = cB.meta.type.asPlain;

log(lvl3, c, 'type:', createCompare(tA.toString(), tB.toString()));
log(lvl3, c, 'type:', createCompare(tA, tB));
} else {
// fallback diff if types are completely different
log(lvl3, c, '', cA.meta.type.toString());
log(lvl3, c, '', tA);
log(lvl5, '', '', '->');
log(lvl3, '', '', cB.meta.type.toString());
log(lvl3, '', '', tB);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/monitor-rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/api": "^5.9.1",
"@polkadot/types": "^5.9.1",
"@polkadot/api": "^6.0.4-1",
"@polkadot/types": "^6.0.4-1",
"koa": "^2.13.1",
"koa-route": "^3.2.0",
"yargs": "^17.1.1"
Expand Down
10 changes: 5 additions & 5 deletions packages/signer-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/api": "^5.9.1",
"@polkadot/api": "^6.0.4-1",
"@polkadot/api-cli": "^0.45.6-1",
"@polkadot/keyring": "^7.3.1",
"@polkadot/types": "^5.9.1",
"@polkadot/util": "^7.3.1",
"@polkadot/util-crypto": "^7.3.1",
"@polkadot/keyring": "^7.4.1",
"@polkadot/types": "^6.0.4-1",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"yargs": "^17.1.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/signer-cli/src/cmdSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function validateSeed (suri: string) {
assert(isHex(phrase, 256), 'Hex seed needs to be 256-bits');
} else {
// sadly isHex detects as string, so we need a cast here
assert(SEED_LENGTHS.includes((phrase as string).split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
assert(SEED_LENGTHS.includes(phrase.split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
assert(mnemonicValidate(phrase), 'Not a valid mnemonic seed');
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vanitygen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/util": "^7.3.1",
"@polkadot/util-crypto": "^7.3.1",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"chalk": "^4.1.2",
"yargs": "^17.1.1"
},
Expand Down
Loading