Repository navigation
[SDK] Return null from resolveText for names without a resolver #9042
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "thirdweb": patch | ||
| --- | ||
|
|
||
| resolveText and resolveAvatar return null for names without a resolver | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { TEST_CLIENT } from "../../../test/src/test-clients.js"; | ||
| import { resolve } from "./__generated__/UniversalResolver/read/resolve.js"; | ||
| import { resolveText } from "./resolve-text.js"; | ||
|
|
||
| vi.mock("./__generated__/UniversalResolver/read/resolve.js", () => ({ | ||
| resolve: vi.fn(), | ||
| })); | ||
|
|
||
| describe("resolveText errors", () => { | ||
| beforeEach(() => { | ||
| vi.mocked(resolve).mockReset(); | ||
| }); | ||
|
|
||
| it("returns null when the name has no resolver", async () => { | ||
| vi.mocked(resolve).mockRejectedValue({ | ||
| code: 3, | ||
| data: "0x77209fe800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", | ||
| message: "execution reverted", | ||
| }); | ||
|
|
||
| await expect( | ||
| resolveText({ | ||
| client: TEST_CLIENT, | ||
| key: "avatar", | ||
| name: "no-resolver-test-1.eth", | ||
| }), | ||
| ).resolves.toBeNull(); | ||
| }); | ||
|
|
||
| it("rethrows other errors", async () => { | ||
| const error = { | ||
| code: 3, | ||
| data: "0x12345678", | ||
| message: "execution reverted", | ||
| }; | ||
| vi.mocked(resolve).mockRejectedValue(error); | ||
|
|
||
| await expect( | ||
| resolveText({ | ||
| client: TEST_CLIENT, | ||
| key: "avatar", | ||
| name: "no-resolver-test-2.eth", | ||
| }), | ||
| ).rejects.toBe(error); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,17 @@ export async function resolveText(options: ResolveTextOptions) { | |
| contract, | ||
| data, | ||
| name: toHex(packetToBytes(name)), | ||
| }).catch((e) => { | ||
| if ( | ||
| typeof e === "object" && | ||
| e !== null && | ||
| "data" in e && | ||
| typeof e.data === "string" && | ||
| e.data.startsWith("0x77209fe8") | ||
| ) { | ||
| return ["0x"] as const; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate cached results by resolver. If one resolver returns
|
||
| } | ||
| throw e; | ||
| }); | ||
|
|
||
| if (result[0] === "0x") { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a minor changeset for the public behavior change.
resolveTextnow returnsnullwhere it previously rejected. Mark this as a minor release.As per coding guidelines: “minor for any new/modified public API.”
Source: Coding guidelines