diff options
author | Kadinsky <kandinsky454@protonmail.ch> | 2018-10-15 19:25:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-15 19:25:24 +0800 |
commit | 79db7147a4f9664372516fb391f69f2d9e1c0b8c (patch) | |
tree | b3306cd8f798906d7577f7900ed602105dcf2d45 | |
parent | 23fb8dab132c0228c90ae1a9ceb8fce56fade139 (diff) | |
parent | 69e9dbd68323439ac817e71c610dfae3716bee26 (diff) | |
download | dexon-sol-tools-79db7147a4f9664372516fb391f69f2d9e1c0b8c.tar dexon-sol-tools-79db7147a4f9664372516fb391f69f2d9e1c0b8c.tar.gz dexon-sol-tools-79db7147a4f9664372516fb391f69f2d9e1c0b8c.tar.bz2 dexon-sol-tools-79db7147a4f9664372516fb391f69f2d9e1c0b8c.tar.lz dexon-sol-tools-79db7147a4f9664372516fb391f69f2d9e1c0b8c.tar.xz dexon-sol-tools-79db7147a4f9664372516fb391f69f2d9e1c0b8c.tar.zst dexon-sol-tools-79db7147a4f9664372516fb391f69f2d9e1c0b8c.zip |
Merge pull request #1118 from BEcorp/development
[order-watcher] Public function getStats
-rw-r--r-- | packages/order-watcher/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/order-watcher/src/index.ts | 1 | ||||
-rw-r--r-- | packages/order-watcher/src/order_watcher/order_watcher.ts | 10 | ||||
-rw-r--r-- | packages/order-watcher/test/order_watcher_test.ts | 17 | ||||
-rw-r--r-- | packages/types/src/index.ts | 4 |
5 files changed, 40 insertions, 1 deletions
diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index ce56e492c..feebb9d69 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "2.1.2", + "changes": [ + { + "note": "Added getStats function and returns a Stats object", + "pr": 1118 + } + ] + }, + { "version": "2.1.1", "changes": [ { diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts index d2f91eab1..8280c73a4 100644 --- a/packages/order-watcher/src/index.ts +++ b/packages/order-watcher/src/index.ts @@ -7,6 +7,7 @@ export { OrderState, ExchangeContractErrs, OrderRelevantState, + Stats, } from '@0xproject/types'; export { OnOrderStateChangeCallback, OrderWatcherConfig } from './types'; diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index f9a63efe3..eb37bd617 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -30,7 +30,7 @@ import { orderHashUtils, OrderStateUtils, } from '@0xproject/order-utils'; -import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder } from '@0xproject/types'; +import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0xproject/types'; import { errorUtils, intervalUtils } from '@0xproject/utils'; import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types'; import * as _ from 'lodash'; @@ -213,6 +213,14 @@ export class OrderWatcher { this._expirationWatcher.unsubscribe(); intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } + /** + * Gets statistics of the OrderWatcher Instance. + */ + public getStats(): Stats { + return { + orderCount: _.size(this._orderByOrderHash), + }; + } private async _cleanupAsync(): Promise<void> { for (const orderHash of _.keys(this._orderByOrderHash)) { this._cleanupOrderRelatedState(orderHash); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index 60d9069e8..4545f84bf 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -140,6 +140,23 @@ describe('OrderWatcher', () => { expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent); }); }); + describe('#getStats', async () => { + it('orderCount should increment and decrement with order additions and removals', async () => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + takerAddress, + fillableAmount, + ); + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); + await orderWatcher.addOrderAsync(signedOrder); + expect(orderWatcher.getStats().orderCount).to.be.eq(1); + orderWatcher.removeOrder(orderHash); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); + }); + }); describe('tests with cleanup', async () => { afterEach(async () => { orderWatcher.unsubscribe(); diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 6bc966ba1..d33048b61 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -620,3 +620,7 @@ export interface EIP712TypedData { message: EIP712Object; primaryType: string; } + +export interface Stats { + orderCount: number; +} |