Skip to content

Commit 827eb88

Browse files
Merge pull request #664 from JeneaVranceanu/fix/web3-error-output
2 parents f8528f8 + c8aef49 commit 827eb88

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Sources/Core/Web3Error/Web3Error.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
public enum Web3Error: Error {
10+
public enum Web3Error: LocalizedError {
1111
case transactionSerializationError
1212
case connectionError
1313

@@ -25,7 +25,7 @@ public enum Web3Error: Error {
2525
case generalError(err: Error)
2626
case unknownError
2727

28-
public var errorDescription: String {
28+
public var errorDescription: String? {
2929
switch self {
3030

3131
case .transactionSerializationError:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Web3ErrorTests.swift
3+
//
4+
// Created by JeneaVranceanu on 11.11.2022.
5+
//
6+
7+
import XCTest
8+
import Foundation
9+
@testable import Core
10+
11+
class Web3ErrorTests: XCTestCase {
12+
13+
func testWeb3ErrorReturnsExpectedDescription() {
14+
let emojis = ["🚀", "👋", "🥇", "☑️"]
15+
let message = "This is a custom description for test case! web3swift \(emojis.randomElement()!)"
16+
17+
/// It's important that we represent `Web3Error` as a generic `Error`!
18+
/// This is intentional as in `do-catch` block we do not receive `Web3Error`
19+
/// but `Error` type instead that can be casted.
20+
let error: Error = Web3Error.inputError(desc: message)
21+
XCTAssertEqual(error.localizedDescription, message)
22+
}
23+
24+
}
25+

0 commit comments

Comments
 (0)