Add Polkadot static metadata (#3827)
* Add Polkadot static metadata * v13 static polkadot * v14 static polkadot * CHANGELOG
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api';
|
||||
import { Metadata, TypeRegistry } from '@polkadot/types';
|
||||
import metaStatic from '@polkadot/types/metadata/static';
|
||||
import metaStatic from '@polkadot/types/metadata/static-substrate';
|
||||
|
||||
export function createApiWithAugmentations (): ApiPromise {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { Storage } from '@polkadot/types/metadata/decorate/types';
|
||||
|
||||
import { decorateStorage, Metadata, TypeRegistry } from '@polkadot/types';
|
||||
import metaStatic from '@polkadot/types/metadata/static';
|
||||
import metaStatic from '@polkadot/types/metadata/static-substrate';
|
||||
|
||||
import { extractStorageArgs } from './validate';
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import { decorateStorage, Metadata } from '@polkadot/types';
|
||||
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
|
||||
import rpcHeader from '@polkadot/types/json/Header.004.json';
|
||||
import rpcSignedBlock from '@polkadot/types/json/SignedBlock.004.immortal.json';
|
||||
import rpcMetadata from '@polkadot/types/metadata/static';
|
||||
import rpcMetadata from '@polkadot/types/metadata/static-substrate';
|
||||
import { assert, BN, bnToU8a, logger, u8aToHex } from '@polkadot/util';
|
||||
import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import fs from 'fs';
|
||||
import { GenericCall as Call, Metadata, TypeRegistry, Vec } from '@polkadot/types';
|
||||
import * as definitions from '@polkadot/types/interfaces/definitions';
|
||||
import { getStorage as getSubstrateStorage } from '@polkadot/types/metadata/decorate/storage/getStorage';
|
||||
import rpcdata from '@polkadot/types/metadata/static';
|
||||
import rpcdata from '@polkadot/types/metadata/static-substrate';
|
||||
import { Text } from '@polkadot/types/primitive';
|
||||
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
|
||||
import { stringCamelCase, stringLowerFirst } from '@polkadot/util';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { ExtraTypes } from '../generate/types';
|
||||
|
||||
import { Metadata, TypeRegistry } from '@polkadot/types';
|
||||
import staticData from '@polkadot/types/metadata/static';
|
||||
import staticData from '@polkadot/types/metadata/static-substrate';
|
||||
|
||||
import { registerDefinitions } from './register';
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { CodecTo } from '../types';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Metadata } from '../metadata';
|
||||
import rpcMetadata from '../metadata/static';
|
||||
import rpcMetadata from '../metadata/static-substrate';
|
||||
import { Text, U32, u128 as U128 } from '../primitive';
|
||||
import { Tuple } from '.';
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
import { createTypeUnsafe, TypeRegistry } from '../create';
|
||||
import { GenericAccountId as AccountId } from '../generic';
|
||||
import { Metadata } from '../metadata';
|
||||
import rpcMetadata from '../metadata/static';
|
||||
import rpcMetadata from '../metadata/static-substrate';
|
||||
import { Text } from '../primitive';
|
||||
import { Tuple, Vec } from '.';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Metadata } from '../metadata';
|
||||
import rpcMetadata from '../metadata/static';
|
||||
import rpcMetadata from '../metadata/static-substrate';
|
||||
import { GenericExtrinsic as Extrinsic } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Metadata } from '../metadata';
|
||||
import rpcMetadata from '../metadata/static';
|
||||
import rpcMetadata from '../metadata/static-substrate';
|
||||
import { GenericSignerPayload as SignerPayload } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BN } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decorateExtrinsics, Metadata } from '../../metadata';
|
||||
import rpcMetadata from '../../metadata/static';
|
||||
import rpcMetadata from '../../metadata/static-substrate';
|
||||
import { GenericExtrinsicV4 as Extrinsic } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { Metadata } from '../../metadata';
|
||||
import metadataStatic from '../../metadata/static';
|
||||
import metadataStatic from '../../metadata/static-substrate';
|
||||
import { GenericExtrinsicSignatureV4 as ExtrinsicSignature } from '.';
|
||||
|
||||
const signOptions = {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { TypeRegistry } from '../create';
|
||||
import block00300 from '../json/SignedBlock.003.00.json';
|
||||
import { Metadata } from '../metadata';
|
||||
import metadataStatic from '../metadata/static';
|
||||
import metadataStatic from '../metadata/static-substrate';
|
||||
import { GenericBlock as Block } from './Block';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Metadata } from '../metadata';
|
||||
import metadataStatic from '../metadata/static';
|
||||
import metadataStatic from '../metadata/static-substrate';
|
||||
import { GenericCall as Call } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { Codec } from './types';
|
||||
|
||||
import * as definitions from './interfaces/definitions';
|
||||
import metadataStatic from './metadata/static';
|
||||
import metadataStatic from './metadata/static-substrate';
|
||||
import { createTypeUnsafe, TypeRegistry } from './create';
|
||||
import * as exported from './index.types';
|
||||
import { Metadata } from './metadata';
|
||||
|
||||
@@ -8,7 +8,7 @@ import { TypeRegistry } from '../../create';
|
||||
import json1 from '../../json/EventRecord.001.json';
|
||||
import json3 from '../../json/EventRecord.003.json';
|
||||
import { Metadata } from '../../metadata';
|
||||
import rpcMetadata from '../../metadata/static';
|
||||
import rpcMetadata from '../../metadata/static-substrate';
|
||||
|
||||
describe('EventRecord', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Metadata } from './Metadata';
|
||||
import substrateData from './static';
|
||||
import substrateData from './static-substrate';
|
||||
|
||||
describe('Metadata', (): void => {
|
||||
it('allows creation from hex with JSON equivalence', (): void => {
|
||||
|
||||
@@ -6,8 +6,8 @@ import type { Constants } from '../types';
|
||||
|
||||
import { TypeRegistry } from '../../../create';
|
||||
import { Metadata } from '../../Metadata';
|
||||
import rpcMetadata from '../../static';
|
||||
import rpcMetadataV10 from '../../v10/static';
|
||||
import rpcMetadata from '../../static-substrate';
|
||||
import rpcMetadataV10 from '../../v10/static-substrate';
|
||||
import { decorateConstants } from '..';
|
||||
|
||||
function init (meta: string): [Constants, TypeRegistry] {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BN } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../../create';
|
||||
import { Metadata } from '../../Metadata';
|
||||
import metadataStatic from '../../static';
|
||||
import metadataStatic from '../../static-substrate';
|
||||
import { decorateExtrinsics } from '..';
|
||||
|
||||
const keyring = createTestPairs({ type: 'ed25519' }, false);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { Metadata } from '../Metadata';
|
||||
import json from '../static';
|
||||
import json from '../static-substrate';
|
||||
import { decorateConstants, decorateExtrinsics, decorateStorage } from './';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -6,7 +6,7 @@ import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../../create';
|
||||
import { Metadata } from '../../';
|
||||
import rpcMetadata from '../../static';
|
||||
import rpcMetadata from '../../static-substrate';
|
||||
import { decorateStorage } from '..';
|
||||
|
||||
const keyring = createTestPairs({ type: 'ed25519' });
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import metadata from './v13/static';
|
||||
import metadata from './v13/static-polkadot';
|
||||
|
||||
export default metadata;
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import metadata from './v13/static-substrate';
|
||||
|
||||
export default metadata;
|
||||
@@ -11,16 +11,16 @@ import { Metadata } from '../Metadata';
|
||||
import { getUniqTypes } from './getUniqTypes';
|
||||
|
||||
/** @internal */
|
||||
export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry, version: number, rpcData: string, staticSubstrate: Record<string, unknown>): void {
|
||||
it('decodes latest substrate properly', (): void => {
|
||||
const metadata = new Metadata(registry, rpcData);
|
||||
export function decodeLatestMeta<Modules extends Codec> (registry: Registry, version: number, staticMeta: string, staticJson: Record<string, unknown>): void {
|
||||
it('decodes metadata properly', (): void => {
|
||||
const metadata = new Metadata(registry, staticMeta);
|
||||
|
||||
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(staticSubstrate);
|
||||
expect(metadata.toJSON()).toEqual(staticJson);
|
||||
} catch (error) {
|
||||
console.error(stringify(metadata.toJSON()));
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { Metadata } from '../Metadata';
|
||||
import staticData from '../static';
|
||||
import staticData from '../static-substrate';
|
||||
|
||||
describe('toCallsOnly', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateData from './static-substrate';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateJson from './static-substrate.json';
|
||||
|
||||
describe('MetadataV10 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestSubstrate(registry, 10, substrateData, substrateJson);
|
||||
decodeLatestMeta(registry, 10, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 10, substrateData);
|
||||
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateData from './static-substrate';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateJson from './static-substrate.json';
|
||||
|
||||
describe('MetadataV11 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestSubstrate(registry, 11, substrateData, substrateJson);
|
||||
decodeLatestMeta(registry, 11, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 11, substrateData);
|
||||
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateData from './static-substrate';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateJson from './static-substrate.json';
|
||||
|
||||
describe('MetadataV12 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestSubstrate(registry, 12, substrateData, substrateJson);
|
||||
decodeLatestMeta(registry, 12, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 12, substrateData);
|
||||
|
||||
|
||||
@@ -2,16 +2,32 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import polkadotData from './static-polkadot';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import polkadotJson from './static-polkadot.json';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateData from './static-substrate';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateJson from './static-substrate.json';
|
||||
|
||||
describe('MetadataV13 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestSubstrate(registry, 13, substrateData, substrateJson);
|
||||
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);
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -5,9 +5,16 @@ import type { MetadataAll } from '../../interfaces/metadata';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { Metadata } from '../Metadata';
|
||||
import substrateData from './static';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import polkadotData from './static-polkadot';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import polkadotJson from './static-polkadot.json';
|
||||
import polkadotTypes from './static-polkadot-types.json';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateData from './static-substrate';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateJson from './static-substrate.json';
|
||||
import substrateTypes from './static-types.json';
|
||||
import substrateTypes from './static-substrate-types.json';
|
||||
|
||||
describe('MetadataV14 (substrate)', (): void => {
|
||||
// FIXME This is to be replaced with the proper version (here as a stop-gap)
|
||||
@@ -45,3 +52,40 @@ describe('MetadataV14 (substrate)', (): void => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('MetadataV14 (polkadot)', (): void => {
|
||||
// FIXME This is to be replaced with the proper version (here as a stop-gap)
|
||||
it('parses', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, polkadotData);
|
||||
const all = metadata.get('metadata') as MetadataAll;
|
||||
const v14 = all.asV14;
|
||||
const jsonStruct = v14.toJSON();
|
||||
const jsonTypes = v14.lookup.types.toJSON();
|
||||
|
||||
delete (jsonStruct as Record<string, unknown>).lookup;
|
||||
|
||||
const allJson = {
|
||||
magicNumber: 1635018093,
|
||||
metadata: {
|
||||
v14: jsonStruct
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
expect(allJson).toEqual(polkadotJson);
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify(allJson));
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
try {
|
||||
expect(jsonTypes).toEqual(polkadotTypes);
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify(jsonTypes));
|
||||
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -2,14 +2,16 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestMeta, defaultValues, toLatest } from '../util/testUtil';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateData from './static-substrate';
|
||||
// eslint-disable-next-line import/no-duplicates
|
||||
import substrateJson from './static-substrate.json';
|
||||
|
||||
describe('MetadataV9 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestSubstrate(registry, 9, substrateData, substrateJson);
|
||||
decodeLatestMeta(registry, 9, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 9, substrateData);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { decorateStorage, Metadata } from '../metadata';
|
||||
import rpcDataV11 from '../metadata/v11/static';
|
||||
import rpcDataV11 from '../metadata/v11/static-substrate';
|
||||
import { StorageKey } from '.';
|
||||
|
||||
describe('StorageKey', (): void => {
|
||||
|
||||
Reference in New Issue
Block a user