aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-30 20:26:46 +0800
committerFabio Berger <me@fabioberger.com>2018-01-30 20:26:46 +0800
commitc6dece6bd1e5f5afa56b290557eb7a6245c76cb6 (patch)
treead7a33ffe5d80c0eb41ae10fbc8314f193e52383 /packages/0x.js/test/utils
parent93a5b3f457c1211676296840c285759007a55500 (diff)
downloaddexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.gz
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.bz2
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.lz
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.xz
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.zst
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.zip
Add config file specifically in prettier command and fix files
Diffstat (limited to 'packages/0x.js/test/utils')
-rw-r--r--packages/0x.js/test/utils/chai_setup.ts12
-rw-r--r--packages/0x.js/test/utils/constants.ts18
-rw-r--r--packages/0x.js/test/utils/fill_scenarios.ts374
-rw-r--r--packages/0x.js/test/utils/order_factory.ts74
-rw-r--r--packages/0x.js/test/utils/report_callback_errors.ts102
-rw-r--r--packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts34
-rw-r--r--packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts42
-rw-r--r--packages/0x.js/test/utils/token_utils.ts48
-rw-r--r--packages/0x.js/test/utils/web3_factory.ts40
9 files changed, 372 insertions, 372 deletions
diff --git a/packages/0x.js/test/utils/chai_setup.ts b/packages/0x.js/test/utils/chai_setup.ts
index e156b5f7c..078edd309 100644
--- a/packages/0x.js/test/utils/chai_setup.ts
+++ b/packages/0x.js/test/utils/chai_setup.ts
@@ -4,10 +4,10 @@ import ChaiBigNumber = require('chai-bignumber');
import * as dirtyChai from 'dirty-chai';
export const chaiSetup = {
- configure() {
- chai.config.includeStack = true;
- chai.use(ChaiBigNumber());
- chai.use(dirtyChai);
- chai.use(chaiAsPromised);
- },
+ configure() {
+ chai.config.includeStack = true;
+ chai.use(ChaiBigNumber());
+ chai.use(dirtyChai);
+ chai.use(chaiAsPromised);
+ },
};
diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts
index b7161e9ab..a9e665c25 100644
--- a/packages/0x.js/test/utils/constants.ts
+++ b/packages/0x.js/test/utils/constants.ts
@@ -1,11 +1,11 @@
export const constants = {
- NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
- RPC_URL: 'http://localhost:8545',
- ROPSTEN_NETWORK_ID: 3,
- KOVAN_NETWORK_ID: 42,
- TESTRPC_NETWORK_ID: 50,
- KOVAN_RPC_URL: 'https://kovan.infura.io/',
- ROPSTEN_RPC_URL: 'https://ropsten.infura.io/',
- ZRX_DECIMALS: 18,
- GAS_ESTIMATE: 500000,
+ NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
+ RPC_URL: 'http://localhost:8545',
+ ROPSTEN_NETWORK_ID: 3,
+ KOVAN_NETWORK_ID: 42,
+ TESTRPC_NETWORK_ID: 50,
+ KOVAN_RPC_URL: 'https://kovan.infura.io/',
+ ROPSTEN_RPC_URL: 'https://ropsten.infura.io/',
+ ZRX_DECIMALS: 18,
+ GAS_ESTIMATE: 500000,
};
diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts
index 1d4b8b6f4..1a61487f4 100644
--- a/packages/0x.js/test/utils/fill_scenarios.ts
+++ b/packages/0x.js/test/utils/fill_scenarios.ts
@@ -11,192 +11,192 @@ import { constants } from './constants';
const INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS = new BigNumber(100);
export class FillScenarios {
- private _zeroEx: ZeroEx;
- private _userAddresses: string[];
- private _tokens: Token[];
- private _coinbase: string;
- private _zrxTokenAddress: string;
- private _exchangeContractAddress: string;
- constructor(
- zeroEx: ZeroEx,
- userAddresses: string[],
- tokens: Token[],
- zrxTokenAddress: string,
- exchangeContractAddress: string,
- ) {
- this._zeroEx = zeroEx;
- this._userAddresses = userAddresses;
- this._tokens = tokens;
- this._coinbase = userAddresses[0];
- this._zrxTokenAddress = zrxTokenAddress;
- this._exchangeContractAddress = exchangeContractAddress;
- }
- public async initTokenBalancesAsync() {
- const web3Wrapper = (this._zeroEx as any)._web3Wrapper as Web3Wrapper;
- for (const token of this._tokens) {
- if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
- const contractInstance = web3Wrapper.getContractInstance(
- artifacts.DummyTokenArtifact.abi,
- token.address,
- );
- const defaults = {};
- const dummyToken = new DummyTokenContract(contractInstance, defaults);
- const tokenSupply = ZeroEx.toBaseUnitAmount(INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS, token.decimals);
- const txHash = await dummyToken.setBalance.sendTransactionAsync(this._coinbase, tokenSupply, {
- from: this._coinbase,
- });
- await this._zeroEx.awaitTransactionMinedAsync(txHash);
- }
- }
- }
- public async createFillableSignedOrderAsync(
- makerTokenAddress: string,
- takerTokenAddress: string,
- makerAddress: string,
- takerAddress: string,
- fillableAmount: BigNumber,
- expirationUnixTimestampSec?: BigNumber,
- ): Promise<SignedOrder> {
- return this.createAsymmetricFillableSignedOrderAsync(
- makerTokenAddress,
- takerTokenAddress,
- makerAddress,
- takerAddress,
- fillableAmount,
- fillableAmount,
- expirationUnixTimestampSec,
- );
- }
- public async createFillableSignedOrderWithFeesAsync(
- makerTokenAddress: string,
- takerTokenAddress: string,
- makerFee: BigNumber,
- takerFee: BigNumber,
- makerAddress: string,
- takerAddress: string,
- fillableAmount: BigNumber,
- feeRecepient: string,
- expirationUnixTimestampSec?: BigNumber,
- ): Promise<SignedOrder> {
- return this._createAsymmetricFillableSignedOrderWithFeesAsync(
- makerTokenAddress,
- takerTokenAddress,
- makerFee,
- takerFee,
- makerAddress,
- takerAddress,
- fillableAmount,
- fillableAmount,
- feeRecepient,
- expirationUnixTimestampSec,
- );
- }
- public async createAsymmetricFillableSignedOrderAsync(
- makerTokenAddress: string,
- takerTokenAddress: string,
- makerAddress: string,
- takerAddress: string,
- makerFillableAmount: BigNumber,
- takerFillableAmount: BigNumber,
- expirationUnixTimestampSec?: BigNumber,
- ): Promise<SignedOrder> {
- const makerFee = new BigNumber(0);
- const takerFee = new BigNumber(0);
- const feeRecepient = constants.NULL_ADDRESS;
- return this._createAsymmetricFillableSignedOrderWithFeesAsync(
- makerTokenAddress,
- takerTokenAddress,
- makerFee,
- takerFee,
- makerAddress,
- takerAddress,
- makerFillableAmount,
- takerFillableAmount,
- feeRecepient,
- expirationUnixTimestampSec,
- );
- }
- public async createPartiallyFilledSignedOrderAsync(
- makerTokenAddress: string,
- takerTokenAddress: string,
- takerAddress: string,
- fillableAmount: BigNumber,
- partialFillAmount: BigNumber,
- ) {
- const [makerAddress] = this._userAddresses;
- const signedOrder = await this.createAsymmetricFillableSignedOrderAsync(
- makerTokenAddress,
- takerTokenAddress,
- makerAddress,
- takerAddress,
- fillableAmount,
- fillableAmount,
- );
- const shouldThrowOnInsufficientBalanceOrAllowance = false;
- await this._zeroEx.exchange.fillOrderAsync(
- signedOrder,
- partialFillAmount,
- shouldThrowOnInsufficientBalanceOrAllowance,
- takerAddress,
- );
- return signedOrder;
- }
- private async _createAsymmetricFillableSignedOrderWithFeesAsync(
- makerTokenAddress: string,
- takerTokenAddress: string,
- makerFee: BigNumber,
- takerFee: BigNumber,
- makerAddress: string,
- takerAddress: string,
- makerFillableAmount: BigNumber,
- takerFillableAmount: BigNumber,
- feeRecepient: string,
- expirationUnixTimestampSec?: BigNumber,
- ): Promise<SignedOrder> {
- await Promise.all([
- this._increaseBalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount),
- this._increaseBalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount),
- ]);
- await Promise.all([
- this._increaseBalanceAndAllowanceAsync(this._zrxTokenAddress, makerAddress, makerFee),
- this._increaseBalanceAndAllowanceAsync(this._zrxTokenAddress, takerAddress, takerFee),
- ]);
+ private _zeroEx: ZeroEx;
+ private _userAddresses: string[];
+ private _tokens: Token[];
+ private _coinbase: string;
+ private _zrxTokenAddress: string;
+ private _exchangeContractAddress: string;
+ constructor(
+ zeroEx: ZeroEx,
+ userAddresses: string[],
+ tokens: Token[],
+ zrxTokenAddress: string,
+ exchangeContractAddress: string,
+ ) {
+ this._zeroEx = zeroEx;
+ this._userAddresses = userAddresses;
+ this._tokens = tokens;
+ this._coinbase = userAddresses[0];
+ this._zrxTokenAddress = zrxTokenAddress;
+ this._exchangeContractAddress = exchangeContractAddress;
+ }
+ public async initTokenBalancesAsync() {
+ const web3Wrapper = (this._zeroEx as any)._web3Wrapper as Web3Wrapper;
+ for (const token of this._tokens) {
+ if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
+ const contractInstance = web3Wrapper.getContractInstance(
+ artifacts.DummyTokenArtifact.abi,
+ token.address,
+ );
+ const defaults = {};
+ const dummyToken = new DummyTokenContract(contractInstance, defaults);
+ const tokenSupply = ZeroEx.toBaseUnitAmount(INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS, token.decimals);
+ const txHash = await dummyToken.setBalance.sendTransactionAsync(this._coinbase, tokenSupply, {
+ from: this._coinbase,
+ });
+ await this._zeroEx.awaitTransactionMinedAsync(txHash);
+ }
+ }
+ }
+ public async createFillableSignedOrderAsync(
+ makerTokenAddress: string,
+ takerTokenAddress: string,
+ makerAddress: string,
+ takerAddress: string,
+ fillableAmount: BigNumber,
+ expirationUnixTimestampSec?: BigNumber,
+ ): Promise<SignedOrder> {
+ return this.createAsymmetricFillableSignedOrderAsync(
+ makerTokenAddress,
+ takerTokenAddress,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ fillableAmount,
+ expirationUnixTimestampSec,
+ );
+ }
+ public async createFillableSignedOrderWithFeesAsync(
+ makerTokenAddress: string,
+ takerTokenAddress: string,
+ makerFee: BigNumber,
+ takerFee: BigNumber,
+ makerAddress: string,
+ takerAddress: string,
+ fillableAmount: BigNumber,
+ feeRecepient: string,
+ expirationUnixTimestampSec?: BigNumber,
+ ): Promise<SignedOrder> {
+ return this._createAsymmetricFillableSignedOrderWithFeesAsync(
+ makerTokenAddress,
+ takerTokenAddress,
+ makerFee,
+ takerFee,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ fillableAmount,
+ feeRecepient,
+ expirationUnixTimestampSec,
+ );
+ }
+ public async createAsymmetricFillableSignedOrderAsync(
+ makerTokenAddress: string,
+ takerTokenAddress: string,
+ makerAddress: string,
+ takerAddress: string,
+ makerFillableAmount: BigNumber,
+ takerFillableAmount: BigNumber,
+ expirationUnixTimestampSec?: BigNumber,
+ ): Promise<SignedOrder> {
+ const makerFee = new BigNumber(0);
+ const takerFee = new BigNumber(0);
+ const feeRecepient = constants.NULL_ADDRESS;
+ return this._createAsymmetricFillableSignedOrderWithFeesAsync(
+ makerTokenAddress,
+ takerTokenAddress,
+ makerFee,
+ takerFee,
+ makerAddress,
+ takerAddress,
+ makerFillableAmount,
+ takerFillableAmount,
+ feeRecepient,
+ expirationUnixTimestampSec,
+ );
+ }
+ public async createPartiallyFilledSignedOrderAsync(
+ makerTokenAddress: string,
+ takerTokenAddress: string,
+ takerAddress: string,
+ fillableAmount: BigNumber,
+ partialFillAmount: BigNumber,
+ ) {
+ const [makerAddress] = this._userAddresses;
+ const signedOrder = await this.createAsymmetricFillableSignedOrderAsync(
+ makerTokenAddress,
+ takerTokenAddress,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ fillableAmount,
+ );
+ const shouldThrowOnInsufficientBalanceOrAllowance = false;
+ await this._zeroEx.exchange.fillOrderAsync(
+ signedOrder,
+ partialFillAmount,
+ shouldThrowOnInsufficientBalanceOrAllowance,
+ takerAddress,
+ );
+ return signedOrder;
+ }
+ private async _createAsymmetricFillableSignedOrderWithFeesAsync(
+ makerTokenAddress: string,
+ takerTokenAddress: string,
+ makerFee: BigNumber,
+ takerFee: BigNumber,
+ makerAddress: string,
+ takerAddress: string,
+ makerFillableAmount: BigNumber,
+ takerFillableAmount: BigNumber,
+ feeRecepient: string,
+ expirationUnixTimestampSec?: BigNumber,
+ ): Promise<SignedOrder> {
+ await Promise.all([
+ this._increaseBalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount),
+ this._increaseBalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount),
+ ]);
+ await Promise.all([
+ this._increaseBalanceAndAllowanceAsync(this._zrxTokenAddress, makerAddress, makerFee),
+ this._increaseBalanceAndAllowanceAsync(this._zrxTokenAddress, takerAddress, takerFee),
+ ]);
- const signedOrder = await orderFactory.createSignedOrderAsync(
- this._zeroEx,
- makerAddress,
- takerAddress,
- makerFee,
- takerFee,
- makerFillableAmount,
- makerTokenAddress,
- takerFillableAmount,
- takerTokenAddress,
- this._exchangeContractAddress,
- feeRecepient,
- expirationUnixTimestampSec,
- );
- return signedOrder;
- }
- private async _increaseBalanceAndAllowanceAsync(
- tokenAddress: string,
- address: string,
- amount: BigNumber,
- ): Promise<void> {
- if (amount.isZero() || address === ZeroEx.NULL_ADDRESS) {
- return; // noop
- }
- await Promise.all([
- this._increaseBalanceAsync(tokenAddress, address, amount),
- this._increaseAllowanceAsync(tokenAddress, address, amount),
- ]);
- }
- private async _increaseBalanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
- await this._zeroEx.token.transferAsync(tokenAddress, this._coinbase, address, amount);
- }
- private async _increaseAllowanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
- const oldMakerAllowance = await this._zeroEx.token.getProxyAllowanceAsync(tokenAddress, address);
- const newMakerAllowance = oldMakerAllowance.plus(amount);
- await this._zeroEx.token.setProxyAllowanceAsync(tokenAddress, address, newMakerAllowance);
- }
+ const signedOrder = await orderFactory.createSignedOrderAsync(
+ this._zeroEx,
+ makerAddress,
+ takerAddress,
+ makerFee,
+ takerFee,
+ makerFillableAmount,
+ makerTokenAddress,
+ takerFillableAmount,
+ takerTokenAddress,
+ this._exchangeContractAddress,
+ feeRecepient,
+ expirationUnixTimestampSec,
+ );
+ return signedOrder;
+ }
+ private async _increaseBalanceAndAllowanceAsync(
+ tokenAddress: string,
+ address: string,
+ amount: BigNumber,
+ ): Promise<void> {
+ if (amount.isZero() || address === ZeroEx.NULL_ADDRESS) {
+ return; // noop
+ }
+ await Promise.all([
+ this._increaseBalanceAsync(tokenAddress, address, amount),
+ this._increaseAllowanceAsync(tokenAddress, address, amount),
+ ]);
+ }
+ private async _increaseBalanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
+ await this._zeroEx.token.transferAsync(tokenAddress, this._coinbase, address, amount);
+ }
+ private async _increaseAllowanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
+ const oldMakerAllowance = await this._zeroEx.token.getProxyAllowanceAsync(tokenAddress, address);
+ const newMakerAllowance = oldMakerAllowance.plus(amount);
+ await this._zeroEx.token.setProxyAllowanceAsync(tokenAddress, address, newMakerAllowance);
+ }
}
diff --git a/packages/0x.js/test/utils/order_factory.ts b/packages/0x.js/test/utils/order_factory.ts
index b65920e64..08f2081a4 100644
--- a/packages/0x.js/test/utils/order_factory.ts
+++ b/packages/0x.js/test/utils/order_factory.ts
@@ -6,41 +6,41 @@ import { SignedOrder, ZeroEx } from '../../src';
const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false;
export const orderFactory = {
- async createSignedOrderAsync(
- zeroEx: ZeroEx,
- maker: string,
- taker: string,
- makerFee: BigNumber,
- takerFee: BigNumber,
- makerTokenAmount: BigNumber,
- makerTokenAddress: string,
- takerTokenAmount: BigNumber,
- takerTokenAddress: string,
- exchangeContractAddress: string,
- feeRecipient: string,
- expirationUnixTimestampSecIfExists?: BigNumber,
- ): Promise<SignedOrder> {
- const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite
- const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists)
- ? defaultExpirationUnixTimestampSec
- : expirationUnixTimestampSecIfExists;
- const order = {
- maker,
- taker,
- makerFee,
- takerFee,
- makerTokenAmount,
- takerTokenAmount,
- makerTokenAddress,
- takerTokenAddress,
- salt: ZeroEx.generatePseudoRandomSalt(),
- exchangeContractAddress,
- feeRecipient,
- expirationUnixTimestampSec,
- };
- const orderHash = ZeroEx.getOrderHashHex(order);
- const ecSignature = await zeroEx.signOrderHashAsync(orderHash, maker, SHOULD_ADD_PERSONAL_MESSAGE_PREFIX);
- const signedOrder: SignedOrder = _.assign(order, { ecSignature });
- return signedOrder;
- },
+ async createSignedOrderAsync(
+ zeroEx: ZeroEx,
+ maker: string,
+ taker: string,
+ makerFee: BigNumber,
+ takerFee: BigNumber,
+ makerTokenAmount: BigNumber,
+ makerTokenAddress: string,
+ takerTokenAmount: BigNumber,
+ takerTokenAddress: string,
+ exchangeContractAddress: string,
+ feeRecipient: string,
+ expirationUnixTimestampSecIfExists?: BigNumber,
+ ): Promise<SignedOrder> {
+ const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite
+ const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists)
+ ? defaultExpirationUnixTimestampSec
+ : expirationUnixTimestampSecIfExists;
+ const order = {
+ maker,
+ taker,
+ makerFee,
+ takerFee,
+ makerTokenAmount,
+ takerTokenAmount,
+ makerTokenAddress,
+ takerTokenAddress,
+ salt: ZeroEx.generatePseudoRandomSalt(),
+ exchangeContractAddress,
+ feeRecipient,
+ expirationUnixTimestampSec,
+ };
+ const orderHash = ZeroEx.getOrderHashHex(order);
+ const ecSignature = await zeroEx.signOrderHashAsync(orderHash, maker, SHOULD_ADD_PERSONAL_MESSAGE_PREFIX);
+ const signedOrder: SignedOrder = _.assign(order, { ecSignature });
+ return signedOrder;
+ },
};
diff --git a/packages/0x.js/test/utils/report_callback_errors.ts b/packages/0x.js/test/utils/report_callback_errors.ts
index 0b619f73e..27c9745c9 100644
--- a/packages/0x.js/test/utils/report_callback_errors.ts
+++ b/packages/0x.js/test/utils/report_callback_errors.ts
@@ -6,61 +6,61 @@ import { DoneCallback } from '../../src/types';
const expect = chai.expect;
export const reportNoErrorCallbackErrors = (done: DoneCallback, expectToBeCalledOnce = true) => {
- return <T>(f?: (value: T) => void) => {
- const wrapped = (value: T) => {
- if (_.isUndefined(f)) {
- done();
- return;
- }
- try {
- f(value);
- if (expectToBeCalledOnce) {
- done();
- }
- } catch (err) {
- done(err);
- }
- };
- return wrapped;
- };
+ return <T>(f?: (value: T) => void) => {
+ const wrapped = (value: T) => {
+ if (_.isUndefined(f)) {
+ done();
+ return;
+ }
+ try {
+ f(value);
+ if (expectToBeCalledOnce) {
+ done();
+ }
+ } catch (err) {
+ done(err);
+ }
+ };
+ return wrapped;
+ };
};
export const reportNodeCallbackErrors = (done: DoneCallback, expectToBeCalledOnce = true) => {
- return <T>(f?: (value: T) => void) => {
- const wrapped = (error: Error | null, value: T | undefined) => {
- if (!_.isNull(error)) {
- done(error);
- } else {
- if (_.isUndefined(f)) {
- done();
- return;
- }
- try {
- f(value as T);
- if (expectToBeCalledOnce) {
- done();
- }
- } catch (err) {
- done(err);
- }
- }
- };
- return wrapped;
- };
+ return <T>(f?: (value: T) => void) => {
+ const wrapped = (error: Error | null, value: T | undefined) => {
+ if (!_.isNull(error)) {
+ done(error);
+ } else {
+ if (_.isUndefined(f)) {
+ done();
+ return;
+ }
+ try {
+ f(value as T);
+ if (expectToBeCalledOnce) {
+ done();
+ }
+ } catch (err) {
+ done(err);
+ }
+ }
+ };
+ return wrapped;
+ };
};
export const assertNodeCallbackError = (done: DoneCallback, errMsg: string) => {
- const wrapped = <T>(error: Error | null, value: T | undefined) => {
- if (_.isNull(error)) {
- done(new Error('Expected callback to receive an error'));
- } else {
- try {
- expect(error.message).to.be.equal(errMsg);
- done();
- } catch (err) {
- done(err);
- }
- }
- };
- return wrapped;
+ const wrapped = <T>(error: Error | null, value: T | undefined) => {
+ if (_.isNull(error)) {
+ done(new Error('Expected callback to receive an error'));
+ } else {
+ try {
+ expect(error.message).to.be.equal(errMsg);
+ done();
+ } catch (err) {
+ done(err);
+ }
+ }
+ };
+ return wrapped;
};
diff --git a/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts
index 466b0f350..53f2be83d 100644
--- a/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts
+++ b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts
@@ -6,22 +6,22 @@ import { JSONRPCPayload } from '../../../src/types';
* Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js
*/
export class EmptyWalletSubprovider {
- // This method needs to be here to satisfy the interface but linter wants it to be static.
- // tslint:disable-next-line:prefer-function-over-method
- public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
- switch (payload.method) {
- case 'eth_accounts':
- end(null, []);
- return;
+ // This method needs to be here to satisfy the interface but linter wants it to be static.
+ // tslint:disable-next-line:prefer-function-over-method
+ public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
+ switch (payload.method) {
+ case 'eth_accounts':
+ end(null, []);
+ return;
- default:
- next();
- return;
- }
- }
- // Required to implement this method despite not needing it for this subprovider
- // tslint:disable-next-line:prefer-function-over-method
- public setEngine(engine: any) {
- // noop
- }
+ default:
+ next();
+ return;
+ }
+ }
+ // Required to implement this method despite not needing it for this subprovider
+ // tslint:disable-next-line:prefer-function-over-method
+ public setEngine(engine: any) {
+ // noop
+ }
}
diff --git a/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts b/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts
index 307bfb188..e1113a851 100644
--- a/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts
+++ b/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts
@@ -9,26 +9,26 @@ import { JSONRPCPayload } from '../../../src/types';
* Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js
*/
export class FakeGasEstimateSubprovider {
- private _constantGasAmount: number;
- constructor(constantGasAmount: number) {
- this._constantGasAmount = constantGasAmount;
- }
- // This method needs to be here to satisfy the interface but linter wants it to be static.
- // tslint:disable-next-line:prefer-function-over-method
- public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
- switch (payload.method) {
- case 'eth_estimateGas':
- end(null, this._constantGasAmount);
- return;
+ private _constantGasAmount: number;
+ constructor(constantGasAmount: number) {
+ this._constantGasAmount = constantGasAmount;
+ }
+ // This method needs to be here to satisfy the interface but linter wants it to be static.
+ // tslint:disable-next-line:prefer-function-over-method
+ public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
+ switch (payload.method) {
+ case 'eth_estimateGas':
+ end(null, this._constantGasAmount);
+ return;
- default:
- next();
- return;
- }
- }
- // Required to implement this method despite not needing it for this subprovider
- // tslint:disable-next-line:prefer-function-over-method
- public setEngine(engine: any) {
- // noop
- }
+ default:
+ next();
+ return;
+ }
+ }
+ // Required to implement this method despite not needing it for this subprovider
+ // tslint:disable-next-line:prefer-function-over-method
+ public setEngine(engine: any) {
+ // noop
+ }
}
diff --git a/packages/0x.js/test/utils/token_utils.ts b/packages/0x.js/test/utils/token_utils.ts
index 9cbefcf8e..d3fc22ff4 100644
--- a/packages/0x.js/test/utils/token_utils.ts
+++ b/packages/0x.js/test/utils/token_utils.ts
@@ -6,28 +6,28 @@ const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
const WETH_TOKEN_SYMBOL = 'WETH';
export class TokenUtils {
- private _tokens: Token[];
- constructor(tokens: Token[]) {
- this._tokens = tokens;
- }
- public getProtocolTokenOrThrow(): Token {
- const zrxToken = _.find(this._tokens, { symbol: PROTOCOL_TOKEN_SYMBOL });
- if (_.isUndefined(zrxToken)) {
- throw new Error(InternalZeroExError.ZrxNotInTokenRegistry);
- }
- return zrxToken;
- }
- public getWethTokenOrThrow(): Token {
- const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL });
- if (_.isUndefined(wethToken)) {
- throw new Error(InternalZeroExError.WethNotInTokenRegistry);
- }
- return wethToken;
- }
- public getDummyTokens(): Token[] {
- const dummyTokens = _.filter(this._tokens, token => {
- return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
- });
- return dummyTokens;
- }
+ private _tokens: Token[];
+ constructor(tokens: Token[]) {
+ this._tokens = tokens;
+ }
+ public getProtocolTokenOrThrow(): Token {
+ const zrxToken = _.find(this._tokens, { symbol: PROTOCOL_TOKEN_SYMBOL });
+ if (_.isUndefined(zrxToken)) {
+ throw new Error(InternalZeroExError.ZrxNotInTokenRegistry);
+ }
+ return zrxToken;
+ }
+ public getWethTokenOrThrow(): Token {
+ const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL });
+ if (_.isUndefined(wethToken)) {
+ throw new Error(InternalZeroExError.WethNotInTokenRegistry);
+ }
+ return wethToken;
+ }
+ public getDummyTokens(): Token[] {
+ const dummyTokens = _.filter(this._tokens, token => {
+ return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
+ });
+ return dummyTokens;
+ }
}
diff --git a/packages/0x.js/test/utils/web3_factory.ts b/packages/0x.js/test/utils/web3_factory.ts
index 640b96256..26c26e03d 100644
--- a/packages/0x.js/test/utils/web3_factory.ts
+++ b/packages/0x.js/test/utils/web3_factory.ts
@@ -19,24 +19,24 @@ import { constants } from './constants';
import * as Web3 from 'web3';
export const web3Factory = {
- create(hasAddresses: boolean = true): Web3 {
- const provider = this.getRpcProvider(hasAddresses);
- const web3 = new Web3();
- web3.setProvider(provider);
- return web3;
- },
- getRpcProvider(hasAddresses: boolean = true): Web3.Provider {
- const provider = new ProviderEngine();
- if (!hasAddresses) {
- provider.addProvider(new EmptyWalletSubprovider());
- }
- provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_ESTIMATE));
- provider.addProvider(
- new RpcSubprovider({
- rpcUrl: constants.RPC_URL,
- }),
- );
- provider.start();
- return provider;
- },
+ create(hasAddresses: boolean = true): Web3 {
+ const provider = this.getRpcProvider(hasAddresses);
+ const web3 = new Web3();
+ web3.setProvider(provider);
+ return web3;
+ },
+ getRpcProvider(hasAddresses: boolean = true): Web3.Provider {
+ const provider = new ProviderEngine();
+ if (!hasAddresses) {
+ provider.addProvider(new EmptyWalletSubprovider());
+ }
+ provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_ESTIMATE));
+ provider.addProvider(
+ new RpcSubprovider({
+ rpcUrl: constants.RPC_URL,
+ }),
+ );
+ provider.start();
+ return provider;
+ },
};