diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-30 18:05:31 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-10 03:11:45 +0800 |
commit | e7f60032bc391cf8a3802a6d2141a61aa5204589 (patch) | |
tree | 9a9d16fd4493074a872d21cc823cf4b40224f133 /test | |
parent | 589bd8694f1c57d8d62bcda86af3475aef655bc2 (diff) | |
download | dexon-sol-tools-e7f60032bc391cf8a3802a6d2141a61aa5204589.tar dexon-sol-tools-e7f60032bc391cf8a3802a6d2141a61aa5204589.tar.gz dexon-sol-tools-e7f60032bc391cf8a3802a6d2141a61aa5204589.tar.bz2 dexon-sol-tools-e7f60032bc391cf8a3802a6d2141a61aa5204589.tar.lz dexon-sol-tools-e7f60032bc391cf8a3802a6d2141a61aa5204589.tar.xz dexon-sol-tools-e7f60032bc391cf8a3802a6d2141a61aa5204589.tar.zst dexon-sol-tools-e7f60032bc391cf8a3802a6d2141a61aa5204589.zip |
Adjust tests for mempool event watcher
Diffstat (limited to 'test')
-rw-r--r-- | test/event_watcher_test.ts (renamed from test/mempool_test.ts) | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/test/mempool_test.ts b/test/event_watcher_test.ts index 0c8fb921a..208871ea8 100644 --- a/test/mempool_test.ts +++ b/test/event_watcher_test.ts @@ -6,6 +6,8 @@ import * as Web3 from 'web3'; import BigNumber from 'bignumber.js'; import {chaiSetup} from './utils/chai_setup'; import {web3Factory} from './utils/web3_factory'; +import {Web3Wrapper} from '../src/web3_wrapper'; +import {EventWatcher} from '../src/mempool/event_watcher'; import { ZeroEx, LogEvent, @@ -16,10 +18,11 @@ import {DoneCallback} from '../src/types'; chaiSetup.configure(); const expect = chai.expect; -describe('MempoolWatcher', () => { +describe('EventWatcher', () => { let web3: Web3; - let zeroEx: ZeroEx; let stubs: Sinon.SinonStub[] = []; + let eventWatcher: EventWatcher; + let web3Wrapper: Web3Wrapper; const logA = { address: '0x71d271f8b14adef568f8f28f1587ce7271ac4ca5', blockHash: null, @@ -52,16 +55,15 @@ describe('MempoolWatcher', () => { }; before(async () => { web3 = web3Factory.create(); - const config = { - mempoolPollingIntervalMs: 10, - }; - zeroEx = new ZeroEx(web3.currentProvider, config); + const mempoolPollingIntervalMs = 10; + web3Wrapper = new Web3Wrapper(web3.currentProvider); + eventWatcher = new EventWatcher(web3Wrapper, mempoolPollingIntervalMs); }); afterEach(() => { // clean up any stubs after the test has completed _.each(stubs, s => s.restore()); stubs = []; - zeroEx.mempool.unsubscribe(); + eventWatcher.unsubscribe(); }); it('correctly emits initial log events', (done: DoneCallback) => { const logs: Web3.LogEntry[] = [logA, logB]; @@ -75,7 +77,7 @@ describe('MempoolWatcher', () => { ...logB, }, ]; - const getLogsStub = Sinon.stub((zeroEx.mempool as any)._web3Wrapper, 'getLogsAsync'); + const getLogsStub = Sinon.stub(web3Wrapper, 'getLogsAsync'); getLogsStub.onCall(0).returns(logs); stubs.push(getLogsStub); const callback = (event: LogEvent) => { @@ -85,7 +87,7 @@ describe('MempoolWatcher', () => { done(); } }; - zeroEx.mempool.subscribe(callback); + eventWatcher.subscribe(callback); }); it('correctly computes the difference and emits only changes', (done: DoneCallback) => { const initialLogs: Web3.LogEntry[] = [logA, logB]; @@ -108,18 +110,17 @@ describe('MempoolWatcher', () => { ...logC, }, ]; - const getLogsStub = Sinon.stub((zeroEx.mempool as any)._web3Wrapper, 'getLogsAsync'); + const getLogsStub = Sinon.stub(web3Wrapper, 'getLogsAsync'); getLogsStub.onCall(0).returns(initialLogs); getLogsStub.onCall(1).returns(changedLogs); stubs.push(getLogsStub); const callback = (event: LogEvent) => { - // console.log(event); const expectedLogEvent = expectedLogEvents.shift(); expect(event).to.be.deep.equal(expectedLogEvent); if (_.isEmpty(expectedLogEvents)) { done(); } }; - zeroEx.mempool.subscribe(callback); + eventWatcher.subscribe(callback); }); }); |