diff options
Diffstat (limited to 'test/utils')
-rw-r--r-- | test/utils/blockchain_lifecycle.ts | 2 | ||||
-rw-r--r-- | test/utils/order_factory.ts | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/test/utils/blockchain_lifecycle.ts b/test/utils/blockchain_lifecycle.ts index 68e169ac0..50eb57b95 100644 --- a/test/utils/blockchain_lifecycle.ts +++ b/test/utils/blockchain_lifecycle.ts @@ -17,4 +17,4 @@ export class BlockchainLifecycle { throw new Error(`Snapshot with id #${this.snapshotId} failed to revert`); } } -}; +} diff --git a/test/utils/order_factory.ts b/test/utils/order_factory.ts new file mode 100644 index 000000000..0f370ed34 --- /dev/null +++ b/test/utils/order_factory.ts @@ -0,0 +1,40 @@ +import * as _ from 'lodash'; +import * as BigNumber from 'bignumber.js'; +import {SignedOrder, Token} from '../../src/types'; +import {ZeroEx} from '../../src/0x.js'; +import {constants} from './constants'; +import * as ExchangeArtifacts from '../../src/artifacts/Exchange.json'; + +export const orderFactory = { + async createSignedOrderAsync( + zeroEx: ZeroEx, + maker: string, + taker: string, + makerTokenAmount: BigNumber.BigNumber|number, + makerTokenAddress: string, + takerTokenAmount: BigNumber.BigNumber|number, + takerTokenAddress: string, + expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> { + const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite + expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSec) ? + defaultExpirationUnixTimestampSec : + expirationUnixTimestampSec; + const order = { + maker, + taker, + 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, + }; + const orderHash = await zeroEx.getOrderHashHexAsync(order); + const ecSignature = await zeroEx.signOrderHashAsync(orderHash); + const signedOrder: SignedOrder = _.assign(order, {ecSignature}); + return signedOrder; + }, +}; |