aboutsummaryrefslogtreecommitdiffstats
path: root/test/order_state_watcher_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/order_state_watcher_test.ts')
-rw-r--r--test/order_state_watcher_test.ts73
1 files changed, 4 insertions, 69 deletions
diff --git a/test/order_state_watcher_test.ts b/test/order_state_watcher_test.ts
index 41f938584..c8a4a8064 100644
--- a/test/order_state_watcher_test.ts
+++ b/test/order_state_watcher_test.ts
@@ -15,6 +15,7 @@ import {
ZeroExConfig,
OrderState,
SignedOrder,
+ ZeroExError,
OrderStateValid,
OrderStateInvalid,
ExchangeContractErrs,
@@ -92,14 +93,10 @@ describe('OrderStateWatcher', () => {
afterEach(async () => {
zeroEx.orderStateWatcher.unsubscribe();
});
- it('should fail when trying to subscribe twice', (done: DoneCallback) => {
+ it('should fail when trying to subscribe twice', async () => {
zeroEx.orderStateWatcher.subscribe(_.noop);
- try {
- zeroEx.orderStateWatcher.subscribe(_.noop);
- done(new Error('Expected the second subscription to fail'));
- } catch (err) {
- done();
- }
+ expect(() => zeroEx.orderStateWatcher.subscribe(_.noop))
+ .to.throw(ZeroExError.SubscriptionAlreadyPresent);
});
});
describe('tests with cleanup', async () => {
@@ -355,67 +352,5 @@ describe('OrderStateWatcher', () => {
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmountInBaseUnits);
})().catch(done);
});
- describe('check numConfirmations behavior', () => {
- before(() => {
- const configs: ZeroExConfig = {
- orderWatcherConfig: {
- numConfirmations: 1,
- },
- };
- zeroEx = new ZeroEx(web3.currentProvider, configs);
- });
- it('should emit orderState when watching at 1 confirmation deep and event is one block deep',
- (done: DoneCallback) => {
- (async () => {
- fillScenarios = new FillScenarios(
- zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress,
- );
-
- signedOrder = await fillScenarios.createFillableSignedOrderAsync(
- makerToken.address, takerToken.address, maker, taker, fillableAmount,
- );
- const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
- expect(orderState.isValid).to.be.false();
- const invalidOrderState = orderState as OrderStateInvalid;
- expect(invalidOrderState.orderHash).to.be.equal(orderHash);
- expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.InsufficientMakerBalance);
- done();
- });
- zeroEx.orderStateWatcher.subscribe(callback);
-
- const anyRecipient = taker;
- const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker);
- await zeroEx.token.transferAsync(makerToken.address, maker, anyRecipient, makerBalance);
- blockchainLifecycle.mineABlock();
- })().catch(done);
- });
- it('shouldn\'t emit orderState when watching at 1 confirmation deep and event is in mempool',
- (done: DoneCallback) => {
- (async () => {
- fillScenarios = new FillScenarios(
- zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress,
- );
-
- signedOrder = await fillScenarios.createFillableSignedOrderAsync(
- makerToken.address, takerToken.address, maker, taker, fillableAmount,
- );
- const orderHash = ZeroEx.getOrderHashHex(signedOrder);
- zeroEx.orderStateWatcher.addOrder(signedOrder);
- const callback = reportCallbackErrors(done)((orderState: OrderState) => {
- throw new Error('OrderState callback fired when it shouldn\'t have');
- });
- zeroEx.orderStateWatcher.subscribe(callback);
-
- const anyRecipient = taker;
- const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker);
- await zeroEx.token.transferAsync(makerToken.address, maker, anyRecipient, makerBalance);
- setTimeout(() => {
- done();
- }, TIMEOUT_MS);
- })().catch(done);
- });
- });
});
});