Repository: dusk-network/rusk (language: rust)

Issue:
Some network methods are not reusing the existing connection
**Describe the bug**
The network store service methods added in https://github.com/dusk-network/rusk/pull/3170 are not reusing the existing network connection and are creating a new one for each call.


Discussion / hints:

Fix patch:
diff --git a/web-wallet/CHANGELOG.md b/web-wallet/CHANGELOG.md
index fd9599e19..6a72a01b4 100644
--- a/web-wallet/CHANGELOG.md
+++ b/web-wallet/CHANGELOG.md
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Fixed
 
 - Fix width discrepancy in footer icons [#3163]
+- Fix network methods not reusing the existing connection [#3486]
 
 ## [1.3.0] - 2025-01-28
 
@@ -571,6 +572,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 [#3387]: https://github.com/dusk-network/rusk/issues/3387
 [#3403]: https://github.com/dusk-network/rusk/issues/3403
 [#3420]: https://github.com/dusk-network/rusk/issues/3420
+[#3486]: https://github.com/dusk-network/rusk/issues/3486
 
 <!-- VERSIONS -->
 
diff --git a/web-wallet/src/lib/stores/networkStore.js b/web-wallet/src/lib/stores/networkStore.js
index 1beb99dcf..d88d6289b 100644
--- a/web-wallet/src/lib/stores/networkStore.js
+++ b/web-wallet/src/lib/stores/networkStore.js
@@ -45,8 +45,7 @@ const { set, subscribe } = networkStore;
  * @type {NetworkStoreServices["checkBlock"]}
  */
 const checkBlock = (height, hash) =>
-  network
-    .connect()
+  connect()
     .then(() => network.query(`checkBlock(height: ${height}, hash: "${hash}")`))
     .then(getKey("checkBlock"));
 
@@ -74,8 +73,7 @@ const getAddressSyncer = (options) =>
 
 /** @type {NetworkStoreServices["getBlockHashByHeight"]} */
 const getBlockHashByHeight = (height) =>
-  network
-    .connect()
+  connect()
     .then(() => network.query(`block(height: ${height}) { header { hash } }`))
     .then(getPath("block.header.hash"))
     .then(when(isUndefined, always("")));
@@ -85,8 +83,7 @@ const getCurrentBlockHeight = () => network.blockHeight;
 
 /** @type {NetworkStoreServices["getLastFinalizedBlockHeight"]} */
 const getLastFinalizedBlockHeight = () =>
-  network
-    .connect()
+  connect()
     .then(() => network.query("lastBlockPair { json }"))
     .then(getPath("lastBlockPair.json.last_finalized_block.0"))
     .then(condition(isUndefined, always(0n), BigInt));


Test patch:
diff --git a/web-wallet/src/lib/stores/__tests__/networkStore.spec.js b/web-wallet/src/lib/stores/__tests__/networkStore.spec.js
index d4e12d23e..1e7f90cb5 100644
--- a/web-wallet/src/lib/stores/__tests__/networkStore.spec.js
+++ b/web-wallet/src/lib/stores/__tests__/networkStore.spec.js
@@ -133,6 +133,9 @@ describe("Network store", async () => {
 
       await expect(store.checkBlock(12n, "some-hash")).resolves.toBe(true);
       await expect(store.checkBlock(12n, "some-hash")).resolves.toBe(false);
+
+      // check that the cached network is used
+      expect(connectSpy).toHaveBeenCalledTimes(1);
     });
 
     it("should expose a service method to retrieve a `AccountSyncer` for the network", async () => {
@@ -177,6 +180,9 @@ describe("Network store", async () => {
       networkQuerySpy.mockResolvedValueOnce({ block: null });
 
       await expect(store.getBlockHashByHeight(123n)).resolves.toBe("");
+
+      // check that the cached network is used
+      expect(connectSpy).toHaveBeenCalledTimes(1);
     });
 
     it("should expose a service method to retrieve the current block height", async () => {
@@ -200,6 +206,9 @@ describe("Network store", async () => {
       networkQuerySpy.mockResolvedValueOnce({ lastBlockPair: null });
 
       await expect(store.getLastFinalizedBlockHeight()).resolves.toBe(0n);
+
+      // check that the cached network is used
+      expect(connectSpy).toHaveBeenCalledTimes(1);
     });
   });
 });