Bump common (#5043)

* Bump common

* Adjust deprecated util signatures

* Adjust

* Adjust http mock typings
This commit is contained in:
Jaco
2022-07-08 09:31:49 +03:00
committed by GitHub
parent 3c5091f2d0
commit fd5b48058e
23 changed files with 249 additions and 196 deletions
+6 -6
View File
@@ -24,14 +24,14 @@
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/keyring": "^9.7.2",
"@polkadot/keyring": "^10.0.1",
"@polkadot/types": "8.11.4-12-x",
"@polkadot/types-support": "8.11.4-12-x",
"@polkadot/util": "^9.7.2",
"@polkadot/util-crypto": "^9.7.2",
"@polkadot/x-fetch": "^9.7.2",
"@polkadot/x-global": "^9.7.2",
"@polkadot/x-ws": "^9.7.2",
"@polkadot/util": "^10.0.1",
"@polkadot/util-crypto": "^10.0.1",
"@polkadot/x-fetch": "^10.0.1",
"@polkadot/x-global": "^10.0.1",
"@polkadot/x-ws": "^10.0.1",
"@substrate/connect": "0.7.7",
"eventemitter3": "^4.0.7",
"mock-socket": "^9.1.5",
+3 -6
View File
@@ -21,7 +21,6 @@ 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: {
@@ -32,8 +31,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({
expect(mock.body.test_body).toEqual({
id: 1,
jsonrpc: '2.0',
method: 'test_body',
@@ -42,8 +40,7 @@ describe('send', (): void => {
});
});
it('throws error when !response.ok', (): Promise<any> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
it('throws error when !response.ok', async (): Promise<any> => {
mock = mockHttp([{
code: 500,
method: 'test_error'
@@ -52,7 +49,7 @@ describe('send', (): void => {
return http
.send('test_error', [])
.catch((error): void => {
expect((error as Error).message).toMatch(/\[500\]: Internal Server/);
expect((error as Error).message).toMatch(/\[500\]/);
});
});
});
+3 -3
View File
@@ -227,8 +227,8 @@ export class MockProvider implements ProviderInterface {
number: blockNumber,
parentHash: blockNumber.isZero()
? new Uint8Array(32)
: bnToU8a(this.prevNumber, 256, false),
stateRoot: bnToU8a(blockNumber, 256, false)
: bnToU8a(this.prevNumber, { bitLength: 256, isLe: false }),
stateRoot: bnToU8a(blockNumber, { bitLength: 256, isLe: false })
});
this.prevNumber = blockNumber;
@@ -237,7 +237,7 @@ export class MockProvider implements ProviderInterface {
}
private setStateBn (key: Uint8Array, value: BN | number): void {
this.db[u8aToHex(key)] = bnToU8a(value, 64, true);
this.db[u8aToHex(key)] = bnToU8a(value, { bitLength: 64, isLe: true });
}
private updateSubs (method: string, value: Codec): void {
+20 -8
View File
@@ -1,23 +1,35 @@
// Copyright 2017-2022 @polkadot/rpc-provider authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable */
import type { Mock } from './types';
import nock from 'nock';
interface Request {
code?: number;
method: string;
reply?: Record<string, unknown>;
}
interface HttpMock extends Mock {
post: (uri: string) => {
reply: (code: number, handler: (uri: string, body: { id: string }) => unknown) => HttpMock
}
}
export const TEST_HTTP_URL = 'http://localhost:9944';
export function mockHttp (requests: any[]): any {
export function mockHttp (requests: Request[]): Mock {
nock.cleanAll();
return requests.reduce((scope, request: any): nock.Scope => {
return scope
return requests.reduce((scope: HttpMock, request: Request) =>
scope
.post('/')
.reply(request.code || 200, (uri: string, body: { id: string }): any => {
.reply(request.code || 200, (uri: string, body: { id: string }) => {
scope.body = scope.body || {};
scope.body[request.method] = body;
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {});
});
}, nock(TEST_HTTP_URL));
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {}) as unknown;
}),
nock(TEST_HTTP_URL) as unknown as HttpMock);
}
+1 -1
View File
@@ -11,7 +11,7 @@ export interface Global extends NodeJS.Global {
}
export interface Mock {
body: Record<string, any>;
body: Record<string, Record<string, unknown>>;
requests: number;
server: Server;
done: () => Record<string, unknown>;