aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/order.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/utils/order.ts')
-rw-r--r--test/utils/order.ts64
1 files changed, 30 insertions, 34 deletions
diff --git a/test/utils/order.ts b/test/utils/order.ts
index d775dc616..8a7d8430e 100644
--- a/test/utils/order.ts
+++ b/test/utils/order.ts
@@ -3,40 +3,36 @@ import * as BigNumber from 'bignumber.js';
import * as _ from 'lodash';
import {ZeroEx} from '../../src/0x.js';
import {constants} from './constants';
+import * as ExchangeArtifacts from '../../src/artifacts/Exchange.json';
-export async function createSignedOrder(
- zeroEx: ZeroEx,
- tokens: Token[],
- makerTokenAmount: BigNumber.BigNumber|number,
- makerTokenSymbol: string,
- takerTokenAmount: BigNumber.BigNumber|number,
- takerTokenSymbol: string): Promise<SignedOrder> {
- // TODO: fetch properly
- const EXCHANGE_ADDRESS = '0xb69e673309512a9d726f87304c6984054f87a93b';
- const INF_TIMESTAMP = 2524604400;
- const makerToken = _.find(tokens, {symbol: makerTokenSymbol});
- const takerToken = _.find(tokens, {symbol: takerTokenSymbol});
- if (_.isUndefined(makerToken)) {
- throw new Error(`Token ${makerTokenSymbol} not found`);
+export const orderFactory = {
+ async createSignedOrderAsync(
+ zeroEx: ZeroEx,
+ networkId: number,
+ maker: string,
+ makerTokenAmount: BigNumber.BigNumber|number,
+ makerTokenAddress: string,
+ takerTokenAmount: BigNumber.BigNumber|number,
+ takerTokenAddress: string): Promise<SignedOrder> {
+ // TODO refactor and check
+ const exchangeAddress: string = (ExchangeArtifacts as any).networks[networkId].address;
+ const INF_TIMESTAMP = 2524604400;
+ const order = {
+ maker,
+ taker: undefined,
+ makerFee: new BigNumber(0),
+ takerFee: new BigNumber(0),
+ makerTokenAmount: _.isNumber(makerTokenAmount) ? new BigNumber(makerTokenAmount) : makerTokenAmount,
+ takerTokenAmount: _.isNumber(takerTokenAmount) ? new BigNumber(takerTokenAmount) : takerTokenAmount,
+ makerTokenAddress,
+ takerTokenAddress,
+ salt: ZeroEx.generatePseudoRandomSalt(),
+ feeRecipient: constants.NULL_ADDRESS,
+ expirationUnixTimestampSec: new BigNumber(INF_TIMESTAMP),
+ };
+ const orderHash = ZeroEx.getOrderHashHex(exchangeAddress, order);
+ const ecSignature = await zeroEx.signOrderHashAsync(orderHash);
+ const signedOrder: SignedOrder = _.assign(order, {ecSignature});
+ return signedOrder;
}
- if (_.isUndefined(takerToken)) {
- throw new Error(`Token ${takerTokenSymbol} not found`);
- }
- const order = {
- maker: '0x5409ed021d9299bf6814279a6a1411a7e866a631',
- taker: undefined,
- makerFee: new BigNumber(0),
- takerFee: new BigNumber(0),
- makerTokenAmount: _.isNumber(makerTokenAmount) ? new BigNumber(makerTokenAmount) : makerTokenAmount,
- takerTokenAmount: _.isNumber(takerTokenAmount) ? new BigNumber(takerTokenAmount) : takerTokenAmount,
- makerTokenAddress: makerToken.address,
- takerTokenAddress: takerToken.address,
- salt: ZeroEx.generatePseudoRandomSalt(),
- feeRecipient: constants.NULL_ADDRESS,
- expirationUnixTimestampSec: new BigNumber(INF_TIMESTAMP),
- };
- const orderHash = ZeroEx.getOrderHashHex(EXCHANGE_ADDRESS, order);
- const ecSignature = await zeroEx.signOrderHashAsync(orderHash);
- const signedOrder: SignedOrder = _.assign(order, {ecSignature});
- return signedOrder;
}