Flatten metadata tests & imports (#3830)
This commit is contained in:
@@ -7,7 +7,7 @@ import type { Constants } from '../types';
|
||||
import { TypeRegistry } from '../../../create';
|
||||
import { Metadata } from '../../Metadata';
|
||||
import rpcMetadata from '../../static-substrate';
|
||||
import rpcMetadataV10 from '../../v10/hex/static-substrate';
|
||||
import rpcMetadataV10 from '../../v10/substrate-hex';
|
||||
import { decorateConstants } from '..';
|
||||
|
||||
function init (meta: string): [Constants, TypeRegistry] {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import metadata from './v13/hex/static-polkadot';
|
||||
import metadata from './v13/polkadot-hex';
|
||||
|
||||
export default metadata;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import metadata from './v13/hex/static-substrate';
|
||||
import metadata from './v13/substrate-hex';
|
||||
|
||||
export default metadata;
|
||||
|
||||
@@ -3,24 +3,26 @@
|
||||
|
||||
import type { Codec, Registry } from '../../types';
|
||||
import type { MetadataInterface } from '../types';
|
||||
import type { Check } from './types';
|
||||
|
||||
import { assert, hexToU8a, stringify, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { unwrapStorageType } from '../../primitive/StorageKey';
|
||||
import { Metadata } from '../Metadata';
|
||||
import { getUniqTypes } from './getUniqTypes';
|
||||
|
||||
/** @internal */
|
||||
export function decodeLatestMeta<Modules extends Codec> (registry: Registry, version: number, staticMeta: string, staticJson: Record<string, unknown>): void {
|
||||
export function decodeLatestMeta<Modules extends Codec> (registry: Registry, version: number, { compare, data }: Check): void {
|
||||
it('decodes metadata properly', (): void => {
|
||||
const metadata = new Metadata(registry, staticMeta);
|
||||
const metadata = new Metadata(registry, data);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
try {
|
||||
expect(metadata.version).toBe(version);
|
||||
expect((metadata[`asV${version}` as keyof Metadata] as unknown as MetadataInterface<Modules>).modules.length).not.toBe(0);
|
||||
expect(metadata.toJSON()).toEqual(staticJson);
|
||||
expect(metadata.toJSON()).toEqual(compare);
|
||||
} catch (error) {
|
||||
console.error(stringify(metadata.toJSON()));
|
||||
|
||||
@@ -57,7 +59,7 @@ export function defaultValues (registry: Registry, rpcData: string, withThrow =
|
||||
const inner = unwrapStorageType(registry, type, modifier.isOptional);
|
||||
const location = `${mod.name.toString()}.${name.toString()}: ${inner}`;
|
||||
|
||||
it(`creates default types for ${location}`, (): void => {
|
||||
it(location, (): void => {
|
||||
expect((): void => {
|
||||
try {
|
||||
const type = registry.createType(inner, hexToU8a(fallback.toHex()));
|
||||
@@ -82,3 +84,18 @@ export function defaultValues (registry: Registry, rpcData: string, withThrow =
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function testMeta (version: number, matchers: Record<string, Check>, withFallback = true): void {
|
||||
describe(`MetadataV${version}`, (): void => {
|
||||
describe.each(Object.keys(matchers))('%s', (type): void => {
|
||||
const matcher = matchers[type];
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestMeta(registry, version, matcher);
|
||||
|
||||
toLatest(registry, version, matcher.data);
|
||||
|
||||
defaultValues(registry, matcher.data, true, withFallback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export interface Check {
|
||||
compare: Record<string, unknown>;
|
||||
data: string;
|
||||
types?: Record<string, unknown>;
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './hex/static-substrate';
|
||||
import substrateJson from './json/static-substrate.json';
|
||||
import { testMeta } from '../util/testUtil';
|
||||
import substrateData from './substrate-hex';
|
||||
import substrateJson from './substrate-json.json';
|
||||
|
||||
describe('MetadataV10 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestMeta(registry, 10, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 10, substrateData);
|
||||
|
||||
defaultValues(registry, substrateData);
|
||||
});
|
||||
testMeta(10, {
|
||||
substrate: {
|
||||
compare: substrateJson as Record<string, unknown>,
|
||||
data: substrateData
|
||||
}
|
||||
}, false);
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './hex/static-substrate';
|
||||
import substrateJson from './json/static-substrate.json';
|
||||
import { testMeta } from '../util/testUtil';
|
||||
import substrateData from './substrate-hex';
|
||||
import substrateJson from './substrate-json.json';
|
||||
|
||||
describe('MetadataV11 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestMeta(registry, 11, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 11, substrateData);
|
||||
|
||||
defaultValues(registry, substrateData);
|
||||
});
|
||||
testMeta(11, {
|
||||
substrate: {
|
||||
compare: substrateJson as Record<string, unknown>,
|
||||
data: substrateData
|
||||
}
|
||||
}, false);
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './hex/static-substrate';
|
||||
import substrateJson from './json/static-substrate.json';
|
||||
import { testMeta } from '../util/testUtil';
|
||||
import substrateData from './substrate-hex';
|
||||
import substrateJson from './substrate-json.json';
|
||||
|
||||
describe('MetadataV12 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestMeta(registry, 12, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 12, substrateData);
|
||||
|
||||
defaultValues(registry, substrateData, true, true);
|
||||
testMeta(12, {
|
||||
substrate: {
|
||||
compare: substrateJson as Record<string, unknown>,
|
||||
data: substrateData
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,29 +1,19 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
import polkadotData from './hex/static-polkadot';
|
||||
import substrateData from './hex/static-substrate';
|
||||
import polkadotJson from './json/static-polkadot.json';
|
||||
import substrateJson from './json/static-substrate.json';
|
||||
import { testMeta } from '../util/testUtil';
|
||||
import polkadotData from './polkadot-hex';
|
||||
import polkadotJson from './polkadot-json.json';
|
||||
import substrateData from './substrate-hex';
|
||||
import substrateJson from './substrate-json.json';
|
||||
|
||||
describe('MetadataV13 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestMeta(registry, 13, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 13, substrateData);
|
||||
|
||||
defaultValues(registry, substrateData, true, true);
|
||||
});
|
||||
|
||||
describe('MetadataV13 (polkadot)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestMeta(registry, 13, polkadotData, polkadotJson);
|
||||
|
||||
toLatest(registry, 13, polkadotData);
|
||||
|
||||
defaultValues(registry, polkadotData, true, true);
|
||||
testMeta(13, {
|
||||
polkadot: {
|
||||
compare: polkadotJson as Record<string, unknown>,
|
||||
data: polkadotData
|
||||
},
|
||||
substrate: {
|
||||
compare: substrateJson as Record<string, unknown>,
|
||||
data: substrateData
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,12 +5,12 @@ import type { MetadataAll } from '../../interfaces/metadata';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { Metadata } from '../Metadata';
|
||||
import polkadotData from './hex/static-polkadot';
|
||||
import substrateData from './hex/static-substrate';
|
||||
import polkadotJson from './json/static-polkadot.json';
|
||||
import polkadotTypes from './json/static-polkadot-types.json';
|
||||
import substrateJson from './json/static-substrate.json';
|
||||
import substrateTypes from './json/static-substrate-types.json';
|
||||
import polkadotData from './polkadot-hex';
|
||||
import polkadotJson from './polkadot-json.json';
|
||||
import polkadotTypes from './polkadot-types.json';
|
||||
import substrateData from './substrate-hex';
|
||||
import substrateJson from './substrate-json.json';
|
||||
import substrateTypes from './substrate-types.json';
|
||||
|
||||
describe('MetadataV14 (substrate)', (): void => {
|
||||
// FIXME This is to be replaced with the proper version (here as a stop-gap)
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './hex/static-substrate';
|
||||
import substrateJson from './json/static-substrate.json';
|
||||
import { testMeta } from '../util/testUtil';
|
||||
import substrateData from './substrate-hex';
|
||||
import substrateJson from './substrate-json.json';
|
||||
|
||||
describe('MetadataV9 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestMeta(registry, 9, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 9, substrateData);
|
||||
|
||||
defaultValues(registry, substrateData);
|
||||
});
|
||||
testMeta(9, {
|
||||
substrate: {
|
||||
compare: substrateJson as Record<string, unknown>,
|
||||
data: substrateData
|
||||
}
|
||||
}, false);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { decorateStorage, Metadata } from '../metadata';
|
||||
import rpcDataV11 from '../metadata/v11/hex/static-substrate';
|
||||
import rpcDataV11 from '../metadata/v11/substrate-hex';
|
||||
import { StorageKey } from '.';
|
||||
|
||||
describe('StorageKey', (): void => {
|
||||
|
||||
Reference in New Issue
Block a user