-
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.
- Loading branch information
1 parent
74f277e
commit 1059578
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveElectrumClientTest.kt
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,35 @@ | ||
package org.bitcoindevkit | ||
|
||
import kotlin.test.Test | ||
|
||
private const val SIGNET_ELECTRUM_URL = "ssl://mempool.space:60602" | ||
|
||
class LiveElectrumClientTest { | ||
@Test | ||
fun testSyncedBalance() { | ||
val descriptor: Descriptor = Descriptor( | ||
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", | ||
Network.SIGNET | ||
) | ||
val wallet: Wallet = Wallet.newNoPersist(descriptor, null, Network.SIGNET) | ||
val electrumClient: ElectrumClient = ElectrumClient(SIGNET_ELECTRUM_URL) | ||
val fullScanRequest: FullScanRequest = wallet.startFullScan() | ||
val update = electrumClient.fullScan(fullScanRequest, 10uL, 10uL, false) | ||
wallet.applyUpdate(update) | ||
wallet.commit() | ||
println("Balance: ${wallet.getBalance().total.toSat()}") | ||
|
||
assert(wallet.getBalance().total.toSat() > 0uL) { | ||
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again." | ||
} | ||
|
||
println("Transactions count: ${wallet.transactions().count()}") | ||
val transactions = wallet.transactions().take(3) | ||
for (tx in transactions) { | ||
val sentAndReceived = wallet.sentAndReceived(tx.transaction) | ||
println("Transaction: ${tx.transaction.txid()}") | ||
println("Sent ${sentAndReceived.sent.toSat()}") | ||
println("Received ${sentAndReceived.received.toSat()}") | ||
} | ||
} | ||
} |