aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-watcher/test/order_watcher_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-watcher/test/order_watcher_test.ts')
-rw-r--r--packages/order-watcher/test/order_watcher_test.ts41
1 files changed, 31 insertions, 10 deletions
diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts
index 60d9069e8..e13d44396 100644
--- a/packages/order-watcher/test/order_watcher_test.ts
+++ b/packages/order-watcher/test/order_watcher_test.ts
@@ -27,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;
@@ -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;
@@ -56,17 +54,23 @@ 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 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();
@@ -140,6 +144,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();