aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-12-06 08:50:02 +0800
committerFabio Berger <me@fabioberger.com>2017-12-06 08:50:02 +0800
commit78274440cbf53c771d0207416a247d27bb025174 (patch)
treeda861d117d980fea8d988ae9958472b048446104 /packages
parente59934ca2110d639671337f1ecd643791ca28c8d (diff)
downloaddexon-sol-tools-78274440cbf53c771d0207416a247d27bb025174.tar
dexon-sol-tools-78274440cbf53c771d0207416a247d27bb025174.tar.gz
dexon-sol-tools-78274440cbf53c771d0207416a247d27bb025174.tar.bz2
dexon-sol-tools-78274440cbf53c771d0207416a247d27bb025174.tar.lz
dexon-sol-tools-78274440cbf53c771d0207416a247d27bb025174.tar.xz
dexon-sol-tools-78274440cbf53c771d0207416a247d27bb025174.tar.zst
dexon-sol-tools-78274440cbf53c771d0207416a247d27bb025174.zip
Add initial tests fort redundantRpcSubprovider
Diffstat (limited to 'packages')
-rw-r--r--packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts
new file mode 100644
index 000000000..edeb1d5a2
--- /dev/null
+++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts
@@ -0,0 +1,62 @@
+import * as chai from 'chai';
+import * as _ from 'lodash';
+import Web3 = require('web3');
+import Web3ProviderEngine = require('web3-provider-engine');
+
+import {RedundantRPCSubprovider} from '../../src';
+import {
+ DoneCallback,
+} from '../../src/types';
+import {chaiSetup} from '../chai_setup';
+import {reportCallbackErrors} from '../utils/report_callback_errors';
+
+const expect = chai.expect;
+
+describe('RedundantRpcSubprovider', () => {
+ let provider: Web3ProviderEngine;
+ it('succeeds when supplied a healthy endpoint', (done: DoneCallback) => {
+ provider = new Web3ProviderEngine();
+ const endpoints = [
+ 'http://localhost:8545',
+ ];
+ const redundantSubprovider = new RedundantRPCSubprovider(endpoints);
+ provider.addProvider(redundantSubprovider);
+ provider.start();
+
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'eth_accounts',
+ params: [],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => {
+ expect(err).to.be.a('null');
+ expect(response.result.length).to.be.equal(10);
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
+ it('succeeds when supplied at least one healthy endpoint', (done: DoneCallback) => {
+ provider = new Web3ProviderEngine();
+ const endpoints = [
+ 'http://does-not-exist:3000',
+ 'http://localhost:8545',
+ ];
+ const redundantSubprovider = new RedundantRPCSubprovider(endpoints);
+ provider.addProvider(redundantSubprovider);
+ provider.start();
+
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'eth_accounts',
+ params: [],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => {
+ expect(err).to.be.a('null');
+ expect(response.result.length).to.be.equal(10);
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
+});