diff --git a/CHANGELOG.md b/CHANGELOG.md index 20cb5861ac7..631e06643e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -444,11 +444,9 @@ Released with 1.0.0-beta.37 code base. - ethers from 5.1.4 to 5.4.4 (#4231) - karma from 5.2.3 to 6.3.4 (#4231) - lerna from 3.22.1 to 4.0.0 (#4231) -- Dropped build tests in CI for Node v8 and v10, and added support for Node v14 +- Dropped build tests in CI for Node v8 and v10, and added support for Node v14 (#4231) - Change default value for `maxPriorityFeePerGas` from `1 Gwei` to `2.5 Gwei` (#4284) -- Introduced new configuration "blockHeaderTimeout" for waiting of block headers for transaction receipt (#3891) - Fixed bug in signTransaction (#4295) -- Format `block.baseFeePerGas` to number (#4330) ## [Unreleased] @@ -465,3 +463,6 @@ Released with 1.0.0-beta.37 code base. - Not considering `tx.chainId` if `tx.common.customChain.chainId` is provided for `web3.eth.accounts.signTransaction` function (#4293) - Added missing PromiEvent handler types (#4194) - Updated README to include Webpack 5 angular support instructions (#4174) +- Emit subscription id with connect event when creating a subscription (#4300) +- Introduced new configuration "blockHeaderTimeout" for waiting of block headers for transaction receipt (#3891) +- Format `block.baseFeePerGas` to number (#4330) diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index b0b134d7997..e244c6d2bbb 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -281,7 +281,6 @@ Subscription.prototype.subscribe = function() { if(!err && result) { _this.id = result; _this.method = payload.params[0]; - _this.emit('connected', result); // call callback on notifications _this.options.requestManager.addSubscription(_this, function(error, result) { @@ -310,6 +309,7 @@ Subscription.prototype.subscribe = function() { _this.emit('error', error); } }); + _this.emit('connected', result); } else { setTimeout(function(){ _this.callback(err, false, _this); diff --git a/test/eth.subscribe.ganache.js b/test/eth.subscribe.ganache.js index 82c47ff6fba..1b1b910aa7e 100644 --- a/test/eth.subscribe.ganache.js +++ b/test/eth.subscribe.ganache.js @@ -54,6 +54,18 @@ describe('subscription connect/reconnect', function () { }); }); + it('unsubscribe should remove the subscription object from the subscriptions and send eth_unsubscribe to the node', function (done) { + subscription = web3.eth + .subscribe('newBlockHeaders') + .on('connected', function () { + const id = subscription.id; + assert(subscription.options.requestManager.subscriptions.has(id)); + subscription.unsubscribe(); // Send eth_unsubscribe to the node + assert(!subscription.options.requestManager.subscriptions.has(id)); + done(); + }); + }); + it('clearSubscriptions', async function() { web3.eth.subscribe('newBlockHeaders'); await waitSeconds(1); // Sub need a little time to set up