diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-18 18:04:57 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-18 18:04:57 +0800 |
commit | 7f90f5ecd4d977a48b6239fa9fb78a50f52187b0 (patch) | |
tree | 7a0461d8164610c9a71155ab9d4e29a1fdfbbdd5 /packages/contracts/test/utils | |
parent | 12f02b98143513d8309a9df7d4dcab46d60352da (diff) | |
parent | 56a4a374cde67e0e5c0c748ed6bee9bb2a084bd9 (diff) | |
download | dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.gz dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.bz2 dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.lz dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.xz dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.tar.zst dexon-sol-tools-7f90f5ecd4d977a48b6239fa9fb78a50f52187b0.zip |
merge v2-prototype
Diffstat (limited to 'packages/contracts/test/utils')
-rw-r--r-- | packages/contracts/test/utils/block_timestamp.ts (renamed from packages/contracts/test/utils/increase_time.ts) | 9 | ||||
-rw-r--r-- | packages/contracts/test/utils/exchange_wrapper.ts | 4 | ||||
-rw-r--r-- | packages/contracts/test/utils/order_factory.ts | 11 |
3 files changed, 19 insertions, 5 deletions
diff --git a/packages/contracts/test/utils/increase_time.ts b/packages/contracts/test/utils/block_timestamp.ts index 4565d8dbc..1159792c4 100644 --- a/packages/contracts/test/utils/increase_time.ts +++ b/packages/contracts/test/utils/block_timestamp.ts @@ -29,3 +29,12 @@ export async function increaseTimeAndMineBlockAsync(seconds: number): Promise<nu return offset; } + +/** + * Returns the timestamp of the latest block in seconds since the Unix epoch. + * @returns a new Promise which will resolve with the timestamp in seconds. + */ +export async function getLatestBlockTimestampAsync(): Promise<number> { + const currentBlock = await web3Wrapper.getBlockAsync('latest'); + return currentBlock.timestamp; +} diff --git a/packages/contracts/test/utils/exchange_wrapper.ts b/packages/contracts/test/utils/exchange_wrapper.ts index 155d0eeb0..a71a0d495 100644 --- a/packages/contracts/test/utils/exchange_wrapper.ts +++ b/packages/contracts/test/utils/exchange_wrapper.ts @@ -223,6 +223,10 @@ export class ExchangeWrapper { const orderInfo = (await this._exchange.getOrderInfo.callAsync(signedOrder)) as OrderInfo; return orderInfo; } + public async getOrdersInfoAsync(signedOrders: SignedOrder[]): Promise<OrderInfo[]> { + const ordersInfo = (await this._exchange.getOrdersInfo.callAsync(signedOrders)) as OrderInfo[]; + return ordersInfo; + } public async matchOrdersAsync( signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder, diff --git a/packages/contracts/test/utils/order_factory.ts b/packages/contracts/test/utils/order_factory.ts index 009dbc396..c81aff269 100644 --- a/packages/contracts/test/utils/order_factory.ts +++ b/packages/contracts/test/utils/order_factory.ts @@ -2,6 +2,7 @@ import { generatePseudoRandomSalt, orderHashUtils } from '@0xproject/order-utils import { Order, SignatureType, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; +import { getLatestBlockTimestampAsync } from './block_timestamp'; import { constants } from './constants'; import { signingUtils } from './signing_utils'; @@ -12,15 +13,15 @@ export class OrderFactory { this._defaultOrderParams = defaultOrderParams; this._privateKey = privateKey; } - public newSignedOrder( + public async newSignedOrderAsync( customOrderParams: Partial<Order> = {}, signatureType: SignatureType = SignatureType.EthSign, - ): SignedOrder { - const tenMinutes = 10 * 60 * 1000; - const randomExpiration = new BigNumber(Date.now() + tenMinutes); + ): Promise<SignedOrder> { + const tenMinutesInSeconds = 10 * 60; + const currentBlockTimestamp = await getLatestBlockTimestampAsync(); const order = ({ senderAddress: constants.NULL_ADDRESS, - expirationTimeSeconds: randomExpiration, + expirationTimeSeconds: new BigNumber(currentBlockTimestamp).add(tenMinutesInSeconds), salt: generatePseudoRandomSalt(), takerAddress: constants.NULL_ADDRESS, ...this._defaultOrderParams, |