Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unhandled on network drop when provider is not initialized #5446

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/controllers/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class Relayer extends IRelayer {
}
}

if (this.hasExperiencedNetworkDisruption || this.connected) {
if (this.provider.disconnect && (this.hasExperiencedNetworkDisruption || this.connected)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be safer to use the optional chain operator or it's not needed ?

Suggested change
if (this.provider.disconnect && (this.hasExperiencedNetworkDisruption || this.connected)) {
if (this.provider?.disconnect && (this.hasExperiencedNetworkDisruption || this.connected)) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need as this.provider is {} if not yet initialized. Being {} is covered by other tests

await createExpiringPromise(this.provider.disconnect(), 2000, "provider.disconnect()").catch(
() => this.onProviderDisconnect(),
);
Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/relayer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ describe("Relayer", () => {
await disconnectSocket(relayer);
});

it("should not throw unhandled on network disconnect when there is no provider instance", async () => {
relayer.messages.init = initSpy;
await relayer.init();
expect(relayer.provider).to.be.empty;
expect(relayer.connected).to.be.false;
// @ts-expect-error - private property
relayer.hasExperiencedNetworkDisruption = true;
// @ts-expect-error - private method
await relayer.transportDisconnect();
});
it("initializes a MessageTracker", async () => {
relayer.messages.init = initSpy;
await relayer.init();
Expand Down
Loading