diff options
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/order_factory.ts | 11 |
2 files changed, 15 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/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, |