@novasamatech/host-substrate-chain-connection 0.7.5-0 → 0.7.5-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,12 @@ export const createPauseController = () => {
25
25
  base = b;
26
26
  return (onMsg, onH) => {
27
27
  reinvocationPending = false;
28
+ // A new inner invocation means a fresh consumer (e.g. the host cached
29
+ // this provider across destroy → re-acquire). Clear `destroyed` so
30
+ // pause/resume work on the new connection. The flag's job is to gate
31
+ // pause/resume between the previous inner.disconnect and the next
32
+ // inner re-invocation — outside that window it should not stick.
33
+ destroyed = false;
28
34
  onMessage = onMsg;
29
35
  onHalt = onH;
30
36
  real = null;
@@ -174,4 +174,27 @@ describe('createPauseController', () => {
174
174
  inner(vi.fn(), vi.fn());
175
175
  expect(mock.latest.send).not.toHaveBeenCalled();
176
176
  });
177
+ it('pause/resume work again after disconnect + a fresh inner invocation', () => {
178
+ // The host caches one provider per chain. After destroyClient cascades
179
+ // through the inner connection's disconnect, the same pauseController is
180
+ // reused on the next lockApi. pause/resume must drive the new socket; the
181
+ // `destroyed` flag from the prior teardown must not stick.
182
+ const mock = createMockBase();
183
+ const pc = createPauseController();
184
+ const inner = pc.middleware(mock.base);
185
+ const firstConn = inner(vi.fn(), vi.fn());
186
+ firstConn.disconnect(); // sets destroyed = true under the old design
187
+ const secondOnHalt = vi.fn();
188
+ inner(vi.fn(), secondOnHalt);
189
+ expect(mock.invocations).toHaveLength(2); // new socket opened
190
+ pc.pause();
191
+ expect(pc.isPaused()).toBe(true);
192
+ expect(mock.invocations[1].disconnect).toHaveBeenCalledTimes(1);
193
+ expect(secondOnHalt).toHaveBeenCalledWith({ type: 'paused' });
194
+ inner(vi.fn(), vi.fn()); // simulate the post-halt re-invocation
195
+ expect(mock.invocations).toHaveLength(2); // still paused → no new base connection
196
+ pc.resume();
197
+ expect(pc.isPaused()).toBe(false);
198
+ expect(mock.invocations).toHaveLength(3); // resume opens a fresh socket
199
+ });
177
200
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-substrate-chain-connection",
3
3
  "type": "module",
4
- "version": "0.7.5-0",
4
+ "version": "0.7.5-2",
5
5
  "description": "Chain connection pool with ref counting and provider branching for Polkadot API",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@novasamatech/storage-adapter": "0.7.5-0",
28
+ "@novasamatech/storage-adapter": "0.7.5-2",
29
29
  "@polkadot-api/ws-provider": "^0.9.0",
30
30
  "@polkadot-api/json-rpc-provider": "^0.2.0",
31
31
  "@polkadot-api/json-rpc-provider-proxy": "^0.4.0",