diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-09 23:21:54 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-10 03:11:46 +0800 |
commit | 4f030ac45c39a30da4f058284b52301d4422a595 (patch) | |
tree | b138c0cbd338de570b52459c791409d6be3acf3d /test | |
parent | c7c81a1f7e11daf0768617501657cb0266c0096a (diff) | |
download | dexon-sol-tools-4f030ac45c39a30da4f058284b52301d4422a595.tar dexon-sol-tools-4f030ac45c39a30da4f058284b52301d4422a595.tar.gz dexon-sol-tools-4f030ac45c39a30da4f058284b52301d4422a595.tar.bz2 dexon-sol-tools-4f030ac45c39a30da4f058284b52301d4422a595.tar.lz dexon-sol-tools-4f030ac45c39a30da4f058284b52301d4422a595.tar.xz dexon-sol-tools-4f030ac45c39a30da4f058284b52301d4422a595.tar.zst dexon-sol-tools-4f030ac45c39a30da4f058284b52301d4422a595.zip |
Rename test file and add test for a partial fill
Diffstat (limited to 'test')
-rw-r--r-- | test/order_state_watcher_test.ts (renamed from test/order_watcher_test.ts) | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/test/order_watcher_test.ts b/test/order_state_watcher_test.ts index 11138567c..f1b027c40 100644 --- a/test/order_watcher_test.ts +++ b/test/order_state_watcher_test.ts @@ -25,7 +25,7 @@ import { DoneCallback } from '../src/types'; chaiSetup.configure(); const expect = chai.expect; -describe.only('EventWatcher', () => { +describe('OrderStateWatcher', () => { let web3: Web3; let zeroEx: ZeroEx; let tokens: Token[]; @@ -56,6 +56,7 @@ describe.only('EventWatcher', () => { }); afterEach(async () => { zeroEx.orderStateWatcher.unsubscribe(); + const orderHash = ZeroEx.getOrderHashHex(signedOrder); zeroEx.orderStateWatcher.removeOrder(signedOrder); }); it('should emit orderStateInvalid when maker allowance set to 0 for watched order', (done: DoneCallback) => { @@ -103,12 +104,17 @@ describe.only('EventWatcher', () => { ); const orderHash = ZeroEx.getOrderHashHex(signedOrder); zeroEx.orderStateWatcher.addOrder(signedOrder); + + let eventCount = 0; const callback = (orderState: OrderState) => { + eventCount++; 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.OrderRemainingFillAmountZero); - done(); + if (eventCount === 2) { + done(); + } }; zeroEx.orderStateWatcher.subscribe(callback); @@ -118,4 +124,42 @@ describe.only('EventWatcher', () => { ); })().catch(done); }); + it('should emit orderStateValid when watched order partially filled', (done: DoneCallback) => { + (async () => { + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerToken.address, takerToken.address, maker, taker, fillableAmount, + ); + + const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker); + const takerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, taker); + + const fillAmountInBaseUnits = new BigNumber(2); + const orderHash = ZeroEx.getOrderHashHex(signedOrder); + zeroEx.orderStateWatcher.addOrder(signedOrder); + + let eventCount = 0; + const callback = (orderState: OrderState) => { + eventCount++; + expect(orderState.isValid).to.be.true(); + const validOrderState = orderState as OrderStateValid; + expect(validOrderState.orderHash).to.be.equal(orderHash); + const orderRelevantState = validOrderState.orderRelevantState; + const remainingMakerBalance = makerBalance.sub(fillAmountInBaseUnits); + expect(orderRelevantState.makerBalance).to.be.bignumber.equal(remainingMakerBalance); + if (eventCount === 2) { + done(); + } + }; + zeroEx.orderStateWatcher.subscribe(callback); + const shouldThrowOnInsufficientBalanceOrAllowance = true; + await zeroEx.exchange.fillOrderAsync( + signedOrder, fillAmountInBaseUnits, shouldThrowOnInsufficientBalanceOrAllowance, taker, + ); + })().catch(done); + }); }); + +/* + * - it should emit orderState when watched order partially filled + * - it should emit orderState when watched order is cancelled + */ |