aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/src/utils/order_validation_utils.ts4
-rw-r--r--packages/0x.js/test/expiration_watcher_test.ts19
-rw-r--r--packages/0x.js/test/utils/report_callback_errors.ts6
3 files changed, 14 insertions, 15 deletions
diff --git a/packages/0x.js/src/utils/order_validation_utils.ts b/packages/0x.js/src/utils/order_validation_utils.ts
index f03703c4e..ed723e3d4 100644
--- a/packages/0x.js/src/utils/order_validation_utils.ts
+++ b/packages/0x.js/src/utils/order_validation_utils.ts
@@ -102,7 +102,7 @@ export class OrderValidationUtils {
if (order.takerTokenAmount.eq(unavailableTakerTokenAmount)) {
throw new Error(ExchangeContractErrs.OrderAlreadyCancelledOrFilled);
}
- const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
+ const currentUnixTimestampSec = utils.getCurrentUnixTimestampSec();
if (order.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
throw new Error(ExchangeContractErrs.OrderCancelExpired);
}
@@ -150,7 +150,7 @@ export class OrderValidationUtils {
}
}
private validateOrderNotExpiredOrThrow(expirationUnixTimestampSec: BigNumber) {
- const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
+ const currentUnixTimestampSec = utils.getCurrentUnixTimestampSec();
if (expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
throw new Error(ExchangeContractErrs.OrderFillExpired);
}
diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts
index 31e01dba6..a384658e7 100644
--- a/packages/0x.js/test/expiration_watcher_test.ts
+++ b/packages/0x.js/test/expiration_watcher_test.ts
@@ -10,10 +10,9 @@ import {utils} from '../src/utils/utils';
import {Web3Wrapper} from '../src/web3_wrapper';
import {TokenUtils} from './utils/token_utils';
import {ExpirationWatcher} from '../src/order_watcher/expiration_watcher';
-import {Token} from '../src/types';
+import {Token, DoneCallback} from '../src/types';
import {ZeroEx} from '../src';
import {FillScenarios} from './utils/fill_scenarios';
-import {DoneCallback} from '../src/types';
import {reportCallbackErrors} from './utils/report_callback_errors';
chaiSetup.configure();
@@ -57,7 +56,7 @@ describe('ExpirationWatcher', () => {
const sinonTimerConfig = {shouldAdvanceTime: true} as any;
// This constructor has incorrect types
timer = Sinon.useFakeTimers(sinonTimerConfig);
- currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
+ currentUnixTimestampSec = utils.getCurrentUnixTimestampSec();
expirationWatcher = new ExpirationWatcher();
});
afterEach(() => {
@@ -74,12 +73,12 @@ describe('ExpirationWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec);
- const callback = reportCallbackErrors(done)((hash: string) => {
+ const callbackAsync = reportCallbackErrors(done)(async (hash: string) => {
expect(hash).to.be.equal(orderHash);
- expect(utils.getCurrentUnixTimestamp()).to.be.bignumber.above(expirationUnixTimestampSec);
+ expect(utils.getCurrentUnixTimestampSec()).to.be.bignumber.above(expirationUnixTimestampSec);
done();
});
- expirationWatcher.subscribe(callback);
+ expirationWatcher.subscribe(callbackAsync);
timer.tick(orderLifetimeS * 1000);
})().catch(done);
});
@@ -93,10 +92,10 @@ describe('ExpirationWatcher', () => {
);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec);
- const callback = reportCallbackErrors(done)((hash: string) => {
+ const callbackAsync = reportCallbackErrors(done)(async (hash: string) => {
done(new Error('Emitted expiration went before the order actually expired'));
});
- expirationWatcher.subscribe(callback);
+ expirationWatcher.subscribe(callbackAsync);
const notEnoughTime = orderLifetimeS - 1;
timer.tick(notEnoughTime * 1000);
done();
@@ -121,14 +120,14 @@ describe('ExpirationWatcher', () => {
expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec);
expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec);
const expirationOrder = [orderHash1, orderHash2];
- const callback = reportCallbackErrors(done)((hash: string) => {
+ const callbackAsync = reportCallbackErrors(done)(async (hash: string) => {
const orderHash = expirationOrder.shift();
expect(hash).to.be.equal(orderHash);
if (_.isEmpty(expirationOrder)) {
done();
}
});
- expirationWatcher.subscribe(callback);
+ expirationWatcher.subscribe(callbackAsync);
timer.tick(order2Lifetime * 1000);
})().catch(done);
});
diff --git a/packages/0x.js/test/utils/report_callback_errors.ts b/packages/0x.js/test/utils/report_callback_errors.ts
index d471b2af2..4f9517704 100644
--- a/packages/0x.js/test/utils/report_callback_errors.ts
+++ b/packages/0x.js/test/utils/report_callback_errors.ts
@@ -1,10 +1,10 @@
import { DoneCallback } from '../../src/types';
export const reportCallbackErrors = (done: DoneCallback) => {
- return (f: (...args: any[]) => void) => {
- const wrapped = (...args: any[]) => {
+ return (fAsync: (...args: any[]) => void|Promise<void>) => {
+ const wrapped = async (...args: any[]) => {
try {
- f(...args);
+ await fAsync(...args);
} catch (err) {
done(err);
}