Skip to content

Commit 9ede7ed

Browse files
committed
nits and tests
1 parent 45acbc6 commit 9ede7ed

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

BDKSwiftExampleWallet/Service/BDK Service/BDKService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension BlockchainClient {
4343
}
4444

4545
private class BDKService {
46-
static var shared: BDKService = BDKService()
46+
static let shared: BDKService = BDKService()
4747

4848
private var balance: Balance?
4949
private var persister: Persister?

BDKSwiftExampleWallet/Service/BDK Service/BDKSwiftExampleWalletError.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,22 @@ enum WalletError: Error {
1515
case fullScanUnsupported
1616
case backendNotImplemented
1717
}
18+
19+
extension WalletError: LocalizedError {
20+
var errorDescription: String? {
21+
switch self {
22+
case .blockchainConfigNotFound:
23+
return "Blockchain configuration not found"
24+
case .dbNotFound:
25+
return "Database not found"
26+
case .notSigned:
27+
return "Transaction not signed"
28+
case .walletNotFound:
29+
return "Wallet not found"
30+
case .fullScanUnsupported:
31+
return "Full scan is not supported by the selected blockchain client"
32+
case .backendNotImplemented:
33+
return "The selected blockchain backend is not yet implemented"
34+
}
35+
}
36+
}

BDKSwiftExampleWalletTests/Service/BDKSwiftExampleWalletBDKServiceTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,40 @@ final class BDKSwiftExampleWalletBDKServiceTests: XCTestCase {
3232
Transaction.mock?.transactionID
3333
)
3434
}
35+
36+
func testBDKClientGetClientType() {
37+
let clientType = BDKClient.mock.getClientType()
38+
39+
XCTAssertEqual(clientType, .esplora)
40+
}
41+
42+
func testBDKClientUpdateClientType() {
43+
// This test verifies that updateClientType doesn't crash with mock client
44+
// In the real implementation, setting an unimplemented type would fallback to esplora
45+
BDKClient.mock.updateClientType(.kyoto)
46+
47+
// Verify it still returns esplora (since mock doesn't actually change)
48+
let clientType = BDKClient.mock.getClientType()
49+
XCTAssertEqual(clientType, .esplora)
50+
}
51+
52+
func testBlockchainClientTypeEnumValues() {
53+
// Test that all expected client types are available
54+
let allCases = BlockchainClientType.allCases
55+
XCTAssertTrue(allCases.contains(.esplora))
56+
XCTAssertTrue(allCases.contains(.kyoto))
57+
XCTAssertTrue(allCases.contains(.electrum))
58+
XCTAssertEqual(allCases.count, 3)
59+
}
60+
61+
func testBlockchainClientEsploraFactory() {
62+
// Test that the esplora factory method works correctly
63+
let testURL = "https://blockstream.info/testnet/api"
64+
let client = BlockchainClient.esplora(url: testURL)
65+
66+
XCTAssertEqual(client.getUrl(), testURL)
67+
XCTAssertEqual(client.getType(), .esplora)
68+
XCTAssertTrue(client.supportsFullScan())
69+
}
3570

3671
}

0 commit comments

Comments
 (0)