Skip to content

Commit

Permalink
Merge branch '1.x' into alex/remove-underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed May 17, 2021
2 parents a69b9f6 + 49b0130 commit d3f8358
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/web3-eth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ var Eth = function Eth() {

this.clearSubscriptions = _this._requestManager.clearSubscriptions.bind(_this._requestManager);

this.removeSubscriptionById = _this._requestManager.removeSubscription.bind(_this._requestManager);

// add net
this.net = new Net(this);
// add chain detection
Expand Down
27 changes: 27 additions & 0 deletions test/eth.subscribe.ganache.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ describe('subscription connect/reconnect', function () {
assert.equal(0, web3.eth._requestManager.subscriptions.size);
});

it('unsubscribes given an id', async function ( ) {
subscription = web3.eth.subscribe('newBlockHeaders');
await waitSeconds(1);

assert.equal(1, web3.eth._requestManager.subscriptions.size);
web3.eth.removeSubscriptionById(subscription.id)

assert.equal(0, web3.eth._requestManager.subscriptions.size);

})

it('unsubscribes given an id with multiple subscriptions', async function () {

subscription = web3.eth.subscribe('newBlockHeaders');
subscription2 = web3.eth.subscribe("logs");
await waitSeconds(1);

assert.equal(2, web3.eth._requestManager.subscriptions.size);

web3.eth.removeSubscriptionById(subscription.id);
assert.equal(1, web3.eth._requestManager.subscriptions.size);

web3.eth.removeSubscriptionById(subscription2.id);
assert.equal(0, web3.eth._requestManager.subscriptions.size);

})

it('resubscribes to an existing subscription', function (done) {
this.timeout(5000);

Expand Down

0 comments on commit d3f8358

Please sign in to comment.