From bd3f101ab8735f97646d1031126fb9e55b67a93d Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:06:34 -0400 Subject: Added orderWatchCount to return total count of orders watched. --- .../order-watcher/src/order_watcher/order_watcher.ts | 3 +++ packages/order-watcher/test/order_watcher_test.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index f9a63efe3..9b2999285 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -213,6 +213,9 @@ export class OrderWatcher { this._expirationWatcher.unsubscribe(); intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } + public getWatchCount(): number { + return _.size(this._orderByOrderHash); + } private async _cleanupAsync(): Promise { 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..f504dda8e 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('#getWatchCount', async () => { + it('should increment and decrement order counts', async() => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + takerAddress, + fillableAmount, + ); + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); + expect(orderWatcher.getWatchCount()).to.be.eq(0); + await orderWatcher.addOrderAsync(signedOrder); + expect(orderWatcher.getWatchCount()).to.be.eq(1); + orderWatcher.removeOrder(orderHash); + expect(orderWatcher.getWatchCount()).to.be.eq(0); + }); + }); describe('tests with cleanup', async () => { afterEach(async () => { orderWatcher.unsubscribe(); -- cgit v1.2.3 From c833b4f49448dacade229f9af4530020dc30a57a Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:23:16 -0400 Subject: Added comments to new getWatchCounts function --- packages/order-watcher/src/order_watcher/order_watcher.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 9b2999285..ac811a4c4 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -213,6 +213,10 @@ export class OrderWatcher { this._expirationWatcher.unsubscribe(); intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } + /** + * Gets number of orderHashes currently being watched by the order watcher instance. + * @returns {number} + */ public getWatchCount(): number { return _.size(this._orderByOrderHash); } -- cgit v1.2.3 From ee0f2e46ee0b7c62225e09b54a3e13607214ae20 Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:32:07 -0400 Subject: Update order-watcher changelog --- packages/order-watcher/CHANGELOG.json | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index ce56e492c..6d1256d9e 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "2.1.2", + "changes": [ + { + "note": "Added getWatchCounts function" + } + ], + "timestamp": 1538836030 + }, { "version": "2.1.1", "changes": [ -- cgit v1.2.3 From d0fed1ae464301cb26df16053991e667598b640e Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 10:43:36 -0400 Subject: Fixed linting issue --- packages/order-watcher/src/order_watcher/order_watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index ac811a4c4..5ddfdd047 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -215,7 +215,7 @@ export class OrderWatcher { } /** * Gets number of orderHashes currently being watched by the order watcher instance. - * @returns {number} + * @returns {number} Number of hashes in _orderByOrderHash */ public getWatchCount(): number { return _.size(this._orderByOrderHash); -- cgit v1.2.3 From 9171f9ec600b04134e0f86741e60a973618839b5 Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 6 Oct 2018 11:04:48 -0400 Subject: Fix lint issues --- packages/order-watcher/src/order_watcher/order_watcher.ts | 1 - packages/order-watcher/test/order_watcher_test.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 5ddfdd047..e59b56b90 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -215,7 +215,6 @@ export class OrderWatcher { } /** * Gets number of orderHashes currently being watched by the order watcher instance. - * @returns {number} Number of hashes in _orderByOrderHash */ public getWatchCount(): number { return _.size(this._orderByOrderHash); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index f504dda8e..f1dbe9b2f 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -141,7 +141,7 @@ describe('OrderWatcher', () => { }); }); describe('#getWatchCount', async () => { - it('should increment and decrement order counts', async() => { + it('should increment and decrement order counts', async () => { signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerAssetData, takerAssetData, -- cgit v1.2.3 From 2e1222556ff8bd3923a5e91174f7d6bd92d6a02c Mon Sep 17 00:00:00 2001 From: amaurer Date: Sun, 7 Oct 2018 12:24:42 -0400 Subject: Changed getWatchedOrders to getStats and returns Stats object --- packages/order-watcher/CHANGELOG.json | 2 +- packages/order-watcher/src/order_watcher/order_watcher.ts | 12 +++++++++--- packages/order-watcher/test/order_watcher_test.ts | 10 +++++----- 3 files changed, 15 insertions(+), 9 deletions(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 6d1256d9e..7b8416428 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -3,7 +3,7 @@ "version": "2.1.2", "changes": [ { - "note": "Added getWatchCounts function" + "note": "Added getStats function and returns a Stats object" } ], "timestamp": 1538836030 diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index e59b56b90..4401b3f7e 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -57,6 +57,10 @@ interface OrderStateByOrderHash { [orderHash: string]: OrderState; } +export interface Stats { + orderCount: number; +} + const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = { orderExpirationCheckingIntervalMs: 50, eventPollingIntervalMs: 200, @@ -214,10 +218,12 @@ export class OrderWatcher { intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists); } /** - * Gets number of orderHashes currently being watched by the order watcher instance. + * Gets statistics of the OrderWatcher Instance. */ - public getWatchCount(): number { - return _.size(this._orderByOrderHash); + public getStats(): Stats { + return { + orderCount : _.size(this._orderByOrderHash), + }; } private async _cleanupAsync(): Promise { for (const orderHash of _.keys(this._orderByOrderHash)) { diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index f1dbe9b2f..4545f84bf 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -140,8 +140,8 @@ describe('OrderWatcher', () => { expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent); }); }); - describe('#getWatchCount', async () => { - it('should increment and decrement order counts', async () => { + describe('#getStats', async () => { + it('orderCount should increment and decrement with order additions and removals', async () => { signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerAssetData, takerAssetData, @@ -150,11 +150,11 @@ describe('OrderWatcher', () => { fillableAmount, ); const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - expect(orderWatcher.getWatchCount()).to.be.eq(0); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); await orderWatcher.addOrderAsync(signedOrder); - expect(orderWatcher.getWatchCount()).to.be.eq(1); + expect(orderWatcher.getStats().orderCount).to.be.eq(1); orderWatcher.removeOrder(orderHash); - expect(orderWatcher.getWatchCount()).to.be.eq(0); + expect(orderWatcher.getStats().orderCount).to.be.eq(0); }); }); describe('tests with cleanup', async () => { -- cgit v1.2.3 From cd04a21e29cc5713c1932b754d9a8f5c5172f960 Mon Sep 17 00:00:00 2001 From: amaurer Date: Fri, 12 Oct 2018 11:55:31 -0400 Subject: Fixes per converstaion, stats interface to pub --- packages/order-watcher/CHANGELOG.json | 6 +++--- packages/order-watcher/src/order_watcher/order_watcher.ts | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index 7b8416428..feebb9d69 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -3,10 +3,10 @@ "version": "2.1.2", "changes": [ { - "note": "Added getStats function and returns a Stats object" + "note": "Added getStats function and returns a Stats object", + "pr": 1118 } - ], - "timestamp": 1538836030 + ] }, { "version": "2.1.1", diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 4401b3f7e..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'; @@ -57,10 +57,6 @@ interface OrderStateByOrderHash { [orderHash: string]: OrderState; } -export interface Stats { - orderCount: number; -} - const DEFAULT_ORDER_WATCHER_CONFIG: OrderWatcherConfig = { orderExpirationCheckingIntervalMs: 50, eventPollingIntervalMs: 200, @@ -222,7 +218,7 @@ export class OrderWatcher { */ public getStats(): Stats { return { - orderCount : _.size(this._orderByOrderHash), + orderCount: _.size(this._orderByOrderHash), }; } private async _cleanupAsync(): Promise { -- cgit v1.2.3 From dc56ce454967d2bf0d5e8c93389c0fa71a9d1cc5 Mon Sep 17 00:00:00 2001 From: amaurer Date: Sat, 13 Oct 2018 08:47:37 -0400 Subject: Exported Stats in OW package --- packages/order-watcher/src/index.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts index d7ad4fba7..4a1b5012b 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'; -- cgit v1.2.3 From 29063cab186196dc7051ca16ca9409e8619c6673 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Thu, 4 Oct 2018 16:33:10 -0700 Subject: update order-watcher to use new artifacts and abi-gen wrappers packages --- packages/order-watcher/package.json | 20 ++++--------- packages/order-watcher/src/artifacts.ts | 13 --------- packages/order-watcher/src/globals.d.ts | 6 ---- .../src/order_watcher/order_watcher.ts | 20 ++++++++++--- .../order-watcher/test/expiration_watcher_test.ts | 19 ++++-------- packages/order-watcher/test/global_hooks.ts | 5 ++-- packages/order-watcher/test/order_watcher_test.ts | 24 ++++++++------- packages/order-watcher/test/utils/token_utils.ts | 34 ---------------------- 8 files changed, 43 insertions(+), 98 deletions(-) delete mode 100644 packages/order-watcher/src/artifacts.ts delete mode 100644 packages/order-watcher/src/globals.d.ts delete mode 100644 packages/order-watcher/test/utils/token_utils.ts (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json index 9bdaef5b1..ca352b754 100644 --- a/packages/order-watcher/package.json +++ b/packages/order-watcher/package.json @@ -12,28 +12,18 @@ "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { - "build": "yarn pre_build && tsc -b", + "build": "yarn tsc -b", "build:ci": "yarn build", - "pre_build": "run-s update_artifacts copy_artifacts generate_contract_wrappers", - "lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/*", - "generate_contract_wrappers": "abi-gen --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers", + "lint": "tslint --project .", "test:circleci": "run-s test:coverage", "test": "yarn run_mocha", "rebuild_and_test": "run-s build test", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", - "copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts", - "update_artifacts": "for i in ${npm_package_config_contracts_v2}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-trimmed/$i.json src/artifacts; done;", - "clean": "shx rm -rf _bundles lib test_temp test/artifacts src/generated_contract_wrappers generated_docs", + "clean": "shx rm -rf _bundles lib test_temp generated_docs", "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES" }, - "config": { - "contracts_v2": "AssetProxyOwner ERC20Proxy ERC20Token ERC721Proxy ERC721Token Exchange Forwarder OrderValidator WETH9 ZRXToken", - "postpublish": { - "assets": [] - } - }, "repository": { "type": "git", "url": "https://github.com/0xProject/0x-monorepo" @@ -43,7 +33,6 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/abi-gen": "^1.0.13", "@0xproject/dev-utils": "^1.0.12", "@0xproject/migrations": "^1.0.14", "@0xproject/tslint-config": "^1.0.8", @@ -55,7 +44,6 @@ "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^2.0.1", - "copyfiles": "^2.0.0", "dirty-chai": "^2.0.1", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", @@ -69,8 +57,10 @@ "typescript": "3.0.1" }, "dependencies": { + "@0xproject/abi-gen-wrappers": "^1.0.0", "@0xproject/assert": "^1.0.13", "@0xproject/base-contract": "^3.0.1", + "@0xproject/contract-artifacts": "^1.0.0", "@0xproject/contract-wrappers": "^2.0.2", "@0xproject/fill-scenarios": "^1.0.7", "@0xproject/json-schemas": "^1.0.7", diff --git a/packages/order-watcher/src/artifacts.ts b/packages/order-watcher/src/artifacts.ts deleted file mode 100644 index 520066a24..000000000 --- a/packages/order-watcher/src/artifacts.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ContractArtifact } from 'ethereum-types'; - -import * as ERC20Token from './artifacts/ERC20Token.json'; -import * as ERC721Token from './artifacts/ERC721Token.json'; -import * as Exchange from './artifacts/Exchange.json'; -import * as WETH9 from './artifacts/WETH9.json'; - -export const artifacts = { - ERC20Token: (ERC20Token as any) as ContractArtifact, - ERC721Token: (ERC721Token as any) as ContractArtifact, - Exchange: (Exchange as any) as ContractArtifact, - EtherToken: (WETH9 as any) as ContractArtifact, -}; diff --git a/packages/order-watcher/src/globals.d.ts b/packages/order-watcher/src/globals.d.ts deleted file mode 100644 index 94e63a32d..000000000 --- a/packages/order-watcher/src/globals.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module '*.json' { - const json: any; - /* tslint:disable */ - export default json; - /* tslint:enable */ -} diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index eb37bd617..8afed3924 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -1,4 +1,5 @@ // tslint:disable:no-unnecessary-type-assertion +import * as artifacts from '@0xproject/contract-artifacts'; import { AssetBalanceAndProxyAllowanceFetcher, ContractWrappers, @@ -30,12 +31,18 @@ import { orderHashUtils, OrderStateUtils, } from '@0xproject/order-utils'; -import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0xproject/types'; +import { + AssetProxyId, + ContractAddresses, + 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'; -import { artifacts } from '../artifacts'; import { orderWatcherPartialConfigSchema } from '../schemas/order_watcher_partial_config_schema'; import { OnOrderStateChangeCallback, OrderWatcherConfig, OrderWatcherError } from '../types'; import { assert } from '../utils/assert'; @@ -96,6 +103,7 @@ export class OrderWatcher { constructor( provider: Provider, networkId: number, + contractAddresses: ContractAddresses, partialConfig: Partial = DEFAULT_ORDER_WATCHER_CONFIG, ) { assert.isWeb3Provider('provider', provider); @@ -110,9 +118,13 @@ export class OrderWatcher { this._collisionResistantAbiDecoder = new CollisionResistanceAbiDecoder( artifacts.ERC20Token.compilerOutput.abi, artifacts.ERC721Token.compilerOutput.abi, - [artifacts.EtherToken.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi], + [artifacts.WETH9.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi], ); - const contractWrappers = new ContractWrappers(provider, { networkId }); + const contractWrappers = new ContractWrappers(provider, { + networkId, + // TODO(albrow): Make contract addresses optional. + contractAddresses, + }); this._eventWatcher = new EventWatcher(provider, config.eventPollingIntervalMs, STATE_LAYER, config.isVerbose); const balanceAndProxyAllowanceFetcher = new AssetBalanceAndProxyAllowanceFetcher( contractWrappers.erc20Token, diff --git a/packages/order-watcher/test/expiration_watcher_test.ts b/packages/order-watcher/test/expiration_watcher_test.ts index ea9923487..056e53988 100644 --- a/packages/order-watcher/test/expiration_watcher_test.ts +++ b/packages/order-watcher/test/expiration_watcher_test.ts @@ -1,7 +1,7 @@ -import { ContractWrappers } from '@0xproject/contract-wrappers'; import { tokenUtils } from '@0xproject/contract-wrappers/lib/test/utils/token_utils'; import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils'; import { FillScenarios } from '@0xproject/fill-scenarios'; +import { getContractAddresses } from '@0xproject/migrations'; import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils'; import { DoneCallback } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; @@ -14,7 +14,6 @@ import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher'; import { utils } from '../src/utils/utils'; import { chaiSetup } from './utils/chai_setup'; -import { constants } from './utils/constants'; import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); @@ -23,14 +22,8 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const MILISECONDS_IN_SECOND = 1000; describe('ExpirationWatcher', () => { - const config = { - networkId: constants.TESTRPC_NETWORK_ID, - }; - const contractWrappers = new ContractWrappers(provider, config); let userAddresses: string[]; - let zrxTokenAddress: string; let fillScenarios: FillScenarios; - const exchangeContractAddress = contractWrappers.exchange.getContractAddress(); let makerAssetData: string; let takerAssetData: string; let coinbase: string; @@ -43,15 +36,15 @@ describe('ExpirationWatcher', () => { let expirationWatcher: ExpirationWatcher; before(async () => { await blockchainLifecycle.startAsync(); + const contractAddresses = getContractAddresses(); userAddresses = await web3Wrapper.getAvailableAddressesAsync(); - zrxTokenAddress = tokenUtils.getProtocolTokenAddress(); fillScenarios = new FillScenarios( provider, userAddresses, - zrxTokenAddress, - exchangeContractAddress, - contractWrappers.erc20Proxy.getContractAddress(), - contractWrappers.erc721Proxy.getContractAddress(), + contractAddresses.zrxToken, + contractAddresses.exchange, + contractAddresses.erc20Proxy, + contractAddresses.erc721Proxy, ); [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; const [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); diff --git a/packages/order-watcher/test/global_hooks.ts b/packages/order-watcher/test/global_hooks.ts index 99df04a51..49340f9e1 100644 --- a/packages/order-watcher/test/global_hooks.ts +++ b/packages/order-watcher/test/global_hooks.ts @@ -1,5 +1,5 @@ import { devConstants } from '@0xproject/dev-utils'; -import { runV2MigrationsAsync } from '@0xproject/migrations'; +import { runMigrationsAsync } from '@0xproject/migrations'; import { provider } from './utils/web3_wrapper'; @@ -12,6 +12,5 @@ before('migrate contracts', async function(): Promise { gas: devConstants.GAS_LIMIT, from: devConstants.TESTRPC_FIRST_ADDRESS, }; - const artifactsDir = `src/artifacts`; - await runV2MigrationsAsync(provider, artifactsDir, txDefaults); + await runMigrationsAsync(provider, txDefaults); }); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index 4545f84bf..98a2fa089 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -3,6 +3,7 @@ import { ContractWrappers } from '@0xproject/contract-wrappers'; import { tokenUtils } from '@0xproject/contract-wrappers/lib/test/utils/token_utils'; import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils'; import { FillScenarios } from '@0xproject/fill-scenarios'; +import { getContractAddresses } from '@0xproject/migrations'; import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils'; import { DoneCallback, @@ -36,13 +37,10 @@ const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('OrderWatcher', () => { - const networkId = constants.TESTRPC_NETWORK_ID; - const config = { networkId }; - const contractWrappers = new ContractWrappers(provider, config); + let contractWrappers: ContractWrappers; let fillScenarios: FillScenarios; let userAddresses: string[]; let zrxTokenAddress: string; - let exchangeContractAddress: string; let makerAssetData: string; let takerAssetData: string; let makerTokenAddress: string; @@ -57,16 +55,22 @@ describe('OrderWatcher', () => { const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), decimals); before(async () => { await blockchainLifecycle.startAsync(); + const networkId = constants.TESTRPC_NETWORK_ID; + const contractAddresses = getContractAddresses(); + const config = { + networkId, + contractAddresses, + }; + contractWrappers = new ContractWrappers(provider, config); userAddresses = await web3Wrapper.getAvailableAddressesAsync(); - zrxTokenAddress = tokenUtils.getProtocolTokenAddress(); - exchangeContractAddress = contractWrappers.exchange.getContractAddress(); + zrxTokenAddress = contractAddresses.zrxToken; fillScenarios = new FillScenarios( provider, userAddresses, zrxTokenAddress, - exchangeContractAddress, - contractWrappers.erc20Proxy.getContractAddress(), - contractWrappers.erc721Proxy.getContractAddress(), + contractAddresses.exchange, + contractAddresses.erc20Proxy, + contractAddresses.erc721Proxy, ); [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); @@ -75,7 +79,7 @@ describe('OrderWatcher', () => { assetDataUtils.encodeERC20AssetData(takerTokenAddress), ]; const orderWatcherConfig = {}; - orderWatcher = new OrderWatcher(provider, networkId, orderWatcherConfig); + orderWatcher = new OrderWatcher(provider, networkId, contractAddresses, orderWatcherConfig); }); after(async () => { await blockchainLifecycle.revertAsync(); diff --git a/packages/order-watcher/test/utils/token_utils.ts b/packages/order-watcher/test/utils/token_utils.ts deleted file mode 100644 index f91b3797f..000000000 --- a/packages/order-watcher/test/utils/token_utils.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Token } from '@0xproject/types'; -import * as _ from 'lodash'; - -import { InternalOrderWatcherError } from '../../src/types'; - -const PROTOCOL_TOKEN_SYMBOL = 'ZRX'; -const WETH_TOKEN_SYMBOL = 'WETH'; - -export class TokenUtils { - private readonly _tokens: Token[]; - constructor(tokens: Token[]) { - this._tokens = tokens; - } - public getProtocolTokenOrThrow(): Token { - const zrxToken = _.find(this._tokens, { symbol: PROTOCOL_TOKEN_SYMBOL }); - if (_.isUndefined(zrxToken)) { - throw new Error(InternalOrderWatcherError.ZrxNotInTokenRegistry); - } - return zrxToken; - } - public getWethTokenOrThrow(): Token { - const wethToken = _.find(this._tokens, { symbol: WETH_TOKEN_SYMBOL }); - if (_.isUndefined(wethToken)) { - throw new Error(InternalOrderWatcherError.WethNotInTokenRegistry); - } - return wethToken; - } - public getDummyTokens(): Token[] { - const dummyTokens = _.filter(this._tokens, token => { - return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol); - }); - return dummyTokens; - } -} -- cgit v1.2.3 From 6c8fb370dc562b128fc24a19e3f7bbf8b5381425 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 9 Oct 2018 13:57:02 -0700 Subject: Update order-watcher to use new migrations functions --- packages/order-watcher/test/expiration_watcher_test.ts | 4 ++-- packages/order-watcher/test/global_hooks.ts | 12 +----------- packages/order-watcher/test/order_watcher_test.ts | 4 ++-- packages/order-watcher/test/utils/migrate.ts | 13 +++++++++++++ 4 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 packages/order-watcher/test/utils/migrate.ts (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/test/expiration_watcher_test.ts b/packages/order-watcher/test/expiration_watcher_test.ts index 056e53988..17be625bc 100644 --- a/packages/order-watcher/test/expiration_watcher_test.ts +++ b/packages/order-watcher/test/expiration_watcher_test.ts @@ -1,7 +1,6 @@ import { tokenUtils } from '@0xproject/contract-wrappers/lib/test/utils/token_utils'; import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils'; import { FillScenarios } from '@0xproject/fill-scenarios'; -import { getContractAddresses } from '@0xproject/migrations'; import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils'; import { DoneCallback } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; @@ -14,6 +13,7 @@ import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher'; import { utils } from '../src/utils/utils'; import { chaiSetup } from './utils/chai_setup'; +import { migrateOnceAsync } from './utils/migrate'; import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); @@ -35,8 +35,8 @@ describe('ExpirationWatcher', () => { let timer: Sinon.SinonFakeTimers; let expirationWatcher: ExpirationWatcher; before(async () => { + const contractAddresses = await migrateOnceAsync(); await blockchainLifecycle.startAsync(); - const contractAddresses = getContractAddresses(); userAddresses = await web3Wrapper.getAvailableAddressesAsync(); fillScenarios = new FillScenarios( provider, diff --git a/packages/order-watcher/test/global_hooks.ts b/packages/order-watcher/test/global_hooks.ts index 49340f9e1..26c37158f 100644 --- a/packages/order-watcher/test/global_hooks.ts +++ b/packages/order-watcher/test/global_hooks.ts @@ -1,16 +1,6 @@ -import { devConstants } from '@0xproject/dev-utils'; -import { runMigrationsAsync } from '@0xproject/migrations'; - -import { provider } from './utils/web3_wrapper'; - -before('migrate contracts', async function(): Promise { +before('set up mocha', async function(): Promise { // HACK: Since the migrations take longer then our global mocha timeout limit // we manually increase it for this before hook. const mochaTestTimeoutMs = 25000; this.timeout(mochaTestTimeoutMs); // tslint:disable-line:no-invalid-this - const txDefaults = { - gas: devConstants.GAS_LIMIT, - from: devConstants.TESTRPC_FIRST_ADDRESS, - }; - await runMigrationsAsync(provider, txDefaults); }); diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts index 98a2fa089..e13d44396 100644 --- a/packages/order-watcher/test/order_watcher_test.ts +++ b/packages/order-watcher/test/order_watcher_test.ts @@ -3,7 +3,6 @@ import { ContractWrappers } from '@0xproject/contract-wrappers'; import { tokenUtils } from '@0xproject/contract-wrappers/lib/test/utils/token_utils'; import { BlockchainLifecycle, callbackErrorReporter } from '@0xproject/dev-utils'; import { FillScenarios } from '@0xproject/fill-scenarios'; -import { getContractAddresses } from '@0xproject/migrations'; import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils'; import { DoneCallback, @@ -28,6 +27,7 @@ import { OrderWatcherError } from '../src/types'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; +import { migrateOnceAsync } from './utils/migrate'; import { provider, web3Wrapper } from './utils/web3_wrapper'; const TIMEOUT_MS = 150; @@ -54,9 +54,9 @@ describe('OrderWatcher', () => { const decimals = constants.ZRX_DECIMALS; const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), decimals); before(async () => { + const contractAddresses = await migrateOnceAsync(); await blockchainLifecycle.startAsync(); const networkId = constants.TESTRPC_NETWORK_ID; - const contractAddresses = getContractAddresses(); const config = { networkId, contractAddresses, diff --git a/packages/order-watcher/test/utils/migrate.ts b/packages/order-watcher/test/utils/migrate.ts new file mode 100644 index 000000000..adcc22b1a --- /dev/null +++ b/packages/order-watcher/test/utils/migrate.ts @@ -0,0 +1,13 @@ +import { devConstants } from '@0xproject/dev-utils'; +import { runMigrationsOnceAsync } from '@0xproject/migrations'; +import { ContractAddresses } from '@0xproject/types'; + +import { provider } from './web3_wrapper'; + +export async function migrateOnceAsync(): Promise { + const txDefaults = { + gas: devConstants.GAS_LIMIT, + from: devConstants.TESTRPC_FIRST_ADDRESS, + }; + return runMigrationsOnceAsync(provider, txDefaults); +} -- cgit v1.2.3 From 1b8b2c0b9b998f42ded72f56c799a7951ed5239f Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 9 Oct 2018 14:17:40 -0700 Subject: Appease linter --- packages/order-watcher/test/utils/migrate.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/test/utils/migrate.ts b/packages/order-watcher/test/utils/migrate.ts index adcc22b1a..26412d246 100644 --- a/packages/order-watcher/test/utils/migrate.ts +++ b/packages/order-watcher/test/utils/migrate.ts @@ -4,6 +4,11 @@ import { ContractAddresses } from '@0xproject/types'; import { provider } from './web3_wrapper'; +/** + * Configures and runs the migrations exactly once. Any subsequent times this is + * called, it returns the cached addresses. + * @returns The addresses of contracts that were deployed during the migrations. + */ export async function migrateOnceAsync(): Promise { const txDefaults = { gas: devConstants.GAS_LIMIT, -- cgit v1.2.3 From 1e9ea09f087c7b3120e758d931a88812b655da08 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 9 Oct 2018 23:10:33 -0700 Subject: Introduce new contract-addresses package and use it everywhere --- packages/order-watcher/package.json | 1 + .../order-watcher/src/order_watcher/order_watcher.ts | 17 +++++++---------- packages/order-watcher/test/utils/migrate.ts | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json index ca352b754..a3f7b1fc7 100644 --- a/packages/order-watcher/package.json +++ b/packages/order-watcher/package.json @@ -60,6 +60,7 @@ "@0xproject/abi-gen-wrappers": "^1.0.0", "@0xproject/assert": "^1.0.13", "@0xproject/base-contract": "^3.0.1", + "@0xproject/contract-addresses": "^1.0.0", "@0xproject/contract-artifacts": "^1.0.0", "@0xproject/contract-wrappers": "^2.0.2", "@0xproject/fill-scenarios": "^1.0.7", diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 8afed3924..2f0dd2f2d 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -1,4 +1,5 @@ // tslint:disable:no-unnecessary-type-assertion +import { ContractAddresses } from '@0xproject/contract-addresses'; import * as artifacts from '@0xproject/contract-artifacts'; import { AssetBalanceAndProxyAllowanceFetcher, @@ -31,14 +32,7 @@ import { orderHashUtils, OrderStateUtils, } from '@0xproject/order-utils'; -import { - AssetProxyId, - ContractAddresses, - ExchangeContractErrs, - OrderState, - SignedOrder, - Stats, -} 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'; @@ -98,12 +92,14 @@ export class OrderWatcher { * Instantiate a new OrderWatcher * @param provider Web3 provider to use for JSON RPC calls * @param networkId NetworkId to watch orders on + * @param contractAddresses Optional contract addresses. Defaults to known + * addresses based on networkId. * @param partialConfig Optional configurations */ constructor( provider: Provider, networkId: number, - contractAddresses: ContractAddresses, + contractAddresses?: ContractAddresses, partialConfig: Partial = DEFAULT_ORDER_WATCHER_CONFIG, ) { assert.isWeb3Provider('provider', provider); @@ -122,7 +118,8 @@ export class OrderWatcher { ); const contractWrappers = new ContractWrappers(provider, { networkId, - // TODO(albrow): Make contract addresses optional. + // Note(albrow): We let the contract-wrappers package handle + // default values for contractAddresses. contractAddresses, }); this._eventWatcher = new EventWatcher(provider, config.eventPollingIntervalMs, STATE_LAYER, config.isVerbose); diff --git a/packages/order-watcher/test/utils/migrate.ts b/packages/order-watcher/test/utils/migrate.ts index 26412d246..53319a383 100644 --- a/packages/order-watcher/test/utils/migrate.ts +++ b/packages/order-watcher/test/utils/migrate.ts @@ -1,6 +1,6 @@ +import { ContractAddresses } from '@0xproject/contract-addresses'; import { devConstants } from '@0xproject/dev-utils'; import { runMigrationsOnceAsync } from '@0xproject/migrations'; -import { ContractAddresses } from '@0xproject/types'; import { provider } from './web3_wrapper'; -- cgit v1.2.3 From d76d8abc1d9a81ba7821f35bb43c0de5c0a7e0a2 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 10 Oct 2018 17:26:32 -0700 Subject: Update .gitignore and .prettierignore --- packages/order-watcher/.npmignore | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/.npmignore b/packages/order-watcher/.npmignore index c5be1b302..ac4ab11f2 100644 --- a/packages/order-watcher/.npmignore +++ b/packages/order-watcher/.npmignore @@ -7,4 +7,3 @@ test/ /_bundles/ /generated_docs/ /scripts/ -/lib/src/monorepo_scripts/ -- cgit v1.2.3 From f0e483798339b24b599c408949265cca54d7e58b Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 15 Oct 2018 13:30:12 -0700 Subject: Fix failing doc generation tests --- packages/order-watcher/src/index.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts index 8280c73a4..6e862a427 100644 --- a/packages/order-watcher/src/index.ts +++ b/packages/order-watcher/src/index.ts @@ -12,6 +12,7 @@ export { export { OnOrderStateChangeCallback, OrderWatcherConfig } from './types'; +export { ContractAddresses } from '@0xproject/contract-addresses'; export { SignedOrder } from '@0xproject/types'; export { JSONRPCRequestPayload, -- cgit v1.2.3 From e3af06ab107f98d4ca4a195da05d808370b56bb4 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 15 Oct 2018 14:11:20 -0700 Subject: Update CHANGELOG.json for all changed packages --- packages/order-watcher/CHANGELOG.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'packages/order-watcher') diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json index feebb9d69..1fa0b3bc9 100644 --- a/packages/order-watcher/CHANGELOG.json +++ b/packages/order-watcher/CHANGELOG.json @@ -1,10 +1,15 @@ [ { - "version": "2.1.2", + "version": "2.2.0", "changes": [ { "note": "Added getStats function and returns a Stats object", "pr": 1118 + }, + { + "note": + "Updated to use new modularized artifacts and the latest version of @0xproject/contract-wrappers. Constructor has a new optional `contractAddresses` parameter.", + "pr": 1105 } ] }, -- cgit v1.2.3