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/test') 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 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 --- .../subproviders/test/unit/ledger_subprovider_test.ts | 2 +- .../test/unit/redundant_rpc_subprovider_test.ts | 2 +- .../subproviders/test/utils/ganache_subprovider.ts | 18 ++++++++++++++++++ packages/subproviders/test/utils/subprovider.ts | 18 ------------------ 4 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 packages/subproviders/test/utils/ganache_subprovider.ts delete mode 100644 packages/subproviders/test/utils/subprovider.ts (limited to 'packages/subproviders/test') 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(); diff --git a/packages/subproviders/test/utils/ganache_subprovider.ts b/packages/subproviders/test/utils/ganache_subprovider.ts new file mode 100644 index 000000000..ac4a9325c --- /dev/null +++ b/packages/subproviders/test/utils/ganache_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 ganacheSubprovider = new GanacheSubprovider({ + logger, + verbose: false, + port: configs.port, + networkId: configs.networkId, + mnemonic: configs.mnemonic, +}); diff --git a/packages/subproviders/test/utils/subprovider.ts b/packages/subproviders/test/utils/subprovider.ts deleted file mode 100644 index b1c459746..000000000 --- a/packages/subproviders/test/utils/subprovider.ts +++ /dev/null @@ -1,18 +0,0 @@ -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 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') 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 v1.2.3 From 919b327fc534e3c2dc6330130cee690f0fa39fea Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 9 Apr 2018 17:14:25 +0900 Subject: Move migrations into separate monorepo subpackage and hook it up to 0x.js and contracts --- packages/subproviders/test/integration/ledger_subprovider_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/subproviders/test') diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts index 503618089..9e81dfac5 100644 --- a/packages/subproviders/test/integration/ledger_subprovider_test.ts +++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts @@ -1,7 +1,7 @@ import { JSONRPCResponsePayload } from '@0xproject/types'; import { promisify } from '@0xproject/utils'; import Eth from '@ledgerhq/hw-app-eth'; -// HACK: This depdency is optional and tslint skips optional depdencies +// HACK: This dependency is optional and tslint skips optional dependencies // tslint:disable-next-line:no-implicit-dependencies import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; import * as chai from 'chai'; -- cgit v1.2.3