From 345c536380e44c97eb305f4fb009db38bc0c67c1 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 16 Sep 2021 07:57:13 +0300 Subject: [PATCH] Fix v13 toCallsOnly path (#3957) --- packages/types/src/metadata/Metadata.spec.ts | 20 ++++++++++++------ .../types/src/metadata/MetadataVersioned.ts | 2 +- .../src/metadata/util/toCallsOnly.spec.ts | 21 +++++++++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/packages/types/src/metadata/Metadata.spec.ts b/packages/types/src/metadata/Metadata.spec.ts index 4affe3bd75..fcaa7ed32e 100644 --- a/packages/types/src/metadata/Metadata.spec.ts +++ b/packages/types/src/metadata/Metadata.spec.ts @@ -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 = { + 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); }); }); diff --git a/packages/types/src/metadata/MetadataVersioned.ts b/packages/types/src/metadata/MetadataVersioned.ts index 6be92a1701..7b1acb2392 100644 --- a/packages/types/src/metadata/MetadataVersioned.ts +++ b/packages/types/src/metadata/MetadataVersioned.ts @@ -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) }); } diff --git a/packages/types/src/metadata/util/toCallsOnly.spec.ts b/packages/types/src/metadata/util/toCallsOnly.spec.ts index 30371dbb66..5055556e9a 100644 --- a/packages/types/src/metadata/util/toCallsOnly.spec.ts +++ b/packages/types/src/metadata/util/toCallsOnly.spec.ts @@ -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);