aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-21 06:39:34 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-21 06:39:34 +0800
commit3e0371685fe16b7dc96f5f900c0d4531b16370d4 (patch)
tree4f8bb59af73309efd9676aeb680ee09bac8fb157 /packages/0x.js/test
parent3bc3666215d4fdaa6d9db87e065ca5e762df9b25 (diff)
downloaddexon-sol-tools-3e0371685fe16b7dc96f5f900c0d4531b16370d4.tar
dexon-sol-tools-3e0371685fe16b7dc96f5f900c0d4531b16370d4.tar.gz
dexon-sol-tools-3e0371685fe16b7dc96f5f900c0d4531b16370d4.tar.bz2
dexon-sol-tools-3e0371685fe16b7dc96f5f900c0d4531b16370d4.tar.lz
dexon-sol-tools-3e0371685fe16b7dc96f5f900c0d4531b16370d4.tar.xz
dexon-sol-tools-3e0371685fe16b7dc96f5f900c0d4531b16370d4.tar.zst
dexon-sol-tools-3e0371685fe16b7dc96f5f900c0d4531b16370d4.zip
Fix async callbacks
Diffstat (limited to 'packages/0x.js/test')
-rw-r--r--packages/0x.js/test/expiration_watcher_test.ts19
-rw-r--r--packages/0x.js/test/utils/report_callback_errors.ts6
2 files changed, 12 insertions, 13 deletions
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);
}