diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-07-17 09:28:47 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-07-17 09:41:37 +0800 |
commit | 9828fa335ea0e52da96c7339854970df33027d65 (patch) | |
tree | d837f0b642d7167acd6a702660f51fe44147e96a /packages/contracts/test/utils | |
parent | 01789e67509a2d87d9056f6b9ef9ff48eee88cdd (diff) | |
download | dexon-sol-tools-9828fa335ea0e52da96c7339854970df33027d65.tar dexon-sol-tools-9828fa335ea0e52da96c7339854970df33027d65.tar.gz dexon-sol-tools-9828fa335ea0e52da96c7339854970df33027d65.tar.bz2 dexon-sol-tools-9828fa335ea0e52da96c7339854970df33027d65.tar.lz dexon-sol-tools-9828fa335ea0e52da96c7339854970df33027d65.tar.xz dexon-sol-tools-9828fa335ea0e52da96c7339854970df33027d65.tar.zst dexon-sol-tools-9828fa335ea0e52da96c7339854970df33027d65.zip |
Fix bugs having to do with block timestamps and order expirationTimes
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, |