Skip to content

Commit 5af56ef

Browse files
committed
Add test to get reverse resolver from the registry
1 parent fa43d40 commit 5af56ef

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Sources/ENSKit/ENSKit.swift

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public struct ENSKit {
3333
)
3434
}
3535

36+
public func resolver(addr: String) async throws -> ENSResolver? {
37+
let reversedDomain = addr.lowercased().replacingOccurrences(of: "0x", with: "") + ".addr.reverse"
38+
return try await resolver(name: reversedDomain)
39+
}
40+
3641
public func contenthash(name: String) async -> URL? {
3742
if let resolver = try? await resolver(name: name),
3843
let contenthash = try? await resolver.contenthash() {

Tests/ENSKitTests/EthereumContractTests/RegistryContractTests.swift

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ final class RegistryContractTests: XCTestCase {
1515
}
1616
}
1717

18+
func testReverseResolver() async throws {
19+
let contract = RegistryContract(client: client)
20+
let vitalik = Namehash.namehash("d8da6bf26964af9d7eed9e03e53415d37aa96045.addr.reverse")
21+
let result = try await contract.resolver(namehash: vitalik)
22+
if let ethResolver = result {
23+
XCTAssertEqual(ethResolver, try! Address("0x5fbb459c49bb06083c33109fa4f14810ec2cf358"))
24+
} else {
25+
XCTFail()
26+
}
27+
}
28+
1829
func testResolverNoResult() async throws {
1930
let contract = RegistryContract(client: client)
2031
let unsupported = Namehash.namehash("unsupportedENS")

0 commit comments

Comments
 (0)