From 5e4e27fed5b9b7c889e6e6e1805377b9eff31a3a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 4 Apr 2018 11:35:58 +0900 Subject: Update dev-utils and subproviders tests to use ganache in-process provider --- packages/subproviders/test/unit/ledger_subprovider_test.ts | 7 ++----- .../subproviders/test/unit/redundant_rpc_subprovider_test.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'packages/subproviders/test/unit') diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts index 3cb487f02..a3800434a 100644 --- a/packages/subproviders/test/unit/ledger_subprovider_test.ts +++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts @@ -4,12 +4,12 @@ import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; import Web3 = require('web3'); import Web3ProviderEngine = require('web3-provider-engine'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { LedgerSubprovider } from '../../src'; import { DoneCallback, LedgerCommunicationClient, LedgerSubproviderErrors } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { reportCallbackErrors } from '../utils/report_callback_errors'; +import { subprovider as ganacheSubprovider } from '../utils/subprovider'; chaiSetup.configure(); const expect = chai.expect; @@ -99,10 +99,7 @@ describe('LedgerSubprovider', () => { before(() => { provider = new Web3ProviderEngine(); provider.addProvider(ledgerSubprovider); - const httpProvider = new RpcSubprovider({ - rpcUrl: 'http://localhost:8545', - }); - provider.addProvider(httpProvider); + provider.addProvider(ganacheSubprovider); provider.start(); }); describe('success cases', () => { diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index a347ab765..ab540e202 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -3,11 +3,13 @@ import * as chai from 'chai'; import * as _ from 'lodash'; import Web3 = require('web3'); import Web3ProviderEngine = require('web3-provider-engine'); +import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { RedundantRPCSubprovider } from '../../src'; import { DoneCallback } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { reportCallbackErrors } from '../utils/report_callback_errors'; +import { subprovider as ganacheSubprovider } from '../utils/subprovider'; const expect = chai.expect; chaiSetup.configure(); @@ -18,6 +20,8 @@ describe('RedundantRpcSubprovider', () => { provider = new Web3ProviderEngine(); const endpoints = ['http://localhost:8545']; const redundantSubprovider = new RedundantRPCSubprovider(endpoints); + // Hack: Hot-swap rpc with ganacheSubprovider + (redundantSubprovider as any)._rpcs = [ganacheSubprovider]; provider.addProvider(redundantSubprovider); provider.start(); @@ -38,6 +42,11 @@ describe('RedundantRpcSubprovider', () => { provider = new Web3ProviderEngine(); const endpoints = ['http://does-not-exist:3000', 'http://localhost:8545']; const redundantSubprovider = new RedundantRPCSubprovider(endpoints); + // Hack: Hot-swap rpcs with [nonExistentSubprovider, ganacheSubprovider] + const nonExistentSubprovider = new RpcSubprovider({ + rpcUrl: 'http://does-not-exist:3000', + }); + (redundantSubprovider as any)._rpcs = [nonExistentSubprovider, ganacheSubprovider]; provider.addProvider(redundantSubprovider); provider.start(); -- cgit From 75a51af00603236e0b80fe04336494944a32739c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 6 Apr 2018 15:04:17 +0900 Subject: Use provider over web3 in deployer, dev-utils and subprovider tests, rename subprovider to ganacheSubprovider in test util --- packages/subproviders/test/unit/ledger_subprovider_test.ts | 2 +- packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/subproviders/test/unit') diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts index a3800434a..d30c68f65 100644 --- a/packages/subproviders/test/unit/ledger_subprovider_test.ts +++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts @@ -8,8 +8,8 @@ import Web3ProviderEngine = require('web3-provider-engine'); import { LedgerSubprovider } from '../../src'; import { DoneCallback, LedgerCommunicationClient, LedgerSubproviderErrors } from '../../src/types'; import { chaiSetup } from '../chai_setup'; +import { ganacheSubprovider } from '../utils/ganache_subprovider'; import { reportCallbackErrors } from '../utils/report_callback_errors'; -import { subprovider as ganacheSubprovider } from '../utils/subprovider'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index ab540e202..e7ca6d496 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -8,8 +8,8 @@ import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { RedundantRPCSubprovider } from '../../src'; import { DoneCallback } from '../../src/types'; import { chaiSetup } from '../chai_setup'; +import { ganacheSubprovider } from '../utils/ganache_subprovider'; import { reportCallbackErrors } from '../utils/report_callback_errors'; -import { subprovider as ganacheSubprovider } from '../utils/subprovider'; const expect = chai.expect; chaiSetup.configure(); -- cgit From 22fa5a57a588c3c5c2a72ec5ef539797c2847688 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 6 Apr 2018 15:46:27 +0900 Subject: Refactor RedundantRpcSubprovider into RedundantSubprovider --- .../test/unit/redundant_rpc_subprovider_test.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'packages/subproviders/test/unit') diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index e7ca6d496..e25cb7eb7 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -5,7 +5,8 @@ import Web3 = require('web3'); import Web3ProviderEngine = require('web3-provider-engine'); import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); -import { RedundantRPCSubprovider } from '../../src'; +import { RedundantSubprovider } from '../../src'; +import { Subprovider } from '../../src/subproviders/subprovider'; import { DoneCallback } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { ganacheSubprovider } from '../utils/ganache_subprovider'; @@ -14,14 +15,12 @@ import { reportCallbackErrors } from '../utils/report_callback_errors'; const expect = chai.expect; chaiSetup.configure(); -describe('RedundantRpcSubprovider', () => { +describe('RedundantSubprovider', () => { 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); - // Hack: Hot-swap rpc with ganacheSubprovider - (redundantSubprovider as any)._rpcs = [ganacheSubprovider]; + const subproviders = [ganacheSubprovider]; + const redundantSubprovider = new RedundantSubprovider(subproviders); provider.addProvider(redundantSubprovider); provider.start(); @@ -40,13 +39,11 @@ describe('RedundantRpcSubprovider', () => { }); 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); - // Hack: Hot-swap rpcs with [nonExistentSubprovider, ganacheSubprovider] const nonExistentSubprovider = new RpcSubprovider({ rpcUrl: 'http://does-not-exist:3000', }); - (redundantSubprovider as any)._rpcs = [nonExistentSubprovider, ganacheSubprovider]; + const subproviders = [nonExistentSubprovider as Subprovider, ganacheSubprovider]; + const redundantSubprovider = new RedundantSubprovider(subproviders); provider.addProvider(redundantSubprovider); provider.start(); -- cgit