Skip to content
Open
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
33 changes: 33 additions & 0 deletions web3sTests/Client/EthereumClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,29 @@ class EthereumClientTests: XCTestCase {
do {
let logs = try await client?.eth_getLogs(addresses: ["0x23d0a442580c01e420270fba6ca836a8b2353acb"], topics: nil, fromBlock: .Earliest, toBlock: .Latest)
XCTAssertNotNil(logs, "Logs not available")
XCTAssertEqual(logs?.count, 0)
} catch {
XCTFail("Expected logs but failed \(error).")
}
}

func testSimpleEthGetLogsWithFailingRequest() async {
guard let client = client else {
XCTFail()
return
}
await XCTAssertThrowsErrorAsync(
try await client.eth_getLogs(
addresses: ["0x3edf60dd017ace33a0220f78741b5581c385a1ba"],
topics: [try? ERC20Events.Transfer.signature()],
fromBlock: .Earliest,
toBlock: .Latest
),
EthereumClientError.unexpectedReturnValue,
"Too many logs to receive. Should throw an error instead of defaulting to empty array"
)
}

func testOrTopicsEthGetLogs() async {
do {
let logs = try await client?.eth_getLogs(addresses: nil, orTopics: [["0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"], ["0x00000000000000000000000061CA935f8b7847C4a1275814d8D88CDa8d406CC9"]], fromBlock: .Number(4902849), toBlock: .Number(4902849))
Expand Down Expand Up @@ -606,3 +624,18 @@ extension EthereumWebSocketClientTests: EthereumWebSocketClientDelegate {
delegateExpectation = nil
}
}

func XCTAssertThrowsErrorAsync<T, R>(
_ expression: @autoclosure () async throws -> T,
_ errorThrown: @autoclosure () -> R,
_ message: @autoclosure () -> String = "This method should fail",
file: StaticString = #filePath,
line: UInt = #line
) async where R: Equatable, R: Error {
do {
let _ = try await expression()
XCTFail(message(), file: file, line: line)
} catch {
XCTAssertEqual(error as? R, errorThrown())
}
}
3 changes: 2 additions & 1 deletion web3swift/src/Client/RecursiveLogCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ struct RecursiveLogCollector {
throw EthereumClientError.unexpectedReturnValue
}
return lhs + rhs
} else {
throw error
}
}
return []
}

private func getLogs(addresses: [EthereumAddress]?, topics: Topics? = nil, from: EthereumBlock, to: EthereumBlock) async throws -> [EthereumLog] {
Expand Down
Loading