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 --- .../subproviders/test/unit/ledger_subprovider_test.ts | 7 ++----- .../test/unit/redundant_rpc_subprovider_test.ts | 9 +++++++++ packages/subproviders/test/utils/configs.ts | 5 +++++ packages/subproviders/test/utils/subprovider.ts | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 packages/subproviders/test/utils/configs.ts create mode 100644 packages/subproviders/test/utils/subprovider.ts (limited to 'packages/subproviders') 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(); diff --git a/packages/subproviders/test/utils/configs.ts b/packages/subproviders/test/utils/configs.ts new file mode 100644 index 000000000..341037e4f --- /dev/null +++ b/packages/subproviders/test/utils/configs.ts @@ -0,0 +1,5 @@ +export const configs = { + port: 8545, + networkId: 50, + mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic', +}; diff --git a/packages/subproviders/test/utils/subprovider.ts b/packages/subproviders/test/utils/subprovider.ts new file mode 100644 index 000000000..b1c459746 --- /dev/null +++ b/packages/subproviders/test/utils/subprovider.ts @@ -0,0 +1,18 @@ +import * as fs from 'fs'; + +import { GanacheSubprovider } from '../../src/subproviders/ganache'; +import { configs } from '../utils/configs'; + +const logger = { + log: (arg: any) => { + fs.appendFileSync('ganache.log', `${arg}\n`); + }, +}; + +export const subprovider = new GanacheSubprovider({ + logger, + verbose: false, + port: configs.port, + networkId: configs.networkId, + mnemonic: configs.mnemonic, +}); -- cgit v1.2.3