Skip to content

Commit

Permalink
[TIDY] Add more tests for ENS resolutions with subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthMike committed Nov 28, 2022
1 parent c551e14 commit 4ab4078
Showing 1 changed file with 124 additions and 2 deletions.
126 changes: 124 additions & 2 deletions web3sTests/ENS/ENSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,45 @@ class ENSTests: XCTestCase {
}
}

func testGivenRegistry_WhenExistingAddressHasSubdomain_ThenResolvesCorrectly() async {
do {
let nameService = EthereumNameService(client: client!)
let ens = try await nameService.resolve(
address: "0xB1037eB3268f942715c999EA6697ce33Febd70A7",
mode: .onchain
)
XCTAssertEqual("subdomain.darhmike.eth", ens)
} catch {
XCTFail("Expected ens but failed \(error).")
}
}

func testGivenRegistry_WhenAddressHasSubdomain_AndReverseRecordNotSet_ThenDoesNotResolveCorrectly() async {
do {
let nameService = EthereumNameService(client: client!)
let ens = try await nameService.resolve(
address: "0x787411394Ccb38483a6F303FDee075f3EA67D65F",
mode: .onchain
)
XCTFail("Resolved but expected failure")
} catch {
XCTAssertEqual(error as? EthereumNameServiceError, .ensUnknown)
}
}

func testGivenRegistry_WhenAddressHasSubdomain_AndReverseRecordNotSet_ThenResolvesENS() async {
do {
let nameService = EthereumNameService(client: client!)
let address = try await nameService.resolve(
ens: "another.darhmike.eth",
mode: .onchain
)
XCTAssertEqual(address, "0x787411394Ccb38483a6F303FDee075f3EA67D65F")
} catch {
XCTAssertEqual(error as? EthereumNameServiceError, .ensUnknown)
}
}

func testGivenRegistry_WhenNotExistingAddress_ThenFailsCorrectly() async {
do {
let nameService = EthereumNameService(client: client!)
Expand Down Expand Up @@ -92,7 +131,7 @@ class ENSTests: XCTestCase {
}
}

func testGivenRegistry_ThenResolvesMultipleAddressesInOneCall() async {
func testGivenRegistry_ThenResolvesMultipleAddressesWithMultiCall() async {
do {
let nameService = EthereumNameService(client: client!)

Expand All @@ -118,7 +157,90 @@ class ENSTests: XCTestCase {
}
}

func testGivenRegistry_ThenResolvesMultipleNamesInOneCall() async {
func testGivenRegistry_ThenResolvesSingleAddressWithMultiCall() async {
do {
let nameService = EthereumNameService(client: client!)

var results: [EthereumNameService.ResolveOutput<String>]?

let resolutions = try await nameService.resolve(addresses: [
"0x162142f0508F557C02bEB7C473682D7C91Bcef41"
])

results = resolutions.map { $0.output }

XCTAssertEqual(
results,
[
.resolved("darhmike.eth")
]
) } catch {
XCTFail("Expected resolutions but failed \(error).")
}
}

func testGivenRegistry_WhenAddressHasSubdomain_ThenResolvesSingleAddressWithMultiCall() async {
do {
let nameService = EthereumNameService(client: client!)

var results: [EthereumNameService.ResolveOutput<String>]?

let resolutions = try await nameService.resolve(addresses: [
"0xB1037eB3268f942715c999EA6697ce33Febd70A7"
])

results = resolutions.map { $0.output }

XCTAssertEqual(
results,
[
.resolved("subdomain.darhmike.eth")
]
) } catch {
XCTFail("Expected resolutions but failed \(error).")
}
}

func testGivenRegistry_WhenAddressHasSubdomain_AndReverseRecordNotSet_ThenDoesNotResolveSingleAddressWithMultiCall() async {
do {
let nameService = EthereumNameService(client: client!)

var results: [EthereumNameService.ResolveOutput<String>]?

let resolutions = try await nameService.resolve(addresses: [
"0x787411394Ccb38483a6F303FDee075f3EA67D65F"
])

results = resolutions.map { $0.output }

XCTAssertEqual(
results,
[
.couldNotBeResolved(.ensUnknown)
]
) } catch {
XCTFail("Expected resolutions but failed \(error).")
}
}

func testGivenRegistry_WhenAddressHasSubdomain_AndReverseRecordNotSet_ThenResolvesENSWithMultiCall() async {
do {
let nameService = EthereumNameService(client: client!)
let results = try await nameService.resolve(
names: ["another.darhmike.eth"]
)
XCTAssertEqual(
results.map(\.output),
[
.resolved("0x787411394Ccb38483a6F303FDee075f3EA67D65F")
]
)
} catch {
XCTAssertEqual(error as? EthereumNameServiceError, .ensUnknown)
}
}

func testGivenRegistry_ThenResolvesMultipleNamesWithMultiCall() async {
do {
let nameService = EthereumNameService(client: client!)

Expand Down

0 comments on commit 4ab4078

Please sign in to comment.