From 700eb7e1f458921c1122890af9b38985240c85aa Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 26 Jul 2019 11:12:17 +0200 Subject: [PATCH] Remove injectDefinitions import, prefer injector (#1195) * Convert RPC classes to primitive classes or /srml types * Lint passes... lokking at tests next. * Tests pass. * Types with basic docs (lots of work here) * Update StorageKey.spec.ts * Add injector to metadata doc generation * Fix import * Remove injectDefinitions import, prefer injector --- .../consts/fromMetadata/fromMetadata.spec.ts | 5 ++--- .../fromMetadata/fromMetadata.spec.ts | 5 ++--- .../api-metadata/src/extrinsics/index.spec.ts | 7 ++----- .../storage/fromMetadata/fromMetadata.spec.ts | 5 ++--- .../src/storage/fromMetadata/storage.spec.ts | 6 +----- .../storage/fromMetadata/substrate.spec.ts | 6 +----- packages/rpc-core/src/formatting.spec.ts | 5 ++--- packages/types/src/Metadata/util/testUtil.ts | 9 ++------ packages/types/src/codec/Compact.spec.ts | 7 ++----- packages/types/src/codec/EnumType.spec.ts | 7 ++----- packages/types/src/codec/Option.spec.ts | 7 ++----- packages/types/src/codec/Struct.spec.ts | 7 ++----- packages/types/src/codec/Tuple.spec.ts | 4 ++-- packages/types/src/codec/createType.spec.ts | 11 ++-------- packages/types/src/index.spec.ts | 7 ++----- packages/types/src/injector.ts | 18 +++++++++++++++- .../types/src/primitive/AccountId.spec.ts | 7 ++----- packages/types/src/primitive/Block.spec.ts | 4 ++-- packages/types/src/primitive/Bytes.spec.ts | 7 ++----- packages/types/src/primitive/Digest.spec.ts | 7 ++----- .../primitive/Extrinsic/ExtrinsicEra.spec.ts | 7 ++----- .../Extrinsic/v2/ExtrinsicExtra.spec.ts | 7 ++----- .../Extrinsic/v2/ExtrinsicSignature.spec.ts | 7 ++----- packages/types/src/primitive/Header.spec.ts | 7 ++----- packages/types/src/primitive/Vote.spec.ts | 7 ++----- packages/types/src/srml/index.ts | 21 ------------------- .../src/srml/rpc/ChainProperties.spec.ts | 7 ++----- .../src/srml/rpc/ExtrinsicStatus.spec.ts | 5 ++--- .../types/src/srml/rpc/KeyValueOption.spec.ts | 7 ++----- .../types/src/srml/rpc/RuntimeVersion.spec.ts | 4 ++-- .../types/src/srml/rpc/SignedBlock.spec.ts | 4 ++-- .../src/srml/rpc/StorageChangeSet.spec.ts | 7 ++----- .../types/src/srml/runtime/KeyValue.spec.ts | 7 ++----- .../types/src/srml/system/EventRecord.spec.ts | 11 +++------- 34 files changed, 80 insertions(+), 169 deletions(-) delete mode 100644 packages/types/src/srml/index.ts diff --git a/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts index 7ce0c0b8d0..4f1a7b8579 100644 --- a/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts @@ -2,14 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '@polkadot/types/injector'; + import { ClassOf, Metadata } from '@polkadot/types'; import json from '@polkadot/types/Metadata/static'; -import { injectDefinitions } from '@polkadot/types/srml'; import fromMetadata from '../fromMetadata'; -injectDefinitions(); - // Use the pre-generated metadata const metadata = new Metadata(json); const consts = fromMetadata(metadata); diff --git a/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts index 1f26e97122..a2694fca5f 100644 --- a/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts @@ -2,14 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '@polkadot/types/injector'; + import { Extrinsic, Metadata } from '@polkadot/types'; -import { injectDefinitions } from '@polkadot/types/srml'; import json from '@polkadot/types/Metadata/v7/static'; import fromMetadata from '.'; -injectDefinitions(); - // Use the pre-generated metadata const metadata = new Metadata(json); const newExtrinsics = fromMetadata(metadata); diff --git a/packages/api-metadata/src/extrinsics/index.spec.ts b/packages/api-metadata/src/extrinsics/index.spec.ts index 32e13edb62..a4d3ef522d 100644 --- a/packages/api-metadata/src/extrinsics/index.spec.ts +++ b/packages/api-metadata/src/extrinsics/index.spec.ts @@ -2,8 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '@polkadot/types/injector'; + import testingPairs from '@polkadot/keyring/testingPairs'; -import { injectDefinitions } from '@polkadot/types/srml'; import { Extrinsic } from '@polkadot/types'; import extrinsics from './static'; @@ -11,10 +12,6 @@ import extrinsics from './static'; const keyring = testingPairs({ type: 'ed25519' }, false); describe('extrinsics', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('encodes an actual transfer (actual data)', (): void => { expect( new Extrinsic( diff --git a/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts index ebfa2e4159..24c3e03e24 100644 --- a/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts @@ -2,16 +2,15 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '@polkadot/types/injector'; + import testingPairs from '@polkadot/keyring/testingPairs'; import { Metadata } from '@polkadot/types'; import json from '@polkadot/types/Metadata/static'; -import { injectDefinitions } from '@polkadot/types/srml'; import { u8aToHex } from '@polkadot/util'; import fromMetadata from '../fromMetadata'; -injectDefinitions(); - const keyring = testingPairs({ type: 'ed25519' }); // Use the pre-generated metadata diff --git a/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts b/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts index 9da17d835c..13ae603a0c 100644 --- a/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts +++ b/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts @@ -2,15 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '@polkadot/types/srml'; +import '@polkadot/types/injector'; import { storage } from './storage'; describe('storage', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('should return well known keys', (): void => { expect(typeof storage.substrate).toBe('object'); diff --git a/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts b/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts index 0c0074e2bc..8f4bf46825 100644 --- a/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts +++ b/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts @@ -2,15 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '@polkadot/types/srml'; +import '@polkadot/types/injector'; import { authorityCount, authorityPrefix, changesTrieConfig, childStorageKeyPrefix, code, extrinsicIndex, heapPages } from './substrate'; describe('substrate', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - // @deprecated: The ':auth:' (authorityPrefix) and ':auth:len' (authorityCount) storage keys // have been removed in https://github.com/paritytech/substrate/pull/2802 it('authorityCount should return the correct storage key', (): void => { diff --git a/packages/rpc-core/src/formatting.spec.ts b/packages/rpc-core/src/formatting.spec.ts index abf0909688..1a0388aaf6 100644 --- a/packages/rpc-core/src/formatting.spec.ts +++ b/packages/rpc-core/src/formatting.spec.ts @@ -2,13 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '@polkadot/types/injector'; + import { Balance } from '@polkadot/types/srml/types'; import { Codec } from '@polkadot/types/types'; import fromMetadata from '@polkadot/api-metadata/storage/fromMetadata'; import { Storage } from '@polkadot/api-metadata/storage/types'; import Metadata from '@polkadot/types/Metadata'; -import { injectDefinitions } from '@polkadot/types/srml'; import rpcMetadataV3 from '@polkadot/types/Metadata/v3/static'; import rpcMetadataV4 from '@polkadot/types/Metadata/v4/static'; import rpcMetadataV5 from '@polkadot/types/Metadata/v5/static'; @@ -33,8 +34,6 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str let provider: any; beforeEach((): void => { - injectDefinitions(); - provider = { send: jest.fn((method, [key]): Promise => Promise.resolve( diff --git a/packages/types/src/Metadata/util/testUtil.ts b/packages/types/src/Metadata/util/testUtil.ts index 03d74d0eef..3199f30e3a 100644 --- a/packages/types/src/Metadata/util/testUtil.ts +++ b/packages/types/src/Metadata/util/testUtil.ts @@ -2,8 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import extrinsicsFromMeta from '@polkadot/api-metadata/extrinsics/fromMetadata'; -import { injectDefinitions } from '@polkadot/types/srml'; import createType from '../../codec/createType'; import Metadata from '../Metadata'; @@ -21,8 +22,6 @@ export function decodeLatestSubstrate ( latestSubstrate: object ): void { it('decodes latest substrate properly', (): void => { - injectDefinitions(); - const metadata = new Metadata(rpcData); console.error(JSON.stringify(metadata.toJSON())); @@ -39,8 +38,6 @@ export function decodeLatestSubstrate ( */ export function toV7 (version: number, rpcData: string): void { it('converts to V7', (): void => { - injectDefinitions(); - const metadata = new Metadata(rpcData)[`asV${version}` as keyof Metadata]; const metadataV7 = new Metadata(rpcData).asV7; @@ -55,8 +52,6 @@ export function toV7 (version: number, rpcData: string): */ export function defaultValues (rpcData: string): void { describe('storage with default values', (): void => { - injectDefinitions(); - const metadata = new Metadata(rpcData); Method.injectMethods(extrinsicsFromMeta(metadata)); diff --git a/packages/types/src/codec/Compact.spec.ts b/packages/types/src/codec/Compact.spec.ts index 501632bb04..b304ba2d38 100644 --- a/packages/types/src/codec/Compact.spec.ts +++ b/packages/types/src/codec/Compact.spec.ts @@ -2,6 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import { Balance, BlockNumber } from '../srml/runtime/types'; import BN from 'bn.js'; @@ -9,15 +11,10 @@ import BN from 'bn.js'; import createType, { ClassOf } from '../codec/createType'; import Moment from '../primitive/Moment'; import U32 from '../primitive/U32'; -import { injectDefinitions } from '../srml'; import Compact from './Compact'; import UInt from './UInt'; describe('Compact', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - describe('encodeU8a', (): void => { it('encodes short u8', (): void => { expect( diff --git a/packages/types/src/codec/EnumType.spec.ts b/packages/types/src/codec/EnumType.spec.ts index 6096f57c19..8700da68a6 100644 --- a/packages/types/src/codec/EnumType.spec.ts +++ b/packages/types/src/codec/EnumType.spec.ts @@ -2,17 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import Enum from './Enum'; import Null from '../primitive/Null'; import Text from '../primitive/Text'; import U32 from '../primitive/U32'; -import { injectDefinitions } from '../srml'; describe('Enum', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - describe('typed enum (previously EnumType)', (): void => { it('provides a clean toString() (value)', (): void => { expect( diff --git a/packages/types/src/codec/Option.spec.ts b/packages/types/src/codec/Option.spec.ts index 51c7c52677..dbc09935a1 100644 --- a/packages/types/src/codec/Option.spec.ts +++ b/packages/types/src/codec/Option.spec.ts @@ -2,7 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '../srml'; +import '../injector'; + import Option from './Option'; import Bytes from '../primitive/Bytes'; import U32 from '../primitive/U32'; @@ -24,10 +25,6 @@ const testEncode = (to: string, expected: any): void => }); describe('Option', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('converts undefined/null to empty', (): void => { expect(new Option(Text, undefined).isNone).toBe(true); expect(new Option(Text, null).isNone).toBe(true); diff --git a/packages/types/src/codec/Struct.spec.ts b/packages/types/src/codec/Struct.spec.ts index c3d6574c0c..3bd73913f5 100644 --- a/packages/types/src/codec/Struct.spec.ts +++ b/packages/types/src/codec/Struct.spec.ts @@ -2,20 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import { ClassOf } from '../codec/createType'; import AccountId from '../primitive/AccountId'; import Text from '../primitive/Text'; import U32 from '../primitive/U32'; -import { injectDefinitions } from '../srml'; import { CodecTo } from '../types'; import Struct from './Struct'; import Vec from './Vec'; describe('Struct', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - describe('decoding', (): void => { const testDecode = (type: string, input: any): void => it(`can decode from ${type}`, (): void => { diff --git a/packages/types/src/codec/Tuple.spec.ts b/packages/types/src/codec/Tuple.spec.ts index 6f9e1d3849..76a76f8d02 100644 --- a/packages/types/src/codec/Tuple.spec.ts +++ b/packages/types/src/codec/Tuple.spec.ts @@ -2,6 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import { VoteThreshold } from '../srml/elections/types'; import { BlockNumber } from '../srml/runtime/types'; import { CodecTo } from '../types'; @@ -12,14 +14,12 @@ import { ClassOf } from '../codec/createType'; import Method from '../primitive/Method'; import Text from '../primitive/Text'; import U32 from '../primitive/U32'; -import { injectDefinitions } from '../srml'; import Tuple from './Tuple'; describe('Tuple', (): void => { let tuple: Tuple; beforeEach((): void => { - injectDefinitions(); tuple = new Tuple( [Text, U32], ['bazzing', 69] diff --git a/packages/types/src/codec/createType.spec.ts b/packages/types/src/codec/createType.spec.ts index e6e975ce86..f6805f4d29 100644 --- a/packages/types/src/codec/createType.spec.ts +++ b/packages/types/src/codec/createType.spec.ts @@ -2,11 +2,12 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import { Codec, Constructor } from '../types'; import createType, { TypeDef, TypeDefInfo, createClass, getTypeClass, getTypeDef, typeSplit, ClassOf } from './createType'; import Text from '../primitive/Text'; -import { injectDefinitions } from '../srml'; import CodecSet from './Set'; describe('typeSplit', (): void => { @@ -214,10 +215,6 @@ describe('getTypeClass', (): void => { }); describe('createClass', (): void => { - beforeAll((): void => { - injectDefinitions(); - }); - it('should memoize from strings', (): void => { const a = createClass('BabeWeight'); const b = createClass('BabeWeight'); @@ -300,10 +297,6 @@ describe('createType', (): void => { }); describe('instanceof', (): void => { - beforeAll((): void => { - injectDefinitions(); - }); - it('instanceof should work (primitive type)', (): void => { const value = createType('Balance', 1234); diff --git a/packages/types/src/index.spec.ts b/packages/types/src/index.spec.ts index cc54ca1e7b..5425870c38 100644 --- a/packages/types/src/index.spec.ts +++ b/packages/types/src/index.spec.ts @@ -2,20 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import './injector'; + import extrinsics from '@polkadot/api-metadata/extrinsics/static'; import { Codec, Constructor } from './types'; import * as Classes from './index.types'; -import { injectDefinitions } from './srml'; const Types = Classes as Record; const UNCONSTRUCTABLE = ['origin', 'usize', 'vote']; describe('types', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - describe('default creation', (): void => { Object.keys(Types).forEach((name): void => { it(`creates an empty ${name}`, (): void => { diff --git a/packages/types/src/injector.ts b/packages/types/src/injector.ts index d717c67835..6a0741712d 100644 --- a/packages/types/src/injector.ts +++ b/packages/types/src/injector.ts @@ -2,6 +2,22 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from './srml'; +import { ClassOf } from './codec/createType'; +import getTypeRegistry from './codec/typeRegistry'; +import * as srmlTypes from './srml/definitions'; + +/** + * @description A utility method that injects all the srml definitions into the type registry + */ +export function injectDefinitions (): void { + const registry = getTypeRegistry(); + + Object.values(srmlTypes).forEach(({ types }): void => + registry.register(types) + ); + + // Here we setup the fallbacks + ClassOf('EventRecord').Fallback = ClassOf('EventRecord0to76'); +} injectDefinitions(); diff --git a/packages/types/src/primitive/AccountId.spec.ts b/packages/types/src/primitive/AccountId.spec.ts index 4448376bd7..457512c33f 100644 --- a/packages/types/src/primitive/AccountId.spec.ts +++ b/packages/types/src/primitive/AccountId.spec.ts @@ -2,20 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import { setAddressPrefix } from '@polkadot/util-crypto'; import createType from '../codec/createType'; import U8a from '../codec/U8a'; import Vec from '../codec/Vec'; import jsonVec from '../json/AccountIdVec.001.json'; -import { injectDefinitions } from '../srml'; import AccountId from './AccountId'; describe('AccountId', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - describe('defaults', (): void => { const id = new AccountId(); diff --git a/packages/types/src/primitive/Block.spec.ts b/packages/types/src/primitive/Block.spec.ts index ab44061771..e595178e6b 100644 --- a/packages/types/src/primitive/Block.spec.ts +++ b/packages/types/src/primitive/Block.spec.ts @@ -2,16 +2,16 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import extrinsics from '@polkadot/api-metadata/extrinsics/static'; import block00300 from '../json/SignedBlock.003.00.json'; -import { injectDefinitions } from '../srml'; import Method from './Method'; import Block from './Block'; describe('Block', (): void => { beforeEach((): void => { - injectDefinitions(); Method.injectMethods(extrinsics); }); diff --git a/packages/types/src/primitive/Bytes.spec.ts b/packages/types/src/primitive/Bytes.spec.ts index 4973fffea8..5ac979cbae 100644 --- a/packages/types/src/primitive/Bytes.spec.ts +++ b/packages/types/src/primitive/Bytes.spec.ts @@ -2,15 +2,12 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import createType from '../codec/createType'; -import { injectDefinitions } from '../srml'; import Bytes from './Bytes'; describe('Bytes', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - const CODE = new Uint8Array([0x14, 0x3a, 0x63, 0x6f, 0x64, 0x65]); describe('construction', (): void => { diff --git a/packages/types/src/primitive/Digest.spec.ts b/packages/types/src/primitive/Digest.spec.ts index f5842dd0c0..52998201de 100644 --- a/packages/types/src/primitive/Digest.spec.ts +++ b/packages/types/src/primitive/Digest.spec.ts @@ -2,17 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '../srml'; +import '../injector'; + import json3 from '../json/Header.003.json'; import block1 from '../json/SignedBlock.003.00.json'; import ConsensusEngineId, { CID_AURA, CID_BABE, CID_GRPA } from './ConsensusEngineId'; import Digest from './Digest'; describe('Digest', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('decodes logs with consensus', (): void => { const digest = new Digest(json3.result.digest); diff --git a/packages/types/src/primitive/Extrinsic/ExtrinsicEra.spec.ts b/packages/types/src/primitive/Extrinsic/ExtrinsicEra.spec.ts index 7ba79dc298..b76b720af7 100644 --- a/packages/types/src/primitive/Extrinsic/ExtrinsicEra.spec.ts +++ b/packages/types/src/primitive/Extrinsic/ExtrinsicEra.spec.ts @@ -2,14 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '../../srml'; +import '../../injector'; + import ExtrinsicEra from './ExtrinsicEra'; describe('ExtrinsicEra', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('decodes an Extrinsic Era with immortal', (): void => { const extrinsicEra = new ExtrinsicEra(new Uint8Array([0])); diff --git a/packages/types/src/primitive/Extrinsic/v2/ExtrinsicExtra.spec.ts b/packages/types/src/primitive/Extrinsic/v2/ExtrinsicExtra.spec.ts index 8cddded016..b84db55e04 100644 --- a/packages/types/src/primitive/Extrinsic/v2/ExtrinsicExtra.spec.ts +++ b/packages/types/src/primitive/Extrinsic/v2/ExtrinsicExtra.spec.ts @@ -2,14 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '../../../srml'; +import '../../../injector'; + import ExtrinsicExtra from './ExtrinsicExtra'; describe('ExtrinsicExtraV2', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('encodes to a sane Uint8Array (default construction)', (): void => { expect( new ExtrinsicExtra().toU8a() diff --git a/packages/types/src/primitive/Extrinsic/v2/ExtrinsicSignature.spec.ts b/packages/types/src/primitive/Extrinsic/v2/ExtrinsicSignature.spec.ts index 5828595a6c..dc29ee1bdb 100644 --- a/packages/types/src/primitive/Extrinsic/v2/ExtrinsicSignature.spec.ts +++ b/packages/types/src/primitive/Extrinsic/v2/ExtrinsicSignature.spec.ts @@ -2,14 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '../../../srml'; +import '../../../injector'; + import ExtrinsicSignature from './ExtrinsicSignature'; describe('ExtrinsicSignatureV2', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('encodes to a sane Uint8Array', (): void => { const u8a = new Uint8Array([ // signer as an AccountIndex diff --git a/packages/types/src/primitive/Header.spec.ts b/packages/types/src/primitive/Header.spec.ts index 920d141ed8..11e3450c78 100644 --- a/packages/types/src/primitive/Header.spec.ts +++ b/packages/types/src/primitive/Header.spec.ts @@ -2,9 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import BN from 'bn.js'; -import { injectDefinitions } from '../srml'; import json1 from '../json/Header.001.json'; import json2 from '../json/Header.002.json'; import json3 from '../json/Header.003.json'; @@ -13,10 +14,6 @@ import block00301 from '../json/SignedBlock.003.01.json'; import Header from './Header'; describe('Header', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('decodes an actual JSON response', (): void => { const header = new Header(json1.result); diff --git a/packages/types/src/primitive/Vote.spec.ts b/packages/types/src/primitive/Vote.spec.ts index f6c2b55928..b3b8650db3 100644 --- a/packages/types/src/primitive/Vote.spec.ts +++ b/packages/types/src/primitive/Vote.spec.ts @@ -2,14 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '../srml'; +import '../injector'; + import Vote from './Vote'; describe('Vote', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('constructs via boolean true', (): void => { expect(new Vote(true).toU8a()).toEqual(new Uint8Array([128])); expect(new Vote(true).isAye).toBe(true); diff --git a/packages/types/src/srml/index.ts b/packages/types/src/srml/index.ts deleted file mode 100644 index 6662ac5e12..0000000000 --- a/packages/types/src/srml/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { ClassOf } from '../codec/createType'; -import getTypeRegistry from '../codec/typeRegistry'; -import * as srmlTypes from './definitions'; - -/** - * @description A utility method that injects all the srml definitions into the type registry - */ -export function injectDefinitions (): void { - const registry = getTypeRegistry(); - - Object.values(srmlTypes).forEach(({ types }): void => - registry.register(types) - ); - - // Here we setup the fallbacks - ClassOf('EventRecord').Fallback = ClassOf('EventRecord0to76'); -} diff --git a/packages/types/src/srml/rpc/ChainProperties.spec.ts b/packages/types/src/srml/rpc/ChainProperties.spec.ts index 3e9de60f02..fae7f8a7cd 100644 --- a/packages/types/src/srml/rpc/ChainProperties.spec.ts +++ b/packages/types/src/srml/rpc/ChainProperties.spec.ts @@ -2,14 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import createType from '../../codec/createType'; -import { injectDefinitions } from '..'; describe('ChainProperties', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('decodes from a null value', (): void => { expect( [...createType('ChainProperties', null).entries()] diff --git a/packages/types/src/srml/rpc/ExtrinsicStatus.spec.ts b/packages/types/src/srml/rpc/ExtrinsicStatus.spec.ts index 3095d7ef8f..4d98d92e2e 100644 --- a/packages/types/src/srml/rpc/ExtrinsicStatus.spec.ts +++ b/packages/types/src/srml/rpc/ExtrinsicStatus.spec.ts @@ -2,18 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import { ExtrinsicStatus } from './types'; import createType from '../../codec/createType'; import rpc from '../../json/ExtrinsicStatus.001.json'; -import { injectDefinitions } from '..'; describe('ExtrinsicStatus', (): void => { let status: ExtrinsicStatus; beforeEach((): void => { - injectDefinitions(); - status = createType('ExtrinsicStatus', rpc.params.result); }); diff --git a/packages/types/src/srml/rpc/KeyValueOption.spec.ts b/packages/types/src/srml/rpc/KeyValueOption.spec.ts index 18eff201aa..5c53ade4e3 100644 --- a/packages/types/src/srml/rpc/KeyValueOption.spec.ts +++ b/packages/types/src/srml/rpc/KeyValueOption.spec.ts @@ -2,14 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import createType from '../../codec/createType'; -import { injectDefinitions } from '..'; describe('KeyValueOption', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('exposes the properties for key/value', (): void => { const [key, value] = createType('KeyValueOption', [ '0x11223344' diff --git a/packages/types/src/srml/rpc/RuntimeVersion.spec.ts b/packages/types/src/srml/rpc/RuntimeVersion.spec.ts index 7dffe20aa4..6bcca5a327 100644 --- a/packages/types/src/srml/rpc/RuntimeVersion.spec.ts +++ b/packages/types/src/srml/rpc/RuntimeVersion.spec.ts @@ -2,17 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import { RuntimeVersion } from './types'; import createType from '../../codec/createType'; import rpc from '../../json/RuntimeVersion.002.json'; -import { injectDefinitions } from '..'; describe('RuntimeVersion', (): void => { let version: RuntimeVersion; beforeEach((): void => { - injectDefinitions(); version = createType('RuntimeVersion', rpc.result); }); diff --git a/packages/types/src/srml/rpc/SignedBlock.spec.ts b/packages/types/src/srml/rpc/SignedBlock.spec.ts index daffc45195..5c47889077 100644 --- a/packages/types/src/srml/rpc/SignedBlock.spec.ts +++ b/packages/types/src/srml/rpc/SignedBlock.spec.ts @@ -2,6 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import extrinsics from '@polkadot/api-metadata/extrinsics/static'; import createType from '../../codec/createType'; @@ -9,11 +11,9 @@ import Method from '../../primitive/Method'; import events from '../../json/SignedBlock.002.json'; import immortalTxs from '../../json/SignedBlock.004.immortal.json'; import mortalTxs from '../../json/SignedBlock.004.mortal.json'; -import { injectDefinitions } from '..'; describe('SignedBlock', (): void => { beforeEach((): void => { - injectDefinitions(); Method.injectMethods(extrinsics); }); diff --git a/packages/types/src/srml/rpc/StorageChangeSet.spec.ts b/packages/types/src/srml/rpc/StorageChangeSet.spec.ts index 758494be70..73f9cf54e0 100644 --- a/packages/types/src/srml/rpc/StorageChangeSet.spec.ts +++ b/packages/types/src/srml/rpc/StorageChangeSet.spec.ts @@ -2,16 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import { createType } from '@polkadot/types'; import json from '../../json/StorageChangeSet.001.json'; -import { injectDefinitions } from '../'; describe('StorageChangeSet', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - describe('construction', (): void => { const set = createType('StorageChangeSet', { block: '0x1234', diff --git a/packages/types/src/srml/runtime/KeyValue.spec.ts b/packages/types/src/srml/runtime/KeyValue.spec.ts index 2b924ae2ce..836b026cf6 100644 --- a/packages/types/src/srml/runtime/KeyValue.spec.ts +++ b/packages/types/src/srml/runtime/KeyValue.spec.ts @@ -2,16 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import { KeyValue } from './types'; import createType from '../../codec/createType'; -import { injectDefinitions } from '..'; describe('KeyValue', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - it('decodes KeyValue from u8a', (): void => { expect( createType('KeyValue', Uint8Array.from([ diff --git a/packages/types/src/srml/system/EventRecord.spec.ts b/packages/types/src/srml/system/EventRecord.spec.ts index 60d1ef64e2..09fac7c351 100644 --- a/packages/types/src/srml/system/EventRecord.spec.ts +++ b/packages/types/src/srml/system/EventRecord.spec.ts @@ -2,23 +2,20 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../../injector'; + import { EventRecord } from './types'; import createType from '../../codec/createType'; import Vec from '../../codec/Vec'; import json1 from '../../json/EventRecord.001.json'; import json3 from '../../json/EventRecord.003.json'; -import { injectDefinitions } from '..'; +import Event from '../../primitive/Event'; import Metadata from '../../Metadata'; import metadataV0 from '../../Metadata/v0/static'; import metadata from '../../Metadata/static'; -import Event from '../../primitive/Event'; describe('EventRecord', (): void => { - beforeEach((): void => { - injectDefinitions(); - }); - describe('EventRecord_0_76', (): void => { beforeEach((): void => { Event.injectMetadata( @@ -36,8 +33,6 @@ describe('EventRecord', (): void => { describe('EventRecord (current)', (): void => { beforeEach((): void => { - injectDefinitions(); - Event.injectMetadata( new Metadata(metadata) );