Bump deps w/ eslint (#2302)

* Bump deps w/ eslint

* Additional cleanups

* Additional

* @polkadot/types done

* Additional

* @polkadot/typegen done

* Additional

* @polkadot/rpc-core done

* Additional

* Additional

* Additional

* docs

* @polkadot/api-derive done

* @polkadot/api done

* @polkadot/api-contracts done

* Update tests
This commit is contained in:
Jaco Greeff
2020-05-24 09:24:45 +02:00
committed by GitHub
parent 97cb408f36
commit 47fc4a2b3c
158 changed files with 701 additions and 497 deletions
@@ -14,6 +14,7 @@ describe('createFunction', (): void => {
it('should create timestamp.now correctly', (): void => {
expect(
createFunction(registry, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: { type: {} } as any,
method: 'Now',
prefix: 'Timestamp',
@@ -29,6 +30,7 @@ describe('createFunction', (): void => {
createFunction(
registry,
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: { type: {} } as any,
method: 'authorityCount',
prefix: 'Substrate',
@@ -50,6 +52,7 @@ describe('createFunction', (): void => {
createFunction(
registry,
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: { type: {} } as any,
method: 'authorityCount',
prefix: 'Substrate',
@@ -74,6 +77,7 @@ describe('createFunction', (): void => {
beforeAll((): void => {
storageFn = createFunction(registry, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: {
name: 'metaName',
type: {
@@ -119,6 +123,7 @@ describe('createFunction', (): void => {
it('allows creates double map function with a Null type key', (): void => {
const storageFn = createFunction(registry, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: {
type: {
asDoubleMap: {
@@ -144,6 +149,7 @@ describe('createFunction', (): void => {
it('allows creating of known DoubleMap keys (with Bytes)', (): void => {
const storageFn = createFunction(registry, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: {
type: {
asDoubleMap: {
@@ -73,10 +73,7 @@ function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, stringKey
const { meta: { name, type } } = itemFn;
// since we are passing an almost-unknown through, trust, but verify
assert(
Array.isArray(args) && !isUndefined(args[0]) && !isNull(args[0]) && !isUndefined(args[1]) && !isNull(args[1]),
`${name} is a DoubleMap and requires two arguments`
);
assert(Array.isArray(args) && !isUndefined(args[0]) && !isNull(args[0]) && !isUndefined(args[1]) && !isNull(args[1]), `${(name || 'unknown').toString()} is a DoubleMap and requires two arguments`);
// if this fails, we have bigger issues
assert(!isUndefined(hasher2), '2 hashing functions should be defined for DoubleMaps');
@@ -110,7 +107,7 @@ function createKey (registry: Registry, itemFn: CreateItemFn, stringKey: string,
if (type.isMap) {
const map = type.asMap;
assert(!isUndefined(arg) && !isNull(arg), `${name} is a Map and requires one argument`);
assert(!isUndefined(arg) && !isNull(arg), `${name.toString()} is a Map and requires one argument`);
param = createTypeUnsafe(registry, map.key.toString(), [arg]).toU8a();
}
@@ -134,7 +131,7 @@ function expandWithMeta ({ meta, method, prefix, section }: CreateItemFn, storag
// explicitly add the actual method in the toJSON, this gets used to determine caching and without it
// instances (e.g. collective) will not work since it is only matched on param meta
storageFn.toJSON = (): any => ({
...(meta.toJSON() as any),
...(meta.toJSON() as Record<string, unknown>),
storage: { method, prefix, section }
});
@@ -14,11 +14,11 @@ export type HasherFunction = (data: HasherInput) => Uint8Array;
const DEFAULT_FN = (data: HasherInput): Uint8Array => xxhashAsU8a(data, 128);
const HASHERS: Record<keyof typeof AllHashers, HasherFunction> = {
Blake2_128: (data: HasherInput): Uint8Array => // eslint-disable-line @typescript-eslint/camelcase
Blake2_128: (data: HasherInput): Uint8Array => // eslint-disable-line camelcase
blake2AsU8a(data, 128),
Blake2_128Concat: (data: HasherInput): Uint8Array => // eslint-disable-line @typescript-eslint/camelcase
Blake2_128Concat: (data: HasherInput): Uint8Array => // eslint-disable-line camelcase
u8aConcat(blake2AsU8a(data, 128), u8aToU8a(data)),
Blake2_256: (data: HasherInput): Uint8Array => // eslint-disable-line @typescript-eslint/camelcase
Blake2_256: (data: HasherInput): Uint8Array => // eslint-disable-line camelcase
blake2AsU8a(data, 256),
Identity: (data: HasherInput): Uint8Array =>
u8aToU8a(data),
@@ -14,7 +14,7 @@ export default function getStorage (registry: Registry, metaVersion: number): St
substrate: Object
.entries(substrate)
.reduce((storage: Record<string, StorageEntry>, [key, fn]): Record<string, StorageEntry> => {
(storage as any)[key] = fn(registry, metaVersion);
(storage as Record<string, unknown>)[key] = fn(registry, metaVersion);
return storage;
}, {})
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Registry } from '@polkadot/types/types';
import { AnyNumber, Registry } from '@polkadot/types/types';
import { assert } from '@polkadot/util';
@@ -11,7 +11,7 @@ import U32 from '@polkadot/types/primitive/U32';
export const MAGIC_NUMBER = 0x6174656d; // `meta`, reversed for Little Endian encoding
export default class MagicNumber extends U32 {
constructor (registry: Registry, value?: any) {
constructor (registry: Registry, value?: AnyNumber) {
super(registry, value);
if (!this.isEmpty) {
@@ -33,13 +33,13 @@ type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6' | 'a
* The versioned runtime metadata as a decoded structure
*/
export default class MetadataVersioned extends Struct {
readonly #converted: Map<number, MetaMapped> = new Map();
readonly #converted = new Map<number, MetaMapped>();
constructor (registry: Registry, value?: any) {
constructor (registry: Registry, value?: unknown) {
super(registry, {
magicNumber: MagicNumber,
metadata: 'MetadataAll'
}, value);
}, value as Map<unknown, unknown>);
registry.setMetadata(this);
}
@@ -2,9 +2,11 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
type Types = string | Types[];
/** @internal */
export default function flattenUniq (list: any[]): any[] {
const flat = list.reduce((result, entry): any[] => {
export default function flattenUniq (list: Types[]): string[] {
const flat = list.reduce((result: string[], entry): string[] => {
return result.concat(
Array.isArray(entry)
? flattenUniq(entry)
@@ -13,6 +15,6 @@ export default function flattenUniq (list: any[]): any[] {
}, []);
return [...new Set(flat)]
.filter((value: any): any => value)
.filter((value: string) => value)
.sort();
}
@@ -11,7 +11,7 @@ import getUniqTypes from './getUniqTypes';
import Metadata from '../Metadata';
/** @internal */
export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry, version: number, rpcData: string, staticSubstrate: object): void {
export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry, version: number, rpcData: string, staticSubstrate: Record<string, unknown>): void {
it('decodes latest substrate properly', (): void => {
const metadata = new Metadata(registry, rpcData);
@@ -49,14 +49,14 @@ export function defaultValues (registry: Registry, rpcData: string, withThrow =
metadata.asLatest.modules.filter(({ storage }): boolean => storage.isSome).forEach((mod): void => {
mod.storage.unwrap().items.forEach(({ fallback, name, type }): void => {
const inner = unwrapStorageType(type);
const location = `${mod.name}.${name}: ${inner}`;
const location = `${mod.name.toString()}.${name.toString()}: ${inner}`;
it(`creates default types for ${location}`, (): void => {
expect((): void => {
try {
registry.createType(inner, fallback);
} catch (error) {
const message = `${location}:: ${error.message}`;
const message = `${location}:: ${(error as Error).message}`;
if (withThrow) {
throw new Error(message);
@@ -26,7 +26,7 @@ function mapCalls (registry: Registry, _calls: Option<Vec<FunctionMetadataLatest
})
)
: null
);
) as Option<Vec<FunctionMetadataLatest>>;
}
/** @internal */
@@ -8,9 +8,11 @@ import { getTypeDef } from '@polkadot/types/create';
import flattenUniq from './flattenUniq';
type Extracted = string | Extracted[];
/** @internal */
function extractTypes (types: string[]): any[] {
return types.map((type): any => {
function extractTypes (types: string[]): Extracted[] {
return types.map((type): Extracted => {
const decoded = getTypeDef(type);
switch (decoded.info) {
@@ -38,12 +40,10 @@ function extractTypes (types: string[]): any[] {
/** @internal */
export default function validateTypes (registry: Registry, types: string[], throwError: boolean): void {
const missing = flattenUniq(extractTypes(types)).filter((type): boolean =>
!registry.hasType(type)
);
const missing = flattenUniq(extractTypes(types)).filter((type) => !registry.hasType(type));
if (missing.length !== 0) {
const message = `Unknown types found, no types for ${missing}`;
const message = `Unknown types found, no types for ${missing.join(', ')}`;
if (throwError) {
throw new Error(message);