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
@@ -17,12 +17,12 @@ describe('encodeObject', (): void => {
it('encodes a valid JsonRPC object', (): void => {
expect(
coder.encodeObject('method', 'params')
coder.encodeObject('method', ['a', 'b'])
).toEqual({
id: 1,
jsonrpc: '2.0',
method: 'method',
params: 'params'
params: ['a', 'b']
});
expect(coder.getId()).toEqual(1);
});
+2 -2
View File
@@ -24,7 +24,7 @@ function formatErrorData (data?: string | number): string {
export default class RpcCoder {
#id = 0;
public decodeResponse (response: JsonRpcResponse): any {
public decodeResponse (response: JsonRpcResponse): unknown {
assert(response, 'Empty response object received');
assert(response.jsonrpc === '2.0', 'Invalid jsonrpc field in decoded object');
@@ -51,7 +51,7 @@ export default class RpcCoder {
);
}
public encodeObject (method: string, params: any | any[]): JsonRpcRequest {
public encodeObject (method: string, params: unknown[]): JsonRpcRequest {
return {
id: ++this.#id,
jsonrpc: '2.0',
+2 -2
View File
@@ -32,13 +32,13 @@ describe('Http', (): void => {
return http.subscribe('', '', [], (cb): void => {
expect(cb).toEqual(expect.anything());
}).catch((error): void => {
expect(error.message).toMatch(/does not have subscriptions/);
expect((error as Error).message).toMatch(/does not have subscriptions/);
});
});
it('does not (yet) support unsubscribe', (): Promise<boolean | void> => {
return http.unsubscribe('', '', 0).catch((error): void => {
expect(error.message).toMatch(/does not have subscriptions/);
expect((error as Error).message).toMatch(/does not have subscriptions/);
});
});
});
+1
View File
@@ -109,6 +109,7 @@ export default class HttpProvider implements ProviderInterface {
assert(response.ok, `[${response.status}]: ${response.statusText}`);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const result = await response.json();
return this.#coder.decodeResponse(result);
@@ -10,14 +10,17 @@ describe('http/polyfill', (): void => {
let origFetch: any;
beforeEach((): void => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
origFetch = global.fetch;
});
afterEach((): void => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
global.fetch = origFetch;
});
it('polyfills with no exceptions (without fetch)', (): void => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(global as any).fetch = undefined;
require('./polyfill');
@@ -25,6 +28,7 @@ describe('http/polyfill', (): void => {
});
it('polyfills with no exceptions (with fetch)', (): void => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(global as any).fetch = (): boolean => true;
require('./polyfill');
+4 -1
View File
@@ -21,6 +21,7 @@ describe('send', (): void => {
});
it('passes the body through correctly', (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
mock = mockHttp([{
method: 'test_body',
reply: {
@@ -31,6 +32,7 @@ describe('send', (): void => {
return http
.send('test_body', ['param'])
.then((): void => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect((mock.body as any).test_body).toEqual({
id: 1,
jsonrpc: '2.0',
@@ -41,6 +43,7 @@ describe('send', (): void => {
});
it('throws error when !response.ok', (): Promise<any> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
mock = mockHttp([{
code: 500,
method: 'test_error'
@@ -49,7 +52,7 @@ describe('send', (): void => {
return http
.send('test_error', [])
.catch((error): void => {
expect(error.message).toMatch(/\[500\]: Internal Server/);
expect((error as Error).message).toMatch(/\[500\]: Internal Server/);
});
});
});
+11 -8
View File
@@ -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.
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable camelcase */
import { Header } from '@polkadot/types/interfaces';
import { Codec, Registry } from '@polkadot/types/types';
@@ -22,14 +22,15 @@ import { randomAsU8a } from '@polkadot/util-crypto';
const INTERVAL = 1000;
const SUBSCRIPTIONS: string[] = Array.prototype.concat.apply(
[], Object.values(jsonrpc).map((section): string[] =>
[],
Object.values(jsonrpc).map((section): string[] =>
Object
.values(section)
.filter(({ isSubscription }) => isSubscription)
.map(({ jsonrpc }) => jsonrpc)
.concat('chain_subscribeNewHead')
)
);
) as string[];
const keyring = testKeyring({ type: 'ed25519' });
const l = logger('api-mock');
@@ -50,12 +51,14 @@ export default class Mock implements ProviderInterface {
private prevNumber = new BN(-1);
private requests: Record<string, (...params: any[]) => any> = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
private requests: Record<string, (...params: any[]) => unknown> = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unsafe-member-access
chain_getBlock: (hash: string): any => this.registry.createType('SignedBlock', rpcSignedBlock.result).toJSON(),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
chain_getBlockHash: (blockNumber: number): string => '0x1234',
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
chain_getFinalizedHead: () => this.registry.createType('Header', rpcHeader.result).hash,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
chain_getHeader: () => this.registry.createType('Header', rpcHeader.result).toJSON(),
state_getKeys: (): string[] => [],
state_getKeysPaged: (): string[] => [],
@@ -112,7 +115,7 @@ export default class Mock implements ProviderInterface {
}
// eslint-disable-next-line @typescript-eslint/require-await
public async send (method: string, params: any[]): Promise<any> {
public async send (method: string, params: any[]): Promise<unknown> {
if (!this.requests[method]) {
throw new Error(`provider.send: Invalid method '${method}'`);
}
@@ -121,11 +124,11 @@ export default class Mock implements ProviderInterface {
}
// eslint-disable-next-line @typescript-eslint/require-await
public async subscribe (type: string, method: string, ...params: any[]): Promise<number> {
public async subscribe (type: string, method: string, ...params: unknown[]): Promise<number> {
l.debug((): any => ['subscribe', method, params]);
if (this.subscriptions[method]) {
const callback: MockStateSubscriptionCallback = params.pop();
const callback = params.pop() as MockStateSubscriptionCallback;
const id = ++this.subscriptionId;
this.subscriptions[method].callbacks[id] = callback;
+1 -1
View File
@@ -18,7 +18,7 @@ describe('send', (): void => {
return mock
.send('something_invalid', [])
.catch((error): void => {
expect(error.message).toMatch(/Invalid method/);
expect((error as Error).message).toMatch(/Invalid method/);
});
});
@@ -18,7 +18,7 @@ describe('subscribe', (): void => {
return mock
.subscribe('test', 'test_notFound')
.catch((error): void => {
expect(error.message).toMatch(/Invalid method 'test_notFound'/);
expect((error as Error).message).toMatch(/Invalid method 'test_notFound'/);
});
});
@@ -41,7 +41,7 @@ describe('subscribe', (): void => {
});
it('calls back with new headers', (done): Promise<number> => {
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: any): void => {
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: { number: number }): void => {
if (header.number === 4) {
done();
}
@@ -51,7 +51,7 @@ describe('subscribe', (): void => {
it('handles errors withing callbacks gracefully', (done): Promise<number> => {
let hasThrown = false;
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: any): void => {
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: { number: number }): void => {
if (!hasThrown) {
hasThrown = true;
+2 -1
View File
@@ -5,6 +5,7 @@
import { Server } from 'mock-socket';
import { Constructor } from '@polkadot/types/types';
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export interface Global extends NodeJS.Global {
WebSocket: Constructor<WebSocket>;
fetch: any;
@@ -14,7 +15,7 @@ export interface Mock {
body: Record<string, any>;
requests: number;
server: Server;
done: () => {};
done: () => Record<string, unknown>;
}
export type MockStateSubscriptionCallback = (error: Error | null, value: any) => void;
@@ -25,7 +25,7 @@ describe('unsubscribe', (): void => {
return mock
.unsubscribe('chain_newHead', 'chain_subscribeNewHead', 5)
.catch((error): boolean => {
expect(error.message).toMatch(/Unable to find/);
expect((error as Error).message).toMatch(/Unable to find/);
return false;
});
@@ -41,7 +41,7 @@ describe('unsubscribe', (): void => {
mock.unsubscribe('chain_newHead', 'chain_subscribeNewHead', id)
)
.catch((error): boolean => {
expect(error.message).toMatch(/Unable to find/);
expect((error as Error).message).toMatch(/Unable to find/);
return false;
});
+3 -3
View File
@@ -9,7 +9,7 @@ export interface JsonRpcObject {
export interface JsonRpcRequest extends JsonRpcObject {
method: string;
params: any[];
params: unknown[];
}
export interface JsonRpcResponseBaseError {
@@ -20,14 +20,14 @@ export interface JsonRpcResponseBaseError {
interface JsonRpcResponseSingle {
error?: JsonRpcResponseBaseError;
result?: any;
result?: unknown;
}
interface JsonRpcResponseSubscription {
method?: string;
params: {
error?: JsonRpcResponseBaseError;
result: any;
result: unknown;
subscription: number;
};
}
+12 -9
View File
@@ -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.
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable camelcase */
import { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitted, ProviderInterfaceEmitCb } from '../types';
@@ -108,6 +108,7 @@ export default class WsProvider implements WSProviderInterface {
this.#websocket = null;
if (autoConnectMs > 0) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.connect();
}
}
@@ -247,9 +248,9 @@ export default class WsProvider implements WSProviderInterface {
* ```
*/
public async subscribe (type: string, method: string, params: any[], callback: ProviderInterfaceCallback): Promise<number> {
const id = await this.send(method, params, { callback, type });
const id = await this.send(method, params, { callback, type }) as Promise<number>;
return id as number;
return id;
}
/**
@@ -270,9 +271,9 @@ export default class WsProvider implements WSProviderInterface {
delete this.#subscriptions[subscription];
const result = await this.send(method, [id]);
const result = await this.send(method, [id]) as Promise<boolean>;
return result as boolean;
return result;
}
#emit = (type: ProviderInterfaceEmitted, ...args: any[]): void => {
@@ -289,6 +290,7 @@ export default class WsProvider implements WSProviderInterface {
if (this.#autoConnectMs > 0) {
setTimeout((): void => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.connect();
}, this.#autoConnectMs);
}
@@ -300,9 +302,10 @@ export default class WsProvider implements WSProviderInterface {
}
#onSocketMessage = (message: MessageEvent): void => {
l.debug((): any => ['received', message.data]);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
l.debug(() => ['received', message.data]);
const response: JsonRpcResponse = JSON.parse(message.data as string);
const response = JSON.parse(message.data as string) as JsonRpcResponse;
return isUndefined(response.method)
? this.#onSocketMessageResult(response)
@@ -320,7 +323,7 @@ export default class WsProvider implements WSProviderInterface {
try {
const { method, params, subscription } = handler;
const result = this.#coder.decodeResponse(response);
const result = this.#coder.decodeResponse(response) as string;
// first send the result - in case of subs, we may have an update
// immediately if we have some queued results already
@@ -348,7 +351,7 @@ export default class WsProvider implements WSProviderInterface {
}
#onSocketMessageSubscribe = (response: JsonRpcResponse): void => {
const method = ALIASSES[response.method as string] || response.method;
const method = ALIASSES[response.method as string] || response.method || 'invalid';
const subId = `${method}::${response.params.subscription}`;
const handler = this.#subscriptions[subId];
@@ -21,6 +21,7 @@ describe('getWebScoket', (): void => {
});
it('polyfills with no exceptions (with WebSocket)', async (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(global as any).WebSocket = undefined;
const WS = await getWSClass();
@@ -29,6 +30,7 @@ describe('getWebScoket', (): void => {
});
it('polyfills with no exceptions (without WebSocket)', async (): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(global as any).WebSocket = (): boolean => true;
const WS = await getWSClass();
@@ -33,6 +33,7 @@ describe('onOpen', (): void => {
}], 0);
const sendPromise = ws.send('test_queue', []);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ws.connect();
return sendPromise.then((result): void => {
+3 -2
View File
@@ -50,7 +50,7 @@ describe('send', (): void => {
return createWs()
.send('test_encoding', [{ error: 'send error' }])
.catch((error): void => {
expect(error.message).toEqual('send error');
expect((error as Error).message).toEqual('send error');
});
});
@@ -67,6 +67,7 @@ describe('send', (): void => {
.send('test_body', ['param'])
.then((): void => {
expect(
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(mock.body as any).test_body
).toEqual('{"id":1,"jsonrpc":"2.0","method":"test_body","params":["param"]}');
});
@@ -84,7 +85,7 @@ describe('send', (): void => {
return createWs()
.send('test_error', [])
.catch((error): void => {
expect(error.message).toMatch(/666: error/);
expect((error as Error).message).toMatch(/666: error/);
});
});