diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-07-04 07:13:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-04 07:13:16 +0800 |
commit | 997964f3e24eda9287a6d4a9c56d8e90b72f0789 (patch) | |
tree | 0cb99d4d64b08dd6bb1d64e53c0e0af751d6b8c9 /test/exchange_wrapper_test.ts | |
parent | d4cef89587ef8ea0f7fbab1146c4524e8f588eac (diff) | |
parent | c9edeae6d8dad1fba6c4f5eca63ff5db3e6555e2 (diff) | |
download | dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.gz dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.bz2 dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.lz dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.xz dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.tar.zst dexon-sol-tools-997964f3e24eda9287a6d4a9c56d8e90b72f0789.zip |
Merge pull request #87 from 0xProject/wrap-log-bignumber
Wrap all event args in a newer version of BigNumber and test it
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r-- | test/exchange_wrapper_test.ts | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 5833a8c23..2682c5d52 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -18,6 +18,7 @@ import { ExchangeContractErrs, OrderCancellationRequest, OrderFillRequest, + LogFillContractEventArgs, } from '../src'; import {DoneCallback} from '../src/types'; import {FillScenarios} from './utils/fill_scenarios'; @@ -680,6 +681,12 @@ describe('ExchangeWrapper', () => { let makerAddress: string; let fillableAmount: BigNumber.BigNumber; let signedOrder: SignedOrder; + const subscriptionOpts: SubscriptionOpts = { + fromBlock: 0, + toBlock: 'latest', + }; + const fillTakerAmountInBaseUnits = new BigNumber(1); + const cancelTakerAmountInBaseUnits = new BigNumber(1); before(() => { [coinbase, makerAddress, takerAddress] = userAddresses; const [makerToken, takerToken] = tokens; @@ -702,10 +709,6 @@ describe('ExchangeWrapper', () => { // Source: https://github.com/mochajs/mocha/issues/2407 it('Should receive the LogFill event when an order is filled', (done: DoneCallback) => { (async () => { - const subscriptionOpts: SubscriptionOpts = { - fromBlock: 0, - toBlock: 'latest', - }; const zeroExEvent = await zeroEx.exchange.subscribeAsync( ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, ); @@ -715,7 +718,6 @@ describe('ExchangeWrapper', () => { expect(event.event).to.be.equal('LogFill'); done(); }); - const fillTakerAmountInBaseUnits = new BigNumber(1); await zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, takerAddress, ); @@ -723,10 +725,6 @@ describe('ExchangeWrapper', () => { }); it('Should receive the LogCancel event when an order is cancelled', (done: DoneCallback) => { (async () => { - const subscriptionOpts: SubscriptionOpts = { - fromBlock: 0, - toBlock: 'latest', - }; const zeroExEvent = await zeroEx.exchange.subscribeAsync( ExchangeEvents.LogCancel, subscriptionOpts, indexFilterValues, exchangeContractAddress, ); @@ -736,16 +734,11 @@ describe('ExchangeWrapper', () => { expect(event.event).to.be.equal('LogCancel'); done(); }); - const cancelTakerAmountInBaseUnits = new BigNumber(1); await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelTakerAmountInBaseUnits); })(); }); it('Outstanding subscriptions are cancelled when zeroEx.setProviderAsync called', (done: DoneCallback) => { (async () => { - const subscriptionOpts: SubscriptionOpts = { - fromBlock: 0, - toBlock: 'latest', - }; const eventSubscriptionToBeCancelled = await zeroEx.exchange.subscribeAsync( ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, ); @@ -765,8 +758,6 @@ describe('ExchangeWrapper', () => { expect(event.event).to.be.equal('LogFill'); done(); }); - - const fillTakerAmountInBaseUnits = new BigNumber(1); await zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, takerAddress, ); @@ -774,10 +765,6 @@ describe('ExchangeWrapper', () => { }); it('Should stop watch for events when stopWatchingAsync called on the eventEmitter', (done: DoneCallback) => { (async () => { - const subscriptionOpts: SubscriptionOpts = { - fromBlock: 0, - toBlock: 'latest', - }; const eventSubscriptionToBeStopped = await zeroEx.exchange.subscribeAsync( ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, ); @@ -785,13 +772,30 @@ describe('ExchangeWrapper', () => { done(new Error('Expected this subscription to have been stopped')); }); await eventSubscriptionToBeStopped.stopWatchingAsync(); - const fillTakerAmountInBaseUnits = new BigNumber(1); await zeroEx.exchange.fillOrderAsync( signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, takerAddress, ); done(); })(); }); + it('Should wrap all event args BigNumber instances in a newer version of BigNumber', (done: DoneCallback) => { + (async () => { + const zeroExEvent = await zeroEx.exchange.subscribeAsync( + ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, + ); + zeroExEvent.watch((err: Error, event: ContractEvent) => { + const args = event.args as LogFillContractEventArgs; + expect(args.filledValueM.isBigNumber).to.be.true(); + expect(args.filledValueT.isBigNumber).to.be.true(); + expect(args.feeMPaid.isBigNumber).to.be.true(); + expect(args.feeTPaid.isBigNumber).to.be.true(); + done(); + }); + await zeroEx.exchange.fillOrderAsync( + signedOrder, fillTakerAmountInBaseUnits, shouldCheckTransfer, takerAddress, + ); + })(); + }); }); describe('#getOrderHashHexUsingContractCallAsync', () => { let makerTokenAddress: string; |