Use tsconfig references (#4328)
* Use tsconfig references * Move types-known (temp until lower-level split) * Sources * Adjust * tesconfig.eslint.json * Bumps * AdjustAdjust * Linting passing... a start... * Adjust * Merge derive * Merge * api-contract-support * It builds? * compare locations
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TEST_HTTP_URL } from '../../test/mockHttp';
|
||||
import { TEST_HTTP_URL } from '@polkadot/rpc-provider/mock/mockHttp';
|
||||
|
||||
import { HttpProvider } from './';
|
||||
|
||||
describe('Http', (): void => {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Mock } from './../mock/types';
|
||||
import type { Mock } from '../mock/types';
|
||||
|
||||
import { mockHttp, TEST_HTTP_URL } from '@polkadot/rpc-provider/mock/mockHttp';
|
||||
|
||||
import { mockHttp, TEST_HTTP_URL } from '../../test/mockHttp';
|
||||
import { HttpProvider } from './';
|
||||
|
||||
describe('send', (): void => {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
import nock from 'nock';
|
||||
|
||||
export const TEST_HTTP_URL = 'http://localhost:9944';
|
||||
|
||||
export function mockHttp (requests: any[]): any {
|
||||
nock.cleanAll();
|
||||
|
||||
return requests.reduce((scope, request: any): nock.Scope => {
|
||||
return scope
|
||||
.post('/')
|
||||
.reply(request.code || 200, (uri: string, body: { id: string }): any => {
|
||||
scope.body = scope.body || {};
|
||||
scope.body[request.method] = body;
|
||||
|
||||
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {});
|
||||
});
|
||||
}, nock(TEST_HTTP_URL));
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { Server, WebSocket } from 'mock-socket';
|
||||
|
||||
import { stringify } from '@polkadot/util';
|
||||
|
||||
interface Scope {
|
||||
body: { [index: string]: Record<string, unknown> };
|
||||
requests: number;
|
||||
server: Server;
|
||||
done: any;
|
||||
}
|
||||
|
||||
interface ErrorDef {
|
||||
id: number;
|
||||
error: {
|
||||
code: number;
|
||||
message: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface ReplyDef {
|
||||
id: number;
|
||||
reply: {
|
||||
result: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
interface RpcBase {
|
||||
id: number;
|
||||
jsonrpc: '2.0';
|
||||
}
|
||||
|
||||
type RpcError = RpcBase & ErrorDef;
|
||||
type RpcReply = RpcBase & { result: unknown };
|
||||
|
||||
export type Request = { method: string } & (ErrorDef | ReplyDef);
|
||||
|
||||
global.WebSocket = WebSocket as typeof global.WebSocket;
|
||||
|
||||
export const TEST_WS_URL = 'ws://localhost:9955';
|
||||
|
||||
// should be JSONRPC def return
|
||||
function createError ({ error: { code, message }, id }: ErrorDef): RpcError {
|
||||
return {
|
||||
error: {
|
||||
code,
|
||||
message
|
||||
},
|
||||
id,
|
||||
jsonrpc: '2.0'
|
||||
};
|
||||
}
|
||||
|
||||
// should be JSONRPC def return
|
||||
function createReply ({ id, reply: { result } }: ReplyDef): RpcReply {
|
||||
return {
|
||||
id,
|
||||
jsonrpc: '2.0',
|
||||
result
|
||||
};
|
||||
}
|
||||
|
||||
// scope definition returned
|
||||
export function mockWs (requests: Request[], wsUrl: string = TEST_WS_URL): Scope {
|
||||
const server = new Server(wsUrl);
|
||||
|
||||
let requestCount = 0;
|
||||
const scope: Scope = {
|
||||
body: {},
|
||||
done: (): void => {
|
||||
server.stop((): void => {
|
||||
// ignore
|
||||
});
|
||||
},
|
||||
requests: 0,
|
||||
server
|
||||
};
|
||||
|
||||
server.on('connection', (socket): void => {
|
||||
socket.on('message', (body): void => {
|
||||
const request = requests[requestCount];
|
||||
const response = (request as ErrorDef).error
|
||||
? createError(request as ErrorDef)
|
||||
: createReply(request as ReplyDef);
|
||||
|
||||
scope.body[request.method] = body as unknown as Record<string, unknown>;
|
||||
requestCount++;
|
||||
|
||||
socket.send(stringify(response));
|
||||
});
|
||||
});
|
||||
|
||||
return scope;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Mock } from './../mock/types';
|
||||
import type { Mock } from '../mock/types';
|
||||
|
||||
import { jest } from '@jest/globals';
|
||||
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { mockWs } from '../mock/mockWs';
|
||||
import { WsProvider } from './';
|
||||
|
||||
const TEST_WS_URL = 'ws://localhost-connect.spec.ts:9988';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Request } from '../../test/mockWs';
|
||||
import type { Request } from '../mock/mockWs';
|
||||
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Mock } from './../mock/types';
|
||||
import { mockWs } from '../mock/mockWs';
|
||||
import { Mock } from '../mock/types';
|
||||
import { WsProvider } from './';
|
||||
|
||||
const TEST_WS_URL = 'ws://localhost-index.spec.ts:9977';
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constructor } from '@polkadot/types/types';
|
||||
import type { Request } from '../../test/mockWs';
|
||||
import type { Request } from '../mock/mockWs';
|
||||
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Global, Mock } from './../mock/types';
|
||||
import { mockWs } from '../mock/mockWs';
|
||||
import { Global, Mock } from '../mock/types';
|
||||
import { WsProvider } from './';
|
||||
|
||||
declare const global: Global;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constructor } from '@polkadot/types/types';
|
||||
import type { Request } from '../../test/mockWs';
|
||||
import type { Request } from '../mock/mockWs';
|
||||
import type { Global, Mock } from './../mock/types';
|
||||
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Global, Mock } from './../mock/types';
|
||||
import { WsProvider } from './';
|
||||
import { mockWs } from '../mock/mockWs';
|
||||
import { WsProvider } from '.';
|
||||
|
||||
declare const global: Global;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constructor } from '@polkadot/types/types';
|
||||
import type { Request } from '../../test/mockWs';
|
||||
import type { Request } from '../mock/mockWs';
|
||||
import type { Global, Mock } from './../mock/types';
|
||||
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Global, Mock } from './../mock/types';
|
||||
import { mockWs } from '../mock/mockWs';
|
||||
import { WsProvider } from './';
|
||||
|
||||
declare const global: Global;
|
||||
|
||||
Reference in New Issue
Block a user