diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-13 09:49:56 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-13 09:49:56 +0800 |
commit | a22661670f105a2bf527aca0e803689e0302ed17 (patch) | |
tree | 86042b06c407b388e39be690d9a40db218f82675 /test | |
parent | 442f35a1fdd98846d3985548b3de6f5c620e68a1 (diff) | |
parent | 5aef16c2aacd279a8e688b4e735526bff7e4970f (diff) | |
download | dexon-sol-tools-a22661670f105a2bf527aca0e803689e0302ed17.tar dexon-sol-tools-a22661670f105a2bf527aca0e803689e0302ed17.tar.gz dexon-sol-tools-a22661670f105a2bf527aca0e803689e0302ed17.tar.bz2 dexon-sol-tools-a22661670f105a2bf527aca0e803689e0302ed17.tar.lz dexon-sol-tools-a22661670f105a2bf527aca0e803689e0302ed17.tar.xz dexon-sol-tools-a22661670f105a2bf527aca0e803689e0302ed17.tar.zst dexon-sol-tools-a22661670f105a2bf527aca0e803689e0302ed17.zip |
Merge branch 'orderWatcher' of github.com:0xProject/0x.js into orderWatcher
* 'orderWatcher' of github.com:0xProject/0x.js: (33 commits)
Remove old tests
Remove unused code
Fix tests
Remove redundant spaces
Don't store empty objects
Fix a typo
Remove duplicate operations
Remove redundant instance variables
Fix tests
Remove blockStore and default to numConfirmations === 0
Add a comment
Store number of confirmations in a blockStore
Remove tautology check
Pass blockStore to eventWatcher
Fix last merge conflicts
Clear cache on unsubscribe
Clear store cache on events
Add more configs for order watcher
Make subscribe function async and make blockStore operational
Adjust tests to new interface
...
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); - }); - }); }); }); |