Explicit Decorate creation with Metadata (#2622)
* Explicit Decorate creation with Metadata * typo * Update generator * Adjust Registry findMetaError sig
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import Metadata from '@polkadot/metadata/Decorated';
|
||||
import Decorated from '@polkadot/metadata/Decorated';
|
||||
import Metadata from '@polkadot/metadata/Metadata';
|
||||
import rpcDataV3 from '@polkadot/metadata/Metadata/v3/static';
|
||||
import rpcDataV4 from '@polkadot/metadata/Metadata/v4/static';
|
||||
import rpcDataV5 from '@polkadot/metadata/Metadata/v5/static';
|
||||
@@ -20,11 +21,15 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV3 (uses xxHash by default)', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV3);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should correctly get Alice\'s freeBalance storage key (hex)', (): void => {
|
||||
expect(
|
||||
new StorageKey(
|
||||
registry,
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.balances
|
||||
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
|
||||
@@ -37,7 +42,7 @@ describe('StorageKey', (): void => {
|
||||
expect(
|
||||
new StorageKey(
|
||||
registry,
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.balances
|
||||
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
|
||||
@@ -53,11 +58,15 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV4 (uses xxHash by default)', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV4);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should correctly get Alice\'s freeBalance storage key (hex)', (): void => {
|
||||
expect(
|
||||
new StorageKey(
|
||||
registry,
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.balances
|
||||
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
|
||||
@@ -70,7 +79,7 @@ describe('StorageKey', (): void => {
|
||||
expect(
|
||||
new StorageKey(
|
||||
registry,
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.balances
|
||||
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
|
||||
@@ -87,7 +96,7 @@ describe('StorageKey', (): void => {
|
||||
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -100,7 +109,7 @@ describe('StorageKey', (): void => {
|
||||
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -114,10 +123,14 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV5', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV5);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -130,7 +143,7 @@ describe('StorageKey', (): void => {
|
||||
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -144,10 +157,14 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV6', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV6);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -160,7 +177,7 @@ describe('StorageKey', (): void => {
|
||||
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -174,10 +191,14 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV7', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV7);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -190,7 +211,7 @@ describe('StorageKey', (): void => {
|
||||
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -204,10 +225,14 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV8', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV8);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -220,7 +245,7 @@ describe('StorageKey', (): void => {
|
||||
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
|
||||
expect(
|
||||
new StorageKey(registry, [
|
||||
metadata
|
||||
decorated
|
||||
.query
|
||||
.system
|
||||
.eventTopics,
|
||||
@@ -234,10 +259,14 @@ describe('StorageKey', (): void => {
|
||||
describe('with MetadataV11', (): void => {
|
||||
const metadata = new Metadata(registry, rpcDataV11);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should allow decoding of a DoubleMap key', (): void => {
|
||||
const key = new StorageKey(registry, '0x5f3e4907f716ac89b6347d15ececedca8bde0a0ea8864605e3b68ed9cb2da01b66ccada06515787c10000000e535263148daaf49be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f');
|
||||
|
||||
key.setMeta(metadata.query.staking.erasStakers.meta);
|
||||
key.setMeta(decorated.query.staking.erasStakers.meta);
|
||||
|
||||
expect(key.toHuman()).toEqual([
|
||||
'16',
|
||||
@@ -248,7 +277,7 @@ describe('StorageKey', (): void => {
|
||||
it('should allow decoding of a Map key', (): void => {
|
||||
const key = new StorageKey(registry, '0x426e15054d267946093858132eb537f191ca57b0c4b20b29ae7e99d6201d680cc906f7710aa165d62c709012f807af8fc3f0d2abb0c51ca9a88d4ef24d1a092bf89dacf5ce63ea1d');
|
||||
|
||||
key.setMeta(metadata.query.society.defenderVotes.meta);
|
||||
key.setMeta(decorated.query.society.defenderVotes.meta);
|
||||
|
||||
expect(key.toHuman()).toEqual([
|
||||
'5D4yQHKfqCQYThhHmTfN1JEDi47uyDJc1xg9eZfAG1R7FC7J'
|
||||
|
||||
@@ -142,7 +142,7 @@ export interface Registry {
|
||||
readonly signedExtensions: string[];
|
||||
|
||||
findMetaCall (callIndex: Uint8Array): CallFunction;
|
||||
findMetaError (errorIndex: Uint8Array): RegistryError;
|
||||
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN }): RegistryError;
|
||||
// due to same circular imports where types don't really want to import from EventData,
|
||||
// keep this as a generic Codec, however the actual impl. returns the correct
|
||||
findMetaEvent (eventIndex: Uint8Array): Constructor<any>;
|
||||
|
||||
Reference in New Issue
Block a user