diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-31 22:03:06 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-05-31 22:03:06 +0800 |
commit | 7f269cd791e4f0ed1515e90478de6b35683ce2bf (patch) | |
tree | 4fdf600a01f5776b0be015f311b10004fdde5a3f | |
parent | 722a6ad5dce484ef5875132fd57970390c69e85d (diff) | |
download | dexon-0x-contracts-7f269cd791e4f0ed1515e90478de6b35683ce2bf.tar.gz dexon-0x-contracts-7f269cd791e4f0ed1515e90478de6b35683ce2bf.tar.zst dexon-0x-contracts-7f269cd791e4f0ed1515e90478de6b35683ce2bf.zip |
Add createSignedOrder function
-rw-r--r-- | test/utils/order.ts | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/test/utils/order.ts b/test/utils/order.ts index a69c1b62f..2de87bac1 100644 --- a/test/utils/order.ts +++ b/test/utils/order.ts @@ -1,28 +1,45 @@ -import {SignedOrder} from '../../src/types'; +import {SignedOrder, Token} from '../../src/types'; import * as BigNumber from 'bignumber.js'; import * as _ from 'lodash'; import {ZeroEx} from '../../src/0x.js'; import {constants} from './constants'; -export async function createSignedOrder(zeroEx: ZeroEx): Promise<SignedOrder> { +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`); + } + 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: new BigNumber(5000000000000000000), - takerTokenAmount: new BigNumber(42000000000000000000), - makerTokenAddress: '0x07f96aa816c1f244cbc6ef114bb2b023ba54a2eb', - takerTokenAddress: '0x1e2f9e10d02a6b8f8f69fcbf515e75039d2ea30d', + 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), }; + console.log(order.makerTokenAmount.toString()); + console.log(order.takerTokenAmount.toString()); const orderHash = ZeroEx.getOrderHashHex(EXCHANGE_ADDRESS, order); const ecSignature = await zeroEx.signOrderHashAsync(orderHash); const signedOrder: SignedOrder = _.assign(order, {ecSignature}); + console.log(signedOrder); return signedOrder; } |