From 395dba919684438fb7dc5b6c3612cf68d1224dc3 Mon Sep 17 00:00:00 2001 From: nivida Date: Mon, 5 Aug 2019 15:13:29 +0200 Subject: [PATCH] CHANGELOG.md updated and AbstractSocketProviderTest extended --- CHANGELOG.md | 1 + .../providers/AbstractSocketProviderTest.js | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cad46588261..4b245451437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,3 +85,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - stripHexPrefix fixed (#2989) - BatchRequest error handling fixed for callbacks (#2993) - ``reconnected`` event and reconnection timeout option added to WebsocketProvider (#2994) +- ``clearSubscriptions`` fixed (#3007) diff --git a/packages/web3-providers/tests/lib/providers/AbstractSocketProviderTest.js b/packages/web3-providers/tests/lib/providers/AbstractSocketProviderTest.js index a2c879d679d..8dd7409cf73 100644 --- a/packages/web3-providers/tests/lib/providers/AbstractSocketProviderTest.js +++ b/packages/web3-providers/tests/lib/providers/AbstractSocketProviderTest.js @@ -257,7 +257,6 @@ describe('AbstractSocketProviderTest', () => { it('calls clearSubscriptions and one unsubscribe call returns false', async () => { abstractSocketProvider.subscriptions.set('0x0', {id: '0x0', subscribeMethod: 'eth_subscribe'}); - abstractSocketProvider.removeAllListeners = jest.fn(); abstractSocketProvider.send = jest.fn((subscribeMethod, parameters) => { expect(subscribeMethod).toEqual('eth_unsubscribe'); @@ -274,7 +273,6 @@ describe('AbstractSocketProviderTest', () => { it('calls clearSubscriptions and all unsubscribe calls are returning true', async () => { abstractSocketProvider.subscriptions.set('0x0', {id: '0x0', subscribeMethod: 'eth_subscribe'}); - abstractSocketProvider.removeAllListeners = jest.fn(); abstractSocketProvider.send = jest.fn((subscribeMethod, parameters) => { expect(subscribeMethod).toEqual('eth_unsubscribe'); @@ -291,6 +289,30 @@ describe('AbstractSocketProviderTest', () => { expect(abstractSocketProvider.subscriptions).toEqual(new Map()); }); + it('calls clearSubscriptions without a type given and all unsubscribe calls are returning true', async () => { + abstractSocketProvider.subscriptions.set('0x0', {id: '0x0', subscribeMethod: 'eth_subscribe'}); + + abstractSocketProvider.send = jest.fn((subscribeMethod, parameters) => { + expect(subscribeMethod).toEqual('eth_unsubscribe'); + + expect(parameters).toEqual(['0x0']); + + return Promise.resolve(true); + }); + + const response = await abstractSocketProvider.clearSubscriptions(); + + expect(response).toEqual(true); + + expect(abstractSocketProvider.subscriptions).toEqual(new Map()); + }); + + it('calls clearSubscriptions without running subscriptions and resolves with true', async () => { + const response = await abstractSocketProvider.clearSubscriptions(); + + expect(response).toEqual(true); + }); + it('calls getSubscriptionEvent and has to iterate over all items', () => { abstractSocketProvider.subscriptions.set('ID', {id: '0x0'});