Fix v13 toCallsOnly path (#3957)

This commit is contained in:
Jaco
2021-09-16 06:57:13 +02:00
committed by GitHub
parent d527a02d2f
commit 345c536380
3 changed files with 32 additions and 11 deletions
+14 -6
View File
@@ -1,23 +1,31 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import polkadot from '@polkadot/types-support/metadata//static-polkadot';
import kusama from '@polkadot/types-support/metadata/static-kusama';
import polkadot from '@polkadot/types-support/metadata/static-polkadot';
import substrate from '@polkadot/types-support/metadata/static-substrate';
import { TypeRegistry } from '../create';
import { Metadata } from './Metadata';
const allData: Record<string, string> = {
kusama,
polkadot,
substrate
};
describe('Metadata', (): void => {
it.each(['polkadot', 'substrate'])('allows creation from hex on %s', (type): void => {
const test = new Metadata(new TypeRegistry(), allData[type]);
describe.each(['kusama', 'polkadot', 'substrate'])('%s metadata', (type): void => {
const metadata = new Metadata(new TypeRegistry(), allData[type]);
it('allows creation from hex', (): void => {
expect(
new Metadata(new TypeRegistry(), test.toHex()).toJSON()
).toEqual(test.toJSON());
new Metadata(new TypeRegistry(), metadata.toHex()).toJSON()
).toEqual(metadata.toJSON());
});
it('has a sane toCallsOnly', (): void => {
expect(
metadata.asCallsOnly.toU8a().length > 65536
).toBe(true);
});
});
@@ -73,7 +73,7 @@ export class MetadataVersioned extends Struct {
public get asCallsOnly (): MetadataVersioned {
return new MetadataVersioned(this.registry, {
magicNumber: this.magicNumber,
metadata: this.registry.createType('MetadataAll', toCallsOnly(this.registry, this.asLatest), this.version)
metadata: this.registry.createType('MetadataAll', toCallsOnly(this.registry, this.asLatest), LATEST_VERSION)
});
}
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import staticData from '@polkadot/types-support/metadata/static-substrate';
import staticLatest from '@polkadot/types-support/metadata/static-substrate';
import staticV13 from '@polkadot/types-support/metadata/v13/substrate-hex';
import { TypeRegistry } from '../../create';
import { Metadata } from '../Metadata';
@@ -9,8 +10,20 @@ import { Metadata } from '../Metadata';
describe('toCallsOnly', (): void => {
const registry = new TypeRegistry();
it('creates a calls-only version of the metadata', (): void => {
const stripped = new Metadata(registry, staticData).asCallsOnly;
it('creates a calls-only version of the latest', (): void => {
const stripped = new Metadata(registry, staticLatest).asCallsOnly;
try {
expect(stripped).toBeDefined();
} catch (error) {
console.error(JSON.stringify(stripped));
throw error;
}
});
it('creates a calls-only version of V13', (): void => {
const stripped = new Metadata(registry, staticV13).asCallsOnly;
try {
expect(stripped).toBeDefined();
@@ -22,7 +35,7 @@ describe('toCallsOnly', (): void => {
});
it('can serialize from the input', (): void => {
const s1 = new Metadata(registry, staticData).asCallsOnly.toU8a();
const s1 = new Metadata(registry, staticLatest).asCallsOnly.toU8a();
const s2 = new Metadata(registry, s1).asCallsOnly.toU8a();
expect(s1).toEqual(s2);