-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: streamline blockchain clients error names
- Loading branch information
1 parent
8f4c80c
commit ca8a3d0
Showing
5 changed files
with
95 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
bdk-swift/Tests/BitcoinDevKitTests/LiveElectrumClientTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import XCTest | ||
@testable import BitcoinDevKit | ||
|
||
private let SIGNET_ELECTRUM_URL = "ssl://mempool.space:60602" | ||
|
||
final class LiveElectrumClientTests: XCTestCase { | ||
func testSyncedBalance() throws { | ||
let descriptor = try Descriptor( | ||
descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", | ||
network: Network.signet | ||
) | ||
let wallet = try Wallet.newNoPersist( | ||
descriptor: descriptor, | ||
changeDescriptor: nil, | ||
network: .signet | ||
) | ||
let electrumClient: ElectrumClient = try ElectrumClient(url: SIGNET_ELECTRUM_URL) | ||
let fullScanRequest: FullScanRequest = wallet.startFullScan() | ||
let update = try electrumClient.fullScan( | ||
fullScanRequest: fullScanRequest, | ||
stopGap: 10, | ||
batchSize: 10, | ||
fetchPrevTxouts: false | ||
) | ||
try wallet.applyUpdate(update: update) | ||
let _ = try wallet.commit() | ||
let address = try wallet.revealNextAddress(keychain: KeychainKind.external).address.asString() | ||
|
||
XCTAssertGreaterThan( | ||
wallet.getBalance().total.toSat(), | ||
UInt64(0), | ||
"Wallet must have positive balance, please send funds to \(address)" | ||
) | ||
|
||
print("Transactions count: \(wallet.transactions().count)") | ||
let transactions = wallet.transactions().prefix(3) | ||
for tx in transactions { | ||
let sentAndReceived = wallet.sentAndReceived(tx: tx.transaction) | ||
print("Transaction: \(tx.transaction.txid())") | ||
print("Sent \(sentAndReceived.sent)") | ||
print("Received \(sentAndReceived.received)") | ||
} | ||
} | ||
} |