diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/event_watcher_test.ts | 2 | ||||
-rw-r--r-- | test/exchange_transfer_simulator_test.ts | 18 | ||||
-rw-r--r-- | test/order_state_watcher_test.ts | 73 |
3 files changed, 13 insertions, 80 deletions
diff --git a/test/event_watcher_test.ts b/test/event_watcher_test.ts index 98dab93b5..b4164fe63 100644 --- a/test/event_watcher_test.ts +++ b/test/event_watcher_test.ts @@ -58,7 +58,7 @@ describe('EventWatcher', () => { web3 = web3Factory.create(); const pollingIntervalMs = 10; web3Wrapper = new Web3Wrapper(web3.currentProvider); - eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs, numConfirmations); + eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs); }); afterEach(() => { // clean up any stubs after the test has completed diff --git a/test/exchange_transfer_simulator_test.ts b/test/exchange_transfer_simulator_test.ts index 3373ebf03..99cb7fb4f 100644 --- a/test/exchange_transfer_simulator_test.ts +++ b/test/exchange_transfer_simulator_test.ts @@ -59,11 +59,10 @@ describe('ExchangeTransferSimulator', () => { await exchangeTransferSimulator.transferFromAsync( exampleTokenAddress, sender, recipient, transferAmount, TradeSide.Taker, TransferType.Trade, ); - const senderBalance = await (exchangeTransferSimulator as any).getBalanceAsync(exampleTokenAddress, sender); - const recipientBalance = await (exchangeTransferSimulator as any).getBalanceAsync( - exampleTokenAddress, recipient); - const senderProxyAllowance = await (exchangeTransferSimulator as any).getProxyAllowanceAsync( - exampleTokenAddress, sender); + const store = (exchangeTransferSimulator as any).store; + const senderBalance = await store.getBalanceAsync(exampleTokenAddress, sender); + const recipientBalance = await store.getBalanceAsync(exampleTokenAddress, recipient); + const senderProxyAllowance = await store.getProxyAllowanceAsync(exampleTokenAddress, sender); expect(senderBalance).to.be.bignumber.equal(0); expect(recipientBalance).to.be.bignumber.equal(transferAmount); expect(senderProxyAllowance).to.be.bignumber.equal(0); @@ -76,11 +75,10 @@ describe('ExchangeTransferSimulator', () => { await exchangeTransferSimulator.transferFromAsync( exampleTokenAddress, sender, recipient, transferAmount, TradeSide.Taker, TransferType.Trade, ); - const senderBalance = await (exchangeTransferSimulator as any).getBalanceAsync(exampleTokenAddress, sender); - const recipientBalance = await (exchangeTransferSimulator as any).getBalanceAsync( - exampleTokenAddress, recipient); - const senderProxyAllowance = await (exchangeTransferSimulator as any).getProxyAllowanceAsync( - exampleTokenAddress, sender); + const store = (exchangeTransferSimulator as any).store; + const senderBalance = await store.getBalanceAsync(exampleTokenAddress, sender); + const recipientBalance = await store.getBalanceAsync(exampleTokenAddress, recipient); + const senderProxyAllowance = await store.getProxyAllowanceAsync(exampleTokenAddress, sender); expect(senderBalance).to.be.bignumber.equal(0); expect(recipientBalance).to.be.bignumber.equal(transferAmount); expect(senderProxyAllowance).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); 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); - }); - }); }); }); |