Explicit Decorate creation with Metadata (#2622)
* Explicit Decorate creation with Metadata * typo * Update generator * Adjust Registry findMetaError sig
This commit is contained in:
@@ -4,11 +4,16 @@
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import Decorated from './Decorated';
|
||||
import Metadata from '../Metadata';
|
||||
import json from '../Metadata/static';
|
||||
import Decorated from './Decorated';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const decorated = new Decorated(registry, json);
|
||||
const metadata = new Metadata(registry, json);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
describe('Decorated', () => {
|
||||
it('should correctly get Alice\'s nonce storage key (u8a)', (): void => {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
import { ModulesWithCalls, Registry } from '@polkadot/types/types';
|
||||
import { Constants, Storage } from './types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import Metadata from '../Metadata';
|
||||
import constantsFromMeta from './consts/fromMetadata';
|
||||
import extrinsicsFromMeta from './extrinsics/fromMetadata';
|
||||
@@ -25,9 +27,11 @@ export default class Decorated {
|
||||
|
||||
public readonly tx: ModulesWithCalls;
|
||||
|
||||
constructor (registry: Registry, value?: Uint8Array | string | Metadata) {
|
||||
constructor (registry: Registry, value: Metadata) {
|
||||
assert(value instanceof Metadata, 'You need to pass a valid Metadata instance to Decorated');
|
||||
|
||||
this.registry = registry;
|
||||
this.metadata = value instanceof Metadata ? value : new Metadata(registry, value);
|
||||
this.metadata = value;
|
||||
|
||||
// decoration
|
||||
this.tx = extrinsicsFromMeta(registry, this.metadata);
|
||||
|
||||
@@ -5,6 +5,7 @@ import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import Metadata from '../../../Metadata';
|
||||
import rpcMetadata from '../../../Metadata/static';
|
||||
import rpcMetadataV8 from '../../../Metadata/v8/static';
|
||||
import Decorated from '../../Decorated';
|
||||
@@ -14,7 +15,11 @@ const keyring = testingPairs({ type: 'ed25519' });
|
||||
describe('fromMetadata', (): void => {
|
||||
describe('latest', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const decorated = new Decorated(registry, rpcMetadata);
|
||||
const metadata = new Metadata(registry, rpcMetadata);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should throw if the storage function expects an argument', (): void => {
|
||||
expect((): any => decorated.query.balances.account()).toThrowError(/requires one argument/);
|
||||
@@ -37,7 +42,11 @@ describe('fromMetadata', (): void => {
|
||||
|
||||
describe('V8', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const decorated = new Decorated(registry, rpcMetadataV8);
|
||||
const metadata = new Metadata(registry, rpcMetadataV8);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const decorated = new Decorated(registry, metadata);
|
||||
|
||||
it('should return the correct length-prefixed storage key', (): void => {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user