UNPKG

1.21 kBPlain TextView Raw
1// Copyright 2017-2018 @polkadot/api-provider authors & contributors
2// This software may be modified and distributed under the terms
3// of the ISC license. See the LICENSE file for details.
4
5import { ProviderInterface, ProviderInterface$Emitted, ProviderInterface$EmitCb } from '../types';
6
7import mocks from './mocks';
8import on from './on';
9import send from './send';
10import state from './state';
11import subscribe from './subscribe';
12import unsubscribe from './unsubscribe';
13
14/**
15 * A moock provider mainly used for testing.
16 * @return {ProviderInterface} The mock provider
17 */
18export default function mockProvider (): ProviderInterface {
19 const self = state();
20
21 mocks(self);
22
23 return {
24 isConnected: (): boolean =>
25 true,
26 on: (type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void =>
27 on(self, type, sub),
28 send: (method: string, params: Array<any>): Promise<any> =>
29 send(self, method, params),
30 subscribe: (type: string, method: string, ...params: Array<any>): Promise<number> =>
31 subscribe(self, type, method, params),
32 unsubscribe: (type: string, method: string, id: number): Promise<boolean> =>
33 unsubscribe(self, type, method, id)
34 };
35}