2020-02-28 17:45:57 +08:00
|
|
|
// @flow
|
|
|
|
|
2020-09-07 23:12:22 +08:00
|
|
|
import {Client as LiveClient} from 'rpc-websockets';
|
2018-10-26 21:37:39 -07:00
|
|
|
|
2018-11-01 14:41:06 -07:00
|
|
|
// Define TEST_LIVE in the environment to test against the real full node
|
2018-10-26 21:37:39 -07:00
|
|
|
// identified by `url` instead of using the mock
|
2018-11-01 14:41:06 -07:00
|
|
|
export const mockRpcEnabled = !process.env.TEST_LIVE;
|
2018-10-26 21:37:39 -07:00
|
|
|
|
|
|
|
let mockNotice = true;
|
|
|
|
|
2020-09-07 23:12:22 +08:00
|
|
|
class MockClient {
|
|
|
|
constructor(url: string) {
|
|
|
|
if (mockNotice) {
|
|
|
|
console.log(
|
|
|
|
'Note: rpc-websockets mock is disabled, testing live against',
|
|
|
|
url,
|
|
|
|
);
|
|
|
|
mockNotice = false;
|
2018-10-26 21:37:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-07 23:12:22 +08:00
|
|
|
connect() {}
|
|
|
|
close() {}
|
|
|
|
on() {}
|
|
|
|
call(): Promise<Object> {
|
2018-10-26 21:37:39 -07:00
|
|
|
throw new Error('call unsupported');
|
|
|
|
}
|
|
|
|
}
|
2020-09-07 23:12:22 +08:00
|
|
|
|
|
|
|
const Client = mockRpcEnabled ? MockClient : LiveClient;
|
|
|
|
export {Client};
|