aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-12-22 22:05:32 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-01-03 18:37:38 +0800
commite744e4cd989bd3ae1070c59f7baa8097f18b8b06 (patch)
treea7fde03873f3c1b8689d3991edbb362f8022e5f0 /packages/0x.js/test/utils
parent9a96e8c704b6f84e00bbe848159a4819844cf09d (diff)
downloaddexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.gz
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.bz2
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.lz
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.xz
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.zst
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.zip
Apply prettier config
Diffstat (limited to 'packages/0x.js/test/utils')
-rw-r--r--packages/0x.js/test/utils/fill_scenarios.ts166
-rw-r--r--packages/0x.js/test/utils/order_factory.ts13
-rw-r--r--packages/0x.js/test/utils/report_callback_errors.ts2
-rw-r--r--packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts4
-rw-r--r--packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts4
-rw-r--r--packages/0x.js/test/utils/token_utils.ts6
-rw-r--r--packages/0x.js/test/utils/web3_factory.ts14
7 files changed, 138 insertions, 71 deletions
diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts
index 8f28ee503..734db8ee6 100644
--- a/packages/0x.js/test/utils/fill_scenarios.ts
+++ b/packages/0x.js/test/utils/fill_scenarios.ts
@@ -1,12 +1,12 @@
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import BigNumber from 'bignumber.js';
-import {SignedOrder, Token, ZeroEx} from '../../src';
-import {artifacts} from '../../src/artifacts';
-import {DummyTokenContract} from '../../src/contract_wrappers/generated/dummy_token';
-import {orderFactory} from '../utils/order_factory';
+import { SignedOrder, Token, ZeroEx } from '../../src';
+import { artifacts } from '../../src/artifacts';
+import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
+import { orderFactory } from '../utils/order_factory';
-import {constants} from './constants';
+import { constants } from './constants';
const INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS = new BigNumber(100);
@@ -17,8 +17,13 @@ export class FillScenarios {
private _coinbase: string;
private _zrxTokenAddress: string;
private _exchangeContractAddress: string;
- constructor(zeroEx: ZeroEx, userAddresses: string[],
- tokens: Token[], zrxTokenAddress: string, exchangeContractAddress: string) {
+ constructor(
+ zeroEx: ZeroEx,
+ userAddresses: string[],
+ tokens: Token[],
+ zrxTokenAddress: string,
+ exchangeContractAddress: string,
+ ) {
this._zeroEx = zeroEx;
this._userAddresses = userAddresses;
this._tokens = tokens;
@@ -31,7 +36,8 @@ export class FillScenarios {
for (const token of this._tokens) {
if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
const contractInstance = web3Wrapper.getContractInstance(
- artifacts.DummyTokenArtifact.abi, token.address,
+ artifacts.DummyTokenArtifact.abi,
+ token.address,
);
const defaults = {};
const dummyToken = new DummyTokenContract(contractInstance, defaults);
@@ -43,61 +49,110 @@ export class FillScenarios {
}
}
}
- public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
- makerAddress: string, takerAddress: string,
- fillableAmount: BigNumber,
- expirationUnixTimestampSec?: BigNumber):
- Promise<SignedOrder> {
+ 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,
+ makerTokenAddress,
+ takerTokenAddress,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ fillableAmount,
+ expirationUnixTimestampSec,
);
}
public async createFillableSignedOrderWithFeesAsync(
- makerTokenAddress: string, takerTokenAddress: string,
- makerFee: BigNumber, takerFee: BigNumber,
- makerAddress: string, takerAddress: string,
+ makerTokenAddress: string,
+ takerTokenAddress: string,
+ makerFee: BigNumber,
+ takerFee: BigNumber,
+ makerAddress: string,
+ takerAddress: string,
fillableAmount: BigNumber,
- feeRecepient: string, expirationUnixTimestampSec?: BigNumber,
+ feeRecepient: string,
+ expirationUnixTimestampSec?: BigNumber,
): Promise<SignedOrder> {
return this._createAsymmetricFillableSignedOrderWithFeesAsync(
- makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
- fillableAmount, fillableAmount, feeRecepient, expirationUnixTimestampSec,
+ 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> {
+ 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,
+ makerTokenAddress,
+ takerTokenAddress,
+ makerFee,
+ takerFee,
+ makerAddress,
+ takerAddress,
+ makerFillableAmount,
+ takerFillableAmount,
+ feeRecepient,
+ expirationUnixTimestampSec,
);
}
- public async createPartiallyFilledSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
- takerAddress: string, fillableAmount: BigNumber,
- partialFillAmount: BigNumber) {
+ 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,
+ makerTokenAddress,
+ takerTokenAddress,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ fillableAmount,
);
const shouldThrowOnInsufficientBalanceOrAllowance = false;
await this._zeroEx.exchange.fillOrderAsync(
- signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
+ 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> {
-
+ 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),
@@ -107,14 +162,27 @@ export class FillScenarios {
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);
+ 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> {
+ tokenAddress: string,
+ address: string,
+ amount: BigNumber,
+ ): Promise<void> {
if (amount.isZero() || address === ZeroEx.NULL_ADDRESS) {
return; // noop
}
@@ -123,16 +191,12 @@ export class FillScenarios {
this._increaseAllowanceAsync(tokenAddress, address, amount),
]);
}
- private async _increaseBalanceAsync(
- tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
+ 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> {
+ 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,
- );
+ 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 41d93e340..04768af65 100644
--- a/packages/0x.js/test/utils/order_factory.ts
+++ b/packages/0x.js/test/utils/order_factory.ts
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js';
import * as _ from 'lodash';
-import {SignedOrder, ZeroEx} from '../../src';
+import { SignedOrder, ZeroEx } from '../../src';
export const orderFactory = {
async createSignedOrderAsync(
@@ -16,11 +16,12 @@ export const orderFactory = {
takerTokenAddress: string,
exchangeContractAddress: string,
feeRecipient: string,
- expirationUnixTimestampSecIfExists?: BigNumber): Promise<SignedOrder> {
+ expirationUnixTimestampSecIfExists?: BigNumber,
+ ): Promise<SignedOrder> {
const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite
- const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists) ?
- defaultExpirationUnixTimestampSec :
- expirationUnixTimestampSecIfExists;
+ const expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSecIfExists)
+ ? defaultExpirationUnixTimestampSec
+ : expirationUnixTimestampSecIfExists;
const order = {
maker,
taker,
@@ -37,7 +38,7 @@ export const orderFactory = {
};
const orderHash = ZeroEx.getOrderHashHex(order);
const ecSignature = await zeroEx.signOrderHashAsync(orderHash, maker);
- const signedOrder: SignedOrder = _.assign(order, {ecSignature});
+ 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 0aaef3f05..8a8f4d966 100644
--- a/packages/0x.js/test/utils/report_callback_errors.ts
+++ b/packages/0x.js/test/utils/report_callback_errors.ts
@@ -1,4 +1,4 @@
-import {DoneCallback} from '../../src/types';
+import { DoneCallback } from '../../src/types';
export const reportCallbackErrors = (done: DoneCallback) => {
return (f: (...args: any[]) => void) => {
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 e5e279873..53f2be83d 100644
--- a/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts
+++ b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts
@@ -1,4 +1,4 @@
-import {JSONRPCPayload} from '../../../src/types';
+import { JSONRPCPayload } from '../../../src/types';
/*
* This class implements the web3-provider-engine subprovider interface and returns
@@ -8,7 +8,7 @@ import {JSONRPCPayload} from '../../../src/types';
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) {
+ public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
switch (payload.method) {
case 'eth_accounts':
end(null, []);
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 d502ca34e..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
@@ -1,4 +1,4 @@
-import {JSONRPCPayload} from '../../../src/types';
+import { JSONRPCPayload } from '../../../src/types';
/*
* This class implements the web3-provider-engine subprovider interface and returns
@@ -15,7 +15,7 @@ export class FakeGasEstimateSubprovider {
}
// 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) {
+ public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
switch (payload.method) {
case 'eth_estimateGas':
end(null, this._constantGasAmount);
diff --git a/packages/0x.js/test/utils/token_utils.ts b/packages/0x.js/test/utils/token_utils.ts
index 48b5e1798..d3fc22ff4 100644
--- a/packages/0x.js/test/utils/token_utils.ts
+++ b/packages/0x.js/test/utils/token_utils.ts
@@ -1,6 +1,6 @@
import * as _ from 'lodash';
-import {InternalZeroExError, Token} from '../../src/types';
+import { InternalZeroExError, Token } from '../../src/types';
const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
const WETH_TOKEN_SYMBOL = 'WETH';
@@ -11,14 +11,14 @@ export class TokenUtils {
this._tokens = tokens;
}
public getProtocolTokenOrThrow(): Token {
- const zrxToken = _.find(this._tokens, {symbol: PROTOCOL_TOKEN_SYMBOL});
+ 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});
+ const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL });
if (_.isUndefined(wethToken)) {
throw new Error(InternalZeroExError.WethNotInTokenRegistry);
}
diff --git a/packages/0x.js/test/utils/web3_factory.ts b/packages/0x.js/test/utils/web3_factory.ts
index 7e65a4381..26c26e03d 100644
--- a/packages/0x.js/test/utils/web3_factory.ts
+++ b/packages/0x.js/test/utils/web3_factory.ts
@@ -6,10 +6,10 @@
import ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
-import {EmptyWalletSubprovider} from './subproviders/empty_wallet_subprovider';
-import {FakeGasEstimateSubprovider} from './subproviders/fake_gas_estimate_subprovider';
+import { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider';
+import { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider';
-import {constants} from './constants';
+import { constants } from './constants';
// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang
// because they are using the wrong XHR package.
@@ -31,9 +31,11 @@ export const web3Factory = {
provider.addProvider(new EmptyWalletSubprovider());
}
provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_ESTIMATE));
- provider.addProvider(new RpcSubprovider({
- rpcUrl: constants.RPC_URL,
- }));
+ provider.addProvider(
+ new RpcSubprovider({
+ rpcUrl: constants.RPC_URL,
+ }),
+ );
provider.start();
return provider;
},