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
+1
View File
@@ -84,6 +84,7 @@ describe('Cached Observables', (): void => {
it('creates different observables for different methods but same arguments', (): void => {
// params do not match here
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
const observable1 = (rpc.chain as any).subscribeNewHeads([123]);
const observable2 = rpc.state.subscribeStorage([123]);
+1
View File
@@ -28,6 +28,7 @@ describe('Api', (): void => {
}
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(isFunction((rpc as any).testing.foo)).toBe(true);
expect(rpc.sections.includes('testing')).toBe(true);
expect(rpc.mapping.get('testing_foo')).toEqual({
+8 -8
View File
@@ -63,7 +63,7 @@ function logErrorMessage (method: string, { params, type }: DefinitionRpc, error
export default class Rpc implements RpcInterface {
readonly #storageCache = new Map<string, string | null>();
public readonly mapping: Map<string, DefinitionRpcExt> = new Map();
public readonly mapping = new Map<string, DefinitionRpcExt>();
public readonly provider: ProviderInterface;
@@ -134,7 +134,7 @@ export default class Rpc implements RpcInterface {
// decorate the sections with base and user methods
this.sections.forEach((sectionName): void => {
(this as any)[sectionName as Section] = {
(this as Record<string, unknown>)[sectionName as Section] = {
...this._createInterface(sectionName, jsonrpc[sectionName as 'babe'] || {}),
...this._createInterface(sectionName, userRpc[sectionName] || {})
};
@@ -156,7 +156,7 @@ export default class Rpc implements RpcInterface {
// `<S extends keyof RpcInterface, M extends keyof RpcInterface[S]>`
// Not doing so, because it makes this class a little bit less readable,
// and leaving it as-is doesn't harm much
(exposed as any)[method] = isSubscription
(exposed as Record<string, unknown>)[method] = isSubscription
? this._createMethodSubscribe(section, method, def as DefinitionRpcSub)
: this._createMethodSend(section, method, def);
@@ -333,7 +333,7 @@ export default class Rpc implements RpcInterface {
try {
return this._formatStorageData(key, result);
} catch (error) {
console.error(`Unable to decode storage ${key.section}.${key.method}:`, error.message);
console.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:`, (error as Error).message);
throw error;
}
@@ -341,10 +341,10 @@ export default class Rpc implements RpcInterface {
const keys = params[0] as Vec<StorageKey>;
return keys
? this._formatStorageSet(keys, result.changes)
? this._formatStorageSet(keys, (result as { changes: [string, string | null][] }).changes)
: this.registry.createType('StorageChangeSet', result);
} else if (rpc.type === 'Vec<StorageChangeSet>') {
const mapped = result.map(({ block, changes }: { block: string; changes: [string, string | null][] }): [Hash, Codec[]] => [
const mapped = (result as { block: string; changes: [string, string | null][] }[]).map(({ block, changes }): [Hash, Codec[]] => [
this.registry.createType('Hash', block),
this._formatStorageSet(params[0] as Vec<StorageKey>, changes)
]);
@@ -352,7 +352,7 @@ export default class Rpc implements RpcInterface {
// we only query at a specific block, not a range - flatten
return method === 'queryStorageAt'
? mapped[0][1]
: mapped;
: mapped as unknown as Codec[];
}
return createTypeUnsafe(this.registry, rpc.type, [result]);
@@ -404,7 +404,7 @@ export default class Rpc implements RpcInterface {
try {
results.push(this._formatStorageSetEntry(key, changes, withCache));
} catch (error) {
console.error(`Unable to decode storage ${key.section}.${key.method}:`, error.message);
console.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:`, (error as Error).message);
throw error;
}
+6 -1
View File
@@ -31,7 +31,7 @@ describe('methodSend', (): void => {
};
provider = {
send: jest.fn((method, params): Promise<any> => {
send: jest.fn((method, params: any[]): Promise<any> => {
return Promise.resolve(params[0]);
})
};
@@ -41,8 +41,10 @@ describe('methodSend', (): void => {
it('checks for mismatched parameters', (done): void => {
// private method
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
const method = (rpc as any)._createMethodSend('test', 'bleh', methods.bleh);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
method(1).subscribe(
(): void => undefined,
(error: Error): void => {
@@ -53,10 +55,13 @@ describe('methodSend', (): void => {
it('calls the provider with the correct parameters', (done): void => {
// private method
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
const method = (rpc as any)._createMethodSend('test', 'blah', methods.blah);
// Args are length-prefixed, because it's a Bytes
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
method(new Uint8Array([2 << 2, 0x12, 0x34])).subscribe((): void => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(provider.send).toHaveBeenCalledWith('test_blah', ['0x1234']);
done();
});
+5 -2
View File
@@ -18,7 +18,9 @@ describe('replay', (): void => {
it('subscribes via the rpc section', (done): void => {
// we don't honor types or number of params here
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(rpc.chain as any).getBlockHash = jest.fn((): Observable<number> => of(1));
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
(rpc.chain as any).getBlockHash(123, false).subscribe((): void => {
expect(
// eslint-disable-next-line @typescript-eslint/unbound-method
@@ -32,6 +34,7 @@ describe('replay', (): void => {
it('returns the observable value', (done): void => {
rpc.system.chain().subscribe((value: any): void => {
if (value) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
expect(value.toString()).toEqual('mockChain'); // Defined in MockProvider
done();
}
@@ -40,9 +43,9 @@ describe('replay', (): void => {
it('replay(1) works as expected', (done): void => {
const observable = rpc.system.chain();
let a: string | undefined;
let a: any | undefined;
observable.subscribe((value: any): void => { a = value; });
observable.subscribe((value?: unknown): void => { a = value; });
setTimeout((): void => {
// Subscribe again to the same observable, it should fire value immediately
+2 -2
View File
@@ -18,7 +18,7 @@ interface Options {
const l = logger('drr');
const CMP = (a: any, b: any): boolean =>
const CMP = (a: unknown, b: unknown): boolean =>
JSON.stringify({ t: a }) === JSON.stringify({ t: b });
const ERR = (error: Error): Observable<never> => {
@@ -40,7 +40,7 @@ export const drr = ({ skipChange = false, skipTimeout = false }: Options = {}):
catchError(ERR),
skipChange
? tap(NOOP)
: distinctUntilChanged(CMP),
: distinctUntilChanged<T>(CMP),
publishReplay(1),
skipTimeout
? refCount()