diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-19 23:48:06 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-19 23:48:06 +0800 |
commit | d8898cf9a30cc349868afcf2b78e6369e57aa726 (patch) | |
tree | f96d1aa76c7e5aa9e3311d5cdbd0d31c8ec8d7fb /packages/subproviders | |
parent | 1aaf633df883f62fad890b2d87a2dc89067821c5 (diff) | |
parent | 3de88d5345c7a4549bc69e2ca28f0601f5d42189 (diff) | |
download | dexon-sol-tools-d8898cf9a30cc349868afcf2b78e6369e57aa726.tar dexon-sol-tools-d8898cf9a30cc349868afcf2b78e6369e57aa726.tar.gz dexon-sol-tools-d8898cf9a30cc349868afcf2b78e6369e57aa726.tar.bz2 dexon-sol-tools-d8898cf9a30cc349868afcf2b78e6369e57aa726.tar.lz dexon-sol-tools-d8898cf9a30cc349868afcf2b78e6369e57aa726.tar.xz dexon-sol-tools-d8898cf9a30cc349868afcf2b78e6369e57aa726.tar.zst dexon-sol-tools-d8898cf9a30cc349868afcf2b78e6369e57aa726.zip |
merge v2-prototype
Diffstat (limited to 'packages/subproviders')
25 files changed, 170 insertions, 79 deletions
diff --git a/packages/subproviders/CHANGELOG.json b/packages/subproviders/CHANGELOG.json index 7a3f29fe0..6942aa5db 100644 --- a/packages/subproviders/CHANGELOG.json +++ b/packages/subproviders/CHANGELOG.json @@ -5,8 +5,16 @@ { "note": "Add `EthLightwalletSubprovider`" } - ], - "timestamp": 1531149657 + ] + }, + { + "timestamp": 1531919263, + "version": "0.10.6", + "changes": [ + { + "note": "Dependencies updated" + } + ] }, { "timestamp": 1529397769, diff --git a/packages/subproviders/CHANGELOG.md b/packages/subproviders/CHANGELOG.md index 6fab0a4c4..c433721eb 100644 --- a/packages/subproviders/CHANGELOG.md +++ b/packages/subproviders/CHANGELOG.md @@ -5,6 +5,10 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v0.10.6 - _July 18, 2018_ + + * Dependencies updated + ## v0.10.5 - _July 9, 2018_ * Update web3-provider-engine to v14.0.6 including the leaked global.XMLHttpRequest bug fix diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index bdc846e6b..620a46384 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/subproviders", - "version": "0.10.5", + "version": "0.10.6", "engines": { "node": ">=6.12" }, @@ -42,9 +42,9 @@ "dependencies": { "@0xproject/assert": "^0.3.0", "@0xproject/types": "^1.0.0", - "@0xproject/web3-wrapper": "^0.7.2", - "@0xproject/typescript-typings": "^0.4.2", - "@0xproject/utils": "^0.7.2", + "@0xproject/web3-wrapper": "^0.7.3", + "@0xproject/typescript-typings": "^0.4.3", + "@0xproject/utils": "^0.7.3", "@ledgerhq/hw-app-eth": "^4.3.0", "@ledgerhq/hw-transport-u2f": "^4.3.0", "ethereum-types": "^0.0.2", @@ -55,6 +55,7 @@ "ethereumjs-util": "^5.1.1", "ganache-core": "0xProject/ganache-core", "hdkey": "^0.7.1", + "json-rpc-error": "2.0.0", "lodash": "^4.17.4", "semaphore-async-await": "^1.5.1", "web3-provider-engine": "14.0.6" @@ -62,7 +63,7 @@ "devDependencies": { "@0xproject/monorepo-scripts": "^0.2.2", "@0xproject/tslint-config": "^0.4.21", - "@0xproject/utils": "^0.7.2", + "@0xproject/utils": "^0.7.3", "@types/bip39": "^2.4.0", "@types/bn.js": "^4.11.0", "@types/hdkey": "^0.7.0", @@ -81,7 +82,7 @@ "nyc": "^11.0.1", "shx": "^0.2.2", "sinon": "^4.0.0", - "tslint": "5.8.0", + "tslint": "5.11.0", "typedoc": "0xProject/typedoc", "typescript": "2.7.1", "webpack": "^3.1.0" diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts index 71d643f14..9d4480e59 100644 --- a/packages/subproviders/src/index.ts +++ b/packages/subproviders/src/index.ts @@ -1,5 +1,6 @@ import Eth from '@ledgerhq/hw-app-eth'; import TransportU2F from '@ledgerhq/hw-transport-u2f'; +export import Web3ProviderEngine = require('web3-provider-engine'); export { ECSignature } from '@0xproject/types'; import { LedgerEthereumClient } from './types'; @@ -10,6 +11,7 @@ export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_sub export { SignerSubprovider } from './subproviders/signer'; export { RedundantSubprovider } from './subproviders/redundant_subprovider'; export { LedgerSubprovider } from './subproviders/ledger'; +export { RPCSubprovider } from './subproviders/rpc_subprovider'; export { GanacheSubprovider } from './subproviders/ganache'; export { Subprovider } from './subproviders/subprovider'; export { NonceTrackerSubprovider } from './subproviders/nonce_tracker'; diff --git a/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts b/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts index a9ebbb790..454dae58e 100644 --- a/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts +++ b/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts @@ -12,8 +12,8 @@ import { PrivateKeyWalletSubprovider } from './private_key_wallet'; * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js */ export class EthLightwalletSubprovider extends BaseWalletSubprovider { - private _keystore: lightwallet.keystore; - private _pwDerivedKey: Uint8Array; + private readonly _keystore: lightwallet.keystore; + private readonly _pwDerivedKey: Uint8Array; constructor(keystore: lightwallet.keystore, pwDerivedKey: Uint8Array) { super(); this._keystore = keystore; diff --git a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts index d750505e7..bc1b34aba 100644 --- a/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts +++ b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts @@ -14,7 +14,7 @@ import { Subprovider } from './subprovider'; * It intercepts the `eth_estimateGas` JSON RPC call and always returns a constant gas amount when queried. */ export class FakeGasEstimateSubprovider extends Subprovider { - private _constantGasAmount: number; + private readonly _constantGasAmount: number; /** * Instantiates an instance of the FakeGasEstimateSubprovider * @param constantGasAmount The constant gas amount you want returned diff --git a/packages/subproviders/src/subproviders/ganache.ts b/packages/subproviders/src/subproviders/ganache.ts index 79c43bc68..986094dba 100644 --- a/packages/subproviders/src/subproviders/ganache.ts +++ b/packages/subproviders/src/subproviders/ganache.ts @@ -10,7 +10,7 @@ import { Subprovider } from './subprovider'; * It intercepts all JSON RPC requests and relays them to an in-process ganache instance. */ export class GanacheSubprovider extends Subprovider { - private _ganacheProvider: Provider; + private readonly _ganacheProvider: Provider; /** * Instantiates a GanacheSubprovider * @param opts The desired opts with which to instantiate the Ganache provider diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts index 8345be33c..6ad5de2e2 100644 --- a/packages/subproviders/src/subproviders/ledger.ts +++ b/packages/subproviders/src/subproviders/ledger.ts @@ -32,14 +32,14 @@ const DEFAULT_ADDRESS_SEARCH_LIMIT = 1000; */ export class LedgerSubprovider extends BaseWalletSubprovider { // tslint:disable-next-line:no-unused-variable - private _nonceLock = new Lock(); - private _connectionLock = new Lock(); - private _networkId: number; + private readonly _nonceLock = new Lock(); + private readonly _connectionLock = new Lock(); + private readonly _networkId: number; private _baseDerivationPath: string; - private _ledgerEthereumClientFactoryAsync: LedgerEthereumClientFactoryAsync; + private readonly _ledgerEthereumClientFactoryAsync: LedgerEthereumClientFactoryAsync; private _ledgerClientIfExists?: LedgerEthereumClient; - private _shouldAlwaysAskForConfirmation: boolean; - private _addressSearchLimit: number; + private readonly _shouldAlwaysAskForConfirmation: boolean; + private readonly _addressSearchLimit: number; /** * Instantiates a LedgerSubprovider. Defaults to derivationPath set to `44'/60'/0'`. * TestRPC/Ganache defaults to `m/44'/60'/0'/0`, so set this in the configs if desired. diff --git a/packages/subproviders/src/subproviders/mnemonic_wallet.ts b/packages/subproviders/src/subproviders/mnemonic_wallet.ts index 596300425..1495112b6 100644 --- a/packages/subproviders/src/subproviders/mnemonic_wallet.ts +++ b/packages/subproviders/src/subproviders/mnemonic_wallet.ts @@ -20,10 +20,10 @@ const DEFAULT_ADDRESS_SEARCH_LIMIT = 1000; * all requests with accounts derived from the supplied mnemonic. */ export class MnemonicWalletSubprovider extends BaseWalletSubprovider { - private _addressSearchLimit: number; + private readonly _addressSearchLimit: number; private _baseDerivationPath: string; private _derivedKeyInfo: DerivedHDKeyInfo; - private _mnemonic: string; + private readonly _mnemonic: string; /** * Instantiates a MnemonicWalletSubprovider. Defaults to baseDerivationPath set to `44'/60'/0'/0`. diff --git a/packages/subproviders/src/subproviders/nonce_tracker.ts b/packages/subproviders/src/subproviders/nonce_tracker.ts index dcc421574..eea722aee 100644 --- a/packages/subproviders/src/subproviders/nonce_tracker.ts +++ b/packages/subproviders/src/subproviders/nonce_tracker.ts @@ -17,7 +17,7 @@ const NONCE_TOO_LOW_ERROR_MESSAGE = 'Transaction nonce is too low'; * We added the additional feature of clearing the cached nonce value when a `nonce value too low` error occurs. */ export class NonceTrackerSubprovider extends Subprovider { - private _nonceCache: { [address: string]: string } = {}; + private readonly _nonceCache: { [address: string]: string } = {}; private static _reconstructTransaction(payload: JSONRPCRequestPayload): EthereumTx { const raw = payload.params[0]; if (_.isUndefined(raw)) { diff --git a/packages/subproviders/src/subproviders/private_key_wallet.ts b/packages/subproviders/src/subproviders/private_key_wallet.ts index b3f48fd90..9d6fc487e 100644 --- a/packages/subproviders/src/subproviders/private_key_wallet.ts +++ b/packages/subproviders/src/subproviders/private_key_wallet.ts @@ -13,8 +13,8 @@ import { BaseWalletSubprovider } from './base_wallet_subprovider'; * all requests with the supplied Ethereum private key. */ export class PrivateKeyWalletSubprovider extends BaseWalletSubprovider { - private _address: string; - private _privateKeyBuffer: Buffer; + private readonly _address: string; + private readonly _privateKeyBuffer: Buffer; /** * Instantiates a PrivateKeyWalletSubprovider. * @param privateKey The corresponding private key to an Ethereum address diff --git a/packages/subproviders/src/subproviders/redundant_subprovider.ts b/packages/subproviders/src/subproviders/redundant_subprovider.ts index a60d6706e..7aa6226d5 100644 --- a/packages/subproviders/src/subproviders/redundant_subprovider.ts +++ b/packages/subproviders/src/subproviders/redundant_subprovider.ts @@ -12,7 +12,7 @@ import { Subprovider } from './subprovider'; * set of JSON RPC endpoints. */ export class RedundantSubprovider extends Subprovider { - private _subproviders: Subprovider[]; + private readonly _subproviders: Subprovider[]; private static async _firstSuccessAsync( subproviders: Subprovider[], payload: JSONRPCRequestPayload, diff --git a/packages/subproviders/src/subproviders/rpc_subprovider.ts b/packages/subproviders/src/subproviders/rpc_subprovider.ts new file mode 100644 index 000000000..d874c6f05 --- /dev/null +++ b/packages/subproviders/src/subproviders/rpc_subprovider.ts @@ -0,0 +1,90 @@ +import { assert } from '@0xproject/assert'; +import { StatusCodes } from '@0xproject/types'; +import { fetchAsync } from '@0xproject/utils'; +import { JSONRPCRequestPayload } from 'ethereum-types'; +import JsonRpcError = require('json-rpc-error'); + +import { Callback, ErrorCallback } from '../types'; + +import { Subprovider } from './subprovider'; + +/** + * This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface. + * It forwards on JSON RPC requests to the supplied `rpcUrl` endpoint + */ +export class RPCSubprovider extends Subprovider { + private readonly _rpcUrl: string; + private readonly _requestTimeoutMs: number; + constructor(rpcUrl: string, requestTimeoutMs: number = 20000) { + super(); + assert.isString('rpcUrl', rpcUrl); + assert.isNumber('requestTimeoutMs', requestTimeoutMs); + this._rpcUrl = rpcUrl; + this._requestTimeoutMs = requestTimeoutMs; + } + /** + * This method conforms to the web3-provider-engine interface. + * It is called internally by the ProviderEngine when it is this subproviders + * turn to handle a JSON RPC request. + * @param payload JSON RPC payload + * @param next Callback to call if this subprovider decides not to handle the request + * @param end Callback to call if subprovider handled the request and wants to pass back the request. + */ + // tslint:disable-next-line:prefer-function-over-method async-suffix + public async handleRequest(payload: JSONRPCRequestPayload, _next: Callback, end: ErrorCallback): Promise<void> { + const finalPayload = Subprovider._createFinalPayload(payload); + const headers = new Headers({ + Accept: 'application/json', + 'Content-Type': 'application/json', + }); + + let response; + try { + response = await fetchAsync( + this._rpcUrl, + { + method: 'POST', + headers, + body: JSON.stringify(finalPayload), + }, + this._requestTimeoutMs, + ); + } catch (err) { + end(new JsonRpcError.InternalError(err)); + return; + } + + const text = await response.text(); + if (!response.ok) { + const statusCode = response.status; + switch (statusCode) { + case StatusCodes.MethodNotAllowed: + end(new JsonRpcError.MethodNotFound()); + return; + case StatusCodes.GatewayTimeout: + const errMsg = + 'Gateway timeout. The request took too long to process. This can happen when querying logs over too wide a block range.'; + const err = new Error(errMsg); + end(new JsonRpcError.InternalError(err)); + return; + default: + end(new JsonRpcError.InternalError(text)); + return; + } + } + + let data; + try { + data = JSON.parse(text); + } catch (err) { + end(new JsonRpcError.InternalError(err)); + return; + } + + if (data.error) { + end(data.error); + return; + } + end(null, data.result); + } +} diff --git a/packages/subproviders/src/subproviders/signer.ts b/packages/subproviders/src/subproviders/signer.ts index f7329e00c..d5fd86897 100644 --- a/packages/subproviders/src/subproviders/signer.ts +++ b/packages/subproviders/src/subproviders/signer.ts @@ -12,7 +12,7 @@ import { Subprovider } from './subprovider'; * are passed onwards for subsequent subproviders to handle. */ export class SignerSubprovider extends Subprovider { - private _web3Wrapper: Web3Wrapper; + private readonly _web3Wrapper: Web3Wrapper; /** * Instantiates a new SignerSubprovider * @param provider Web3 provider that should handle all user account related requests diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts index ff8378c4e..5dc273569 100644 --- a/packages/subproviders/src/subproviders/subprovider.ts +++ b/packages/subproviders/src/subproviders/subprovider.ts @@ -9,18 +9,7 @@ import { Callback, ErrorCallback, JSONRPCRequestPayloadWithMethod } from '../typ export abstract class Subprovider { // tslint:disable-next-line:underscore-private-and-protected private engine!: Provider; - // Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js - private static _getRandomId(): number { - const extraDigits = 3; - const baseTen = 10; - // 13 time digits - const datePart = new Date().getTime() * Math.pow(baseTen, extraDigits); - // 3 random digits - const extraPart = Math.floor(Math.random() * Math.pow(baseTen, extraDigits)); - // 16 digits - return datePart + extraPart; - } - private static _createFinalPayload( + protected static _createFinalPayload( payload: Partial<JSONRPCRequestPayloadWithMethod>, ): Partial<JSONRPCRequestPayloadWithMethod> { const finalPayload = { @@ -32,6 +21,17 @@ export abstract class Subprovider { }; return finalPayload; } + // Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js + private static _getRandomId(): number { + const extraDigits = 3; + const baseTen = 10; + // 13 time digits + const datePart = new Date().getTime() * Math.pow(baseTen, extraDigits); + // 3 random digits + const extraPart = Math.floor(Math.random() * Math.pow(baseTen, extraDigits)); + // 16 digits + return datePart + extraPart; + } // tslint:disable-next-line:async-suffix public abstract async handleRequest( payload: JSONRPCRequestPayload, diff --git a/packages/subproviders/src/utils/subprovider_utils.ts b/packages/subproviders/src/utils/subprovider_utils.ts index 24ebedd06..beda408ab 100644 --- a/packages/subproviders/src/utils/subprovider_utils.ts +++ b/packages/subproviders/src/utils/subprovider_utils.ts @@ -1,4 +1,4 @@ -import ProviderEngine = require('web3-provider-engine'); +import Web3ProviderEngine = require('web3-provider-engine'); import { Subprovider } from '../subproviders/subprovider'; @@ -7,7 +7,7 @@ import { Subprovider } from '../subproviders/subprovider'; * @param provider Given provider * @param subprovider Subprovider to prepend */ -export function prependSubprovider(provider: ProviderEngine, subprovider: Subprovider): void { +export function prependSubprovider(provider: Web3ProviderEngine, subprovider: Subprovider): void { subprovider.setEngine(provider); // HACK: We use implementation details of provider engine here // https://github.com/MetaMask/provider-engine/blob/master/index.js#L68 diff --git a/packages/subproviders/src/utils/wallet_utils.ts b/packages/subproviders/src/utils/wallet_utils.ts index 3748077ef..4c233645b 100644 --- a/packages/subproviders/src/utils/wallet_utils.ts +++ b/packages/subproviders/src/utils/wallet_utils.ts @@ -6,8 +6,8 @@ import { DerivedHDKeyInfo } from '../types'; const DEFAULT_ADDRESS_SEARCH_LIMIT = 1000; class DerivedHDKeyInfoIterator implements IterableIterator<DerivedHDKeyInfo> { - private _parentDerivedKeyInfo: DerivedHDKeyInfo; - private _searchLimit: number; + private readonly _parentDerivedKeyInfo: DerivedHDKeyInfo; + private readonly _searchLimit: number; private _index: number; constructor(initialDerivedKey: DerivedHDKeyInfo, searchLimit: number = DEFAULT_ADDRESS_SEARCH_LIMIT) { diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts index 196cecf32..527ee5b22 100644 --- a/packages/subproviders/test/integration/ledger_subprovider_test.ts +++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts @@ -7,10 +7,8 @@ import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); -import { LedgerSubprovider } from '../../src'; +import { LedgerSubprovider, RPCSubprovider, Web3ProviderEngine } from '../../src'; import { LedgerEthereumClient } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; @@ -86,9 +84,7 @@ describe('LedgerSubprovider', () => { before(() => { ledgerProvider = new Web3ProviderEngine(); ledgerProvider.addProvider(ledgerSubprovider); - const httpProvider = new RpcSubprovider({ - rpcUrl: 'http://localhost:8545', - }); + const httpProvider = new RPCSubprovider('http://localhost:8545'); ledgerProvider.addProvider(httpProvider); ledgerProvider.start(); @@ -180,7 +176,7 @@ describe('LedgerSubprovider', () => { params: [tx], id: 1, }; - await promisify(defaultProvider.sendAsync, defaultProvider)(payload); + await promisify(defaultProvider.sendAsync.bind(defaultProvider))(payload); // Send transaction from Ledger tx = { diff --git a/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts index f17c21f02..063817a95 100644 --- a/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts @@ -2,9 +2,8 @@ import * as chai from 'chai'; import * as lightwallet from 'eth-lightwallet'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { EthLightwalletSubprovider } from '../../src'; +import { EthLightwalletSubprovider, Web3ProviderEngine } from '../../src'; import { DoneCallback } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts index 3b57e125b..a1d146dbc 100644 --- a/packages/subproviders/test/unit/ledger_subprovider_test.ts +++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts @@ -2,9 +2,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; import * as _ from 'lodash'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { LedgerSubprovider } from '../../src'; +import { LedgerSubprovider, Web3ProviderEngine } from '../../src'; import { DoneCallback, LedgerCommunicationClient, @@ -56,7 +55,7 @@ describe('LedgerSubprovider', () => { return ecSignature; }, transport: { - close: _.noop, + close: _.noop.bind(_), } as LedgerCommunicationClient, }; // tslint:enable:no-object-literal-type-assertion diff --git a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts index 51ba7094c..f2bdda3cd 100644 --- a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts @@ -1,9 +1,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { GanacheSubprovider, MnemonicWalletSubprovider } from '../../src/'; +import { GanacheSubprovider, MnemonicWalletSubprovider, Web3ProviderEngine } from '../../src/'; import { DoneCallback, WalletSubproviderErrors } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; diff --git a/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts b/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts index fa33cd50a..05f213cf5 100644 --- a/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts +++ b/packages/subproviders/test/unit/nonce_tracker_subprovider_test.ts @@ -1,11 +1,10 @@ import * as chai from 'chai'; -import Web3ProviderEngine = require('web3-provider-engine'); import FixtureSubprovider = require('web3-provider-engine/subproviders/fixture'); import { promisify } from '@0xproject/utils'; import EthereumTx = require('ethereumjs-tx'); -import { NonceTrackerSubprovider } from '../../src'; +import { NonceTrackerSubprovider, Web3ProviderEngine } from '../../src'; import { chaiSetup } from '../chai_setup'; const expect = chai.expect; @@ -61,9 +60,9 @@ describe('NonceTrackerSubprovider', () => { const payload = { ...getTransactionCountPayload, params: ['0x0', 'pending'] }; - const response = await promisify<any>(provider.sendAsync, provider)(payload); + const response = await promisify<any>(provider.sendAsync.bind(provider))(payload); expect(response.result).to.be.eq('0x00'); - const secondResponse = await promisify<any>(provider.sendAsync, provider)(payload); + const secondResponse = await promisify<any>(provider.sendAsync.bind(provider))(payload); expect(secondResponse.result).to.be.eq('0x00'); }); it('does not cache the result for latest transaction count', async () => { @@ -75,9 +74,9 @@ describe('NonceTrackerSubprovider', () => { const payload = { ...getTransactionCountPayload, params: ['0x0', 'latest'] }; - const response = await promisify<any>(provider.sendAsync, provider)(payload); + const response = await promisify<any>(provider.sendAsync.bind(provider))(payload); expect(response.result).to.be.eq('0x00'); - const secondResponse = await promisify<any>(provider.sendAsync, provider)(payload); + const secondResponse = await promisify<any>(provider.sendAsync.bind(provider))(payload); expect(secondResponse.result).to.be.eq('0x99'); }); it('clears the cache on a Nonce Too Low Error', async () => { @@ -104,14 +103,14 @@ describe('NonceTrackerSubprovider', () => { params: [transaction.serialize()], }; - const response = await promisify<any>(provider.sendAsync, provider)(noncePayload); + const response = await promisify<any>(provider.sendAsync.bind(provider))(noncePayload); expect(response.result).to.be.eq('0x00'); - const secondResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload); + const secondResponse = await promisify<any>(provider.sendAsync.bind(provider))(noncePayload); expect(secondResponse.result).to.be.eq('0x00'); try { - await promisify(provider.sendAsync, provider)(txPayload); + await promisify(provider.sendAsync.bind(provider))(txPayload); } catch (err) { - const thirdResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload); + const thirdResponse = await promisify<any>(provider.sendAsync.bind(provider))(noncePayload); expect(thirdResponse.result).to.be.eq('0x99'); } }); @@ -139,12 +138,12 @@ describe('NonceTrackerSubprovider', () => { params: [transaction.serialize()], }; - const response = await promisify<any>(provider.sendAsync, provider)(noncePayload); + const response = await promisify<any>(provider.sendAsync.bind(provider))(noncePayload); expect(response.result).to.be.eq('0x00'); - const secondResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload); + const secondResponse = await promisify<any>(provider.sendAsync.bind(provider))(noncePayload); expect(secondResponse.result).to.be.eq('0x00'); - await promisify(provider.sendAsync, provider)(txPayload); - const thirdResponse = await promisify<any>(provider.sendAsync, provider)(noncePayload); + await promisify(provider.sendAsync.bind(provider))(txPayload); + const thirdResponse = await promisify<any>(provider.sendAsync.bind(provider))(noncePayload); expect(thirdResponse.result).to.be.eq('0x01'); }); }); diff --git a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts index ab321bcff..95773145f 100644 --- a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts @@ -1,9 +1,8 @@ import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as ethUtils from 'ethereumjs-util'; -import Web3ProviderEngine = require('web3-provider-engine'); -import { GanacheSubprovider, PrivateKeyWalletSubprovider } from '../../src/'; +import { GanacheSubprovider, PrivateKeyWalletSubprovider, Web3ProviderEngine } from '../../src/'; import { DoneCallback, WalletSubproviderErrors } from '../../src/types'; import { chaiSetup } from '../chai_setup'; import { fixtureData } from '../utils/fixture_data'; diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts index 810fb8f45..e30d2f74e 100644 --- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts +++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts @@ -2,10 +2,8 @@ import { DoneCallback } from '@0xproject/types'; import * as chai from 'chai'; import { JSONRPCResponsePayload } from 'ethereum-types'; import * as Sinon from 'sinon'; -import Web3ProviderEngine = require('web3-provider-engine'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); -import { RedundantSubprovider } from '../../src'; +import { RedundantSubprovider, RPCSubprovider, Web3ProviderEngine } from '../../src'; import { Subprovider } from '../../src/subproviders/subprovider'; import { chaiSetup } from '../chai_setup'; import { ganacheSubprovider } from '../utils/ganache_subprovider'; @@ -39,9 +37,7 @@ describe('RedundantSubprovider', () => { }); it('succeeds when supplied at least one healthy endpoint', (done: DoneCallback) => { provider = new Web3ProviderEngine(); - const nonExistentSubprovider = new RpcSubprovider({ - rpcUrl: 'http://does-not-exist:3000', - }); + const nonExistentSubprovider = new RPCSubprovider('http://does-not-exist:3000'); const handleRequestStub = Sinon.stub(nonExistentSubprovider, 'handleRequest').throws( new Error('REQUEST_FAILED'), ); diff --git a/packages/subproviders/tsconfig.json b/packages/subproviders/tsconfig.json index 72dfee80b..e35816553 100644 --- a/packages/subproviders/tsconfig.json +++ b/packages/subproviders/tsconfig.json @@ -1,8 +1,7 @@ { "extends": "../../tsconfig", "compilerOptions": { - "outDir": "lib", - "downlevelIteration": true + "outDir": "lib" }, "include": ["./src/**/*", "./test/**/*"] } |