Skip to content

Commit

Permalink
fix: fixes bug where provider.request opens a connection and `this.to…
Browse files Browse the repository at this point in the history
…EstablishConnection`; opens too
  • Loading branch information
Gancho Radkov committed Feb 21, 2024
1 parent ab3aa2f commit 8c27041
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/core/src/controllers/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,14 @@ export class Relayer extends IRelayer {
public request = async (request: RequestArguments<RelayJsonRpc.SubscribeParams>) => {
this.logger.debug(`Publishing Request Payload`);
const id = request.id as number;
const requestPromise = this.provider.request(request);
this.requestsInFlight.set(id, {
promise: requestPromise,
request,
});

try {
await this.toEstablishConnection();
const requestPromise = this.provider.request(request);
this.requestsInFlight.set(id, {
promise: requestPromise,
request,
});
const result = await requestPromise;
return result;
} catch (e) {
Expand Down
26 changes: 26 additions & 0 deletions packages/sign-client/test/sdk/transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,31 @@ describe("Sign Client Transport Tests", () => {
]);
await deleteClients(clients);
});
it("should automatically start transport on request after being closed", async () => {
const clients = await initTwoClients();
const {
sessionA: { topic },
} = await testConnectMethod(clients);
await clients.A.core.relayer.transportClose();
await throttle(2000);
await Promise.all([
new Promise((resolve) => {
clients.B.on("session_ping", (event: any) => {
resolve(event);
});
}),
new Promise((resolve) => {
clients.A.on("session_ping", (event: any) => {
resolve(event);
});
}),
new Promise(async (resolve) => {
await clients.A.ping({ topic });
await clients.B.ping({ topic });
resolve(true);
}),
]);
await deleteClients(clients);
});
});
});

0 comments on commit 8c27041

Please sign in to comment.