aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-05-16 20:59:10 +0800
committerFabio Berger <me@fabioberger.com>2018-05-16 20:59:10 +0800
commit839db68571037f6fff8273aaade6ea0bd14ea8a5 (patch)
tree302b3164f01bc5363bf07841a42fa30b3842169e /packages/order-watcher
parentfec6ac3ff0c4781cea0b3f42e287aee2b8aa2a79 (diff)
downloaddexon-sol-tools-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar
dexon-sol-tools-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar.gz
dexon-sol-tools-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar.bz2
dexon-sol-tools-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar.lz
dexon-sol-tools-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar.xz
dexon-sol-tools-839db68571037f6fff8273aaade6ea0bd14ea8a5.tar.zst
dexon-sol-tools-839db68571037f6fff8273aaade6ea0bd14ea8a5.zip
Fix TSLint rules
Diffstat (limited to 'packages/order-watcher')
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts4
-rw-r--r--packages/order-watcher/src/utils/utils.ts3
-rw-r--r--packages/order-watcher/test/expiration_watcher_test.ts33
-rw-r--r--packages/order-watcher/test/global_hooks.ts3
-rw-r--r--packages/order-watcher/test/order_watcher_test.ts4
5 files changed, 32 insertions, 15 deletions
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index 3c93d6293..29936a066 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -60,6 +60,7 @@ interface OrderStateByOrderHash {
[orderHash: string]: OrderState;
}
+// tslint:disable-next-line:custom-no-magic-numbers
const DEFAULT_CLEANUP_JOB_INTERVAL_MS = 1000 * 60 * 60; // 1h
/**
@@ -130,7 +131,8 @@ export class OrderWatcher {
assert.isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker);
this._orderByOrderHash[orderHash] = signedOrder;
this._addToDependentOrderHashes(signedOrder, orderHash);
- const expirationUnixTimestampMs = signedOrder.expirationUnixTimestampSec.times(1000);
+ const milisecondsInASecond = 1000;
+ const expirationUnixTimestampMs = signedOrder.expirationUnixTimestampSec.times(milisecondsInASecond);
this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs);
}
/**
diff --git a/packages/order-watcher/src/utils/utils.ts b/packages/order-watcher/src/utils/utils.ts
index af1125632..d34f6b99f 100644
--- a/packages/order-watcher/src/utils/utils.ts
+++ b/packages/order-watcher/src/utils/utils.ts
@@ -5,7 +5,8 @@ export const utils = {
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
},
getCurrentUnixTimestampSec(): BigNumber {
- return new BigNumber(Date.now() / 1000).round();
+ const milisecondsInASecond = 1000;
+ return new BigNumber(Date.now() / milisecondsInASecond).round();
},
getCurrentUnixTimestampMs(): BigNumber {
return new BigNumber(Date.now());
diff --git a/packages/order-watcher/test/expiration_watcher_test.ts b/packages/order-watcher/test/expiration_watcher_test.ts
index 0a2524d78..5672748a1 100644
--- a/packages/order-watcher/test/expiration_watcher_test.ts
+++ b/packages/order-watcher/test/expiration_watcher_test.ts
@@ -21,6 +21,7 @@ import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+const MILISECONDS_IN_SECOND = 1000;
describe('ExpirationWatcher', () => {
let contractWrappers: ContractWrappers;
@@ -83,13 +84,13 @@ describe('ExpirationWatcher', () => {
expirationUnixTimestampSec,
);
const orderHash = getOrderHashHex(signedOrder);
- expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(1000));
+ expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(MILISECONDS_IN_SECOND));
const callbackAsync = callbackErrorReporter.reportNoErrorCallbackErrors(done)((hash: string) => {
expect(hash).to.be.equal(orderHash);
expect(utils.getCurrentUnixTimestampSec()).to.be.bignumber.gte(expirationUnixTimestampSec);
});
expirationWatcher.subscribe(callbackAsync);
- timer.tick(orderLifetimeSec * 1000);
+ timer.tick(orderLifetimeSec * MILISECONDS_IN_SECOND);
})().catch(done);
});
it("doesn't emit events before order expires", (done: DoneCallback) => {
@@ -105,13 +106,13 @@ describe('ExpirationWatcher', () => {
expirationUnixTimestampSec,
);
const orderHash = getOrderHashHex(signedOrder);
- expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(1000));
+ expirationWatcher.addOrder(orderHash, signedOrder.expirationUnixTimestampSec.times(MILISECONDS_IN_SECOND));
const callbackAsync = callbackErrorReporter.reportNoErrorCallbackErrors(done)(async (hash: string) => {
done(new Error('Emitted expiration went before the order actually expired'));
});
expirationWatcher.subscribe(callbackAsync);
const notEnoughTime = orderLifetimeSec - 1;
- timer.tick(notEnoughTime * 1000);
+ timer.tick(notEnoughTime * MILISECONDS_IN_SECOND);
done();
})().catch(done);
});
@@ -139,8 +140,14 @@ describe('ExpirationWatcher', () => {
);
const orderHash1 = getOrderHashHex(signedOrder1);
const orderHash2 = getOrderHashHex(signedOrder2);
- expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec.times(1000));
- expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec.times(1000));
+ expirationWatcher.addOrder(
+ orderHash2,
+ signedOrder2.expirationUnixTimestampSec.times(MILISECONDS_IN_SECOND),
+ );
+ expirationWatcher.addOrder(
+ orderHash1,
+ signedOrder1.expirationUnixTimestampSec.times(MILISECONDS_IN_SECOND),
+ );
const expirationOrder = [orderHash1, orderHash2];
const expectToBeCalledOnce = false;
const callbackAsync = callbackErrorReporter.reportNoErrorCallbackErrors(done, expectToBeCalledOnce)(
@@ -153,7 +160,7 @@ describe('ExpirationWatcher', () => {
},
);
expirationWatcher.subscribe(callbackAsync);
- timer.tick(order2Lifetime * 1000);
+ timer.tick(order2Lifetime * MILISECONDS_IN_SECOND);
})().catch(done);
});
it('emits events in correct order when expirations are equal', (done: DoneCallback) => {
@@ -180,8 +187,14 @@ describe('ExpirationWatcher', () => {
);
const orderHash1 = getOrderHashHex(signedOrder1);
const orderHash2 = getOrderHashHex(signedOrder2);
- expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec.times(1000));
- expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec.times(1000));
+ expirationWatcher.addOrder(
+ orderHash1,
+ signedOrder1.expirationUnixTimestampSec.times(MILISECONDS_IN_SECOND),
+ );
+ expirationWatcher.addOrder(
+ orderHash2,
+ signedOrder2.expirationUnixTimestampSec.times(MILISECONDS_IN_SECOND),
+ );
const expirationOrder = orderHash1 < orderHash2 ? [orderHash1, orderHash2] : [orderHash2, orderHash1];
const expectToBeCalledOnce = false;
const callbackAsync = callbackErrorReporter.reportNoErrorCallbackErrors(done, expectToBeCalledOnce)(
@@ -194,7 +207,7 @@ describe('ExpirationWatcher', () => {
},
);
expirationWatcher.subscribe(callbackAsync);
- timer.tick(order2Lifetime * 1000);
+ timer.tick(order2Lifetime * MILISECONDS_IN_SECOND);
})().catch(done);
});
});
diff --git a/packages/order-watcher/test/global_hooks.ts b/packages/order-watcher/test/global_hooks.ts
index 53b3ef545..fa1dfae38 100644
--- a/packages/order-watcher/test/global_hooks.ts
+++ b/packages/order-watcher/test/global_hooks.ts
@@ -8,7 +8,8 @@ import { provider } from './utils/web3_wrapper';
before('migrate contracts', async function(): Promise<void> {
// HACK: Since the migrations take longer then our global mocha timeout limit
// we manually increase it for this before hook.
- this.timeout(20000);
+ const mochaTestTimeoutMs = 20000;
+ this.timeout(mochaTestTimeoutMs);
const txDefaults = {
gas: devConstants.GAS_ESTIMATE,
from: devConstants.TESTRPC_FIRST_ADDRESS,
diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts
index 8c9249f58..991518269 100644
--- a/packages/order-watcher/test/order_watcher_test.ts
+++ b/packages/order-watcher/test/order_watcher_test.ts
@@ -268,8 +268,8 @@ describe('OrderWatcher', () => {
});
it('should trigger the callback when orders backing ZRX allowance changes', (done: DoneCallback) => {
(async () => {
- const makerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18);
- const takerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(0), 18);
+ const makerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(2), decimals);
+ const takerFee = Web3Wrapper.toBaseUnitAmount(new BigNumber(0), decimals);
signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
makerToken.address,
takerToken.address,