diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-14 07:57:38 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-14 07:57:38 +0800 |
commit | 02bbcf6b0e87925154d486ef9540c13e2a181a1c (patch) | |
tree | 5dcce7f9a7fb4478ecd3e54081c9cc7b20fc0444 /packages/0x.js/test/order_state_watcher_test.ts | |
parent | 33f479c27187f63035d28f2ed76d5a308f0dcc71 (diff) | |
download | dexon-sol-tools-02bbcf6b0e87925154d486ef9540c13e2a181a1c.tar.gz dexon-sol-tools-02bbcf6b0e87925154d486ef9540c13e2a181a1c.tar.zst dexon-sol-tools-02bbcf6b0e87925154d486ef9540c13e2a181a1c.zip |
Add a test for rounding error
Diffstat (limited to 'packages/0x.js/test/order_state_watcher_test.ts')
-rw-r--r-- | packages/0x.js/test/order_state_watcher_test.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 8236a6d6b..b7b5842c9 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -337,6 +337,29 @@ describe('OrderStateWatcher', () => { await zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount); })().catch(done); }); + it('should emit orderStateInvalid when within rounding error range', (done: DoneCallback) => { + (async () => { + const fillableAmountInBaseUnits = new BigNumber(10).pow(18); + const remainingFillableAmountInBaseUnits = new BigNumber(10).pow(2); + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerToken.address, takerToken.address, maker, taker, fillableAmountInBaseUnits, + ); + 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.OrderFillRoundingError); + done(); + }); + zeroEx.orderStateWatcher.subscribe(callback); + await zeroEx.exchange.cancelOrderAsync( + signedOrder, fillableAmountInBaseUnits.minus(remainingFillableAmountInBaseUnits), + ); + })().catch(done); + }); it('should emit orderStateValid when watched order partially cancelled', (done: DoneCallback) => { (async () => { signedOrder = await fillScenarios.createFillableSignedOrderAsync( |