diff options
author | Jacob Evans <jacob@dekz.net> | 2017-11-13 08:17:27 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2017-11-13 08:17:27 +0800 |
commit | 42e3ab91a794f61d65008d969b3d48080b5035d7 (patch) | |
tree | 80d1bc9a2b750009cd30db2e10e33963d9e47023 /test | |
parent | 5e77e8809abd96136fb11ebdc84a2aefa32d4cea (diff) | |
download | dexon-sol-tools-42e3ab91a794f61d65008d969b3d48080b5035d7.tar dexon-sol-tools-42e3ab91a794f61d65008d969b3d48080b5035d7.tar.gz dexon-sol-tools-42e3ab91a794f61d65008d969b3d48080b5035d7.tar.bz2 dexon-sol-tools-42e3ab91a794f61d65008d969b3d48080b5035d7.tar.lz dexon-sol-tools-42e3ab91a794f61d65008d969b3d48080b5035d7.tar.xz dexon-sol-tools-42e3ab91a794f61d65008d969b3d48080b5035d7.tar.zst dexon-sol-tools-42e3ab91a794f61d65008d969b3d48080b5035d7.zip |
Perform the division after multiplication to reduce compounding the rounding errors
Diffstat (limited to 'test')
-rw-r--r-- | test/order_state_watcher_test.ts | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/test/order_state_watcher_test.ts b/test/order_state_watcher_test.ts index 07d18ae61..924e54772 100644 --- a/test/order_state_watcher_test.ts +++ b/test/order_state_watcher_test.ts @@ -190,7 +190,8 @@ describe('OrderStateWatcher', () => { const orderRelevantState = validOrderState.orderRelevantState; const remainingMakerBalance = makerBalance.sub(fillAmountInBaseUnits); const remainingFillable = fillableAmount.minus(fillAmountInBaseUnits); - expect(remainingFillable).to.be.bignumber.equal(fillableAmount.minus(fillAmountInBaseUnits)); + expect(orderRelevantState.remainingFillableMakerTokenAmount).to.be.bignumber.equal( + remainingFillable); expect(orderRelevantState.makerBalance).to.be.bignumber.equal(remainingMakerBalance); if (eventCount === 2) { done(); @@ -204,7 +205,7 @@ describe('OrderStateWatcher', () => { })().catch(done); }); describe('remainingFillableMakerTokenAmount', () => { - it('should calculate correct reamining fillable', (done: DoneCallback) => { + it('should calculate correct remaining fillable', (done: DoneCallback) => { (async () => { const takerFillableAmount = new BigNumber(10); const makerFillableAmount = new BigNumber(20); @@ -265,20 +266,20 @@ describe('OrderStateWatcher', () => { const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker); - const transferAmount = new BigNumber(1); + const remainingAmount = new BigNumber(1); + const transferAmount = makerBalance.sub(remainingAmount); zeroEx.orderStateWatcher.addOrder(signedOrder); const callback = reportCallbackErrors(done)((orderState: OrderState) => { const validOrderState = orderState as OrderStateValid; const orderRelevantState = validOrderState.orderRelevantState; - expect(orderRelevantState.remainingFillableMakerTokenAmount).to.be.bignumber.equal( - transferAmount); + remainingAmount); done(); }); zeroEx.orderStateWatcher.subscribe(callback); - await zeroEx.token.transferAsync(makerToken.address, maker, ZeroEx.NULL_ADDRESS, - makerBalance.minus(transferAmount)); + await zeroEx.token.transferAsync( + makerToken.address, maker, ZeroEx.NULL_ADDRESS, transferAmount); })().catch(done); }); }); |