diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-19 10:28:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 10:28:18 +0800 |
commit | 4bc65faf1ab2c753da0989088852ebf7281fd7de (patch) | |
tree | 40925c2880764b02320903d4bc61d4b5cae59530 /packages/0x.js/test | |
parent | 8634551f53bac9769e866b9a2f6f7d0dbd203704 (diff) | |
parent | d1d26f8bf6da4d47df026f509a51d2be62cf1800 (diff) | |
download | dexon-sol-tools-4bc65faf1ab2c753da0989088852ebf7281fd7de.tar dexon-sol-tools-4bc65faf1ab2c753da0989088852ebf7281fd7de.tar.gz dexon-sol-tools-4bc65faf1ab2c753da0989088852ebf7281fd7de.tar.bz2 dexon-sol-tools-4bc65faf1ab2c753da0989088852ebf7281fd7de.tar.lz dexon-sol-tools-4bc65faf1ab2c753da0989088852ebf7281fd7de.tar.xz dexon-sol-tools-4bc65faf1ab2c753da0989088852ebf7281fd7de.tar.zst dexon-sol-tools-4bc65faf1ab2c753da0989088852ebf7281fd7de.zip |
Merge pull request #526 from 0xProject/fix/expiration-watcher
Fix expiration watcher comparator
Diffstat (limited to 'packages/0x.js/test')
-rw-r--r-- | packages/0x.js/test/0x.js_test.ts | 7 | ||||
-rw-r--r-- | packages/0x.js/test/expiration_watcher_test.ts | 39 | ||||
-rw-r--r-- | packages/0x.js/test/global_hooks.ts | 7 |
3 files changed, 46 insertions, 7 deletions
diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index de5a6be58..838ee7080 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -1,9 +1,4 @@ -import { Deployer } from '@0xproject/deployer'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; -// HACK: This dependency is optional since it is only available when run from within -// the monorepo. tslint doesn't handle optional dependencies -// tslint:disable-next-line:no-implicit-dependencies -import { runMigrationsAsync } from '@0xproject/migrations'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -15,7 +10,6 @@ import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, Zero import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; -import { deployer } from './utils/deployer'; import { TokenUtils } from './utils/token_utils'; import { provider, web3Wrapper } from './utils/web3_wrapper'; @@ -28,7 +22,6 @@ const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false; describe('ZeroEx library', () => { let zeroEx: ZeroEx; before(async () => { - await runMigrationsAsync(deployer); const config = { networkId: constants.TESTRPC_NETWORK_ID, }; diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 29b111fa3..1b022539a 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -153,4 +153,43 @@ describe('ExpirationWatcher', () => { timer.tick(order2Lifetime * 1000); })().catch(done); }); + it('emits events in correct order when expirations are equal', (done: DoneCallback) => { + (async () => { + const order1Lifetime = 60; + const order2Lifetime = 60; + const order1ExpirationUnixTimestampSec = currentUnixTimestampSec.plus(order1Lifetime); + const order2ExpirationUnixTimestampSec = currentUnixTimestampSec.plus(order2Lifetime); + const signedOrder1 = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, + takerTokenAddress, + makerAddress, + takerAddress, + fillableAmount, + order1ExpirationUnixTimestampSec, + ); + const signedOrder2 = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, + takerTokenAddress, + makerAddress, + takerAddress, + fillableAmount, + order2ExpirationUnixTimestampSec, + ); + const orderHash1 = ZeroEx.getOrderHashHex(signedOrder1); + const orderHash2 = ZeroEx.getOrderHashHex(signedOrder2); + expirationWatcher.addOrder(orderHash1, signedOrder1.expirationUnixTimestampSec.times(1000)); + expirationWatcher.addOrder(orderHash2, signedOrder2.expirationUnixTimestampSec.times(1000)); + const expirationOrder = orderHash1 < orderHash2 ? [orderHash1, orderHash2] : [orderHash2, orderHash1]; + const expectToBeCalledOnce = false; + const callbackAsync = reportNoErrorCallbackErrors(done, expectToBeCalledOnce)((hash: string) => { + const orderHash = expirationOrder.shift(); + expect(hash).to.be.equal(orderHash); + if (_.isEmpty(expirationOrder)) { + done(); + } + }); + expirationWatcher.subscribe(callbackAsync); + timer.tick(order2Lifetime * 1000); + })().catch(done); + }); }); diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts new file mode 100644 index 000000000..e3c986524 --- /dev/null +++ b/packages/0x.js/test/global_hooks.ts @@ -0,0 +1,7 @@ +import { runMigrationsAsync } from '@0xproject/migrations'; + +import { deployer } from './utils/deployer'; + +before('migrate contracts', async () => { + await runMigrationsAsync(deployer); +}); |