-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix tests to account for persistence
- Loading branch information
1 parent
98d5a1b
commit 69d1837
Showing
14 changed files
with
566 additions
and
419 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
100 changes: 56 additions & 44 deletions
100
bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTxBuilderTest.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 |
---|---|---|
@@ -1,61 +1,73 @@ | ||
package org.bitcoindevkit | ||
|
||
import kotlin.test.Ignore | ||
import java.io.File | ||
import kotlin.test.AfterTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
class LiveTxBuilderTest { | ||
@Ignore("The Esplora client's fullScan method requires a Wallet instead of a WalletNoPersist.") | ||
private val persistenceFilePath = run { | ||
val currentDirectory = System.getProperty("user.dir") | ||
"$currentDirectory/bdk_persistence.db" | ||
} | ||
|
||
@AfterTest | ||
fun cleanup() { | ||
val file = File(persistenceFilePath) | ||
if (file.exists()) { | ||
file.delete() | ||
} | ||
} | ||
|
||
@Test | ||
fun testTxBuilder() { | ||
val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) | ||
// val wallet = WalletNoPersist(descriptor, null, Network.TESTNET) | ||
val esploraClient = EsploraClient("https://mempool.space/testnet/api") | ||
// val update = esploraClient.fullScan(wallet, 10uL, 1uL) | ||
// wallet.applyUpdate(update) | ||
// println("Balance: ${wallet.getBalance().total}") | ||
// | ||
// assert(wallet.getBalance().total > 0uL) | ||
// | ||
// val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) | ||
// val psbt: PartiallySignedTransaction = TxBuilder() | ||
// .addRecipient(recipient.scriptPubkey(), 4200uL) | ||
// .feeRate(FeeRate.fromSatPerVb(2.0f)) | ||
// .finish(wallet) | ||
// | ||
// println(psbt.serialize()) | ||
// | ||
// assertTrue(psbt.serialize().startsWith("cHNi"), "PSBT should start with 'cHNi'") | ||
val wallet = Wallet(descriptor, null, persistenceFilePath, Network.TESTNET) | ||
val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/") | ||
val update = esploraClient.fullScan(wallet, 10uL, 1uL) | ||
wallet.applyUpdate(update) | ||
println("Balance: ${wallet.getBalance().total}") | ||
|
||
assert(wallet.getBalance().total > 0uL) | ||
|
||
val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) | ||
val psbt: PartiallySignedTransaction = TxBuilder() | ||
.addRecipient(recipient.scriptPubkey(), 4200uL) | ||
.feeRate(FeeRate.fromSatPerVb(2.0f)) | ||
.finish(wallet) | ||
|
||
println(psbt.serialize()) | ||
|
||
assertTrue(psbt.serialize().startsWith("cHNi"), "PSBT should start with 'cHNi'") | ||
} | ||
|
||
@Ignore("The Esplora client's fullScan method requires a Wallet instead of a WalletNoPersist.") | ||
@Test | ||
fun complexTxBuilder() { | ||
val externalDescriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET) | ||
val changeDescriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", Network.TESTNET) | ||
// val wallet = WalletNoPersist(externalDescriptor, changeDescriptor, Network.TESTNET) | ||
// val esploraClient = EsploraClient("https://mempool.space/testnet/api") | ||
// val update = esploraClient.fullScan(wallet, 10uL, 1uL) | ||
// wallet.applyUpdate(update) | ||
// println("Balance: ${wallet.getBalance().total}") | ||
// | ||
// assert(wallet.getBalance().total > 0uL) | ||
// | ||
// val recipient1: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) | ||
// val recipient2: Address = Address("tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", Network.TESTNET) | ||
// val allRecipients: List<ScriptAmount> = listOf( | ||
// ScriptAmount(recipient1.scriptPubkey(), 4200uL), | ||
// ScriptAmount(recipient2.scriptPubkey(), 4200uL), | ||
// ) | ||
// | ||
// val psbt: PartiallySignedTransaction = TxBuilder() | ||
// .setRecipients(allRecipients) | ||
// .feeRate(FeeRate.fromSatPerVb(4.0f)) | ||
// .changePolicy(ChangeSpendPolicy.CHANGE_FORBIDDEN) | ||
// .enableRbf() | ||
// .finish(wallet) | ||
// | ||
// wallet.sign(psbt) | ||
// assertTrue(psbt.serialize().startsWith("cHNi"), "PSBT should start with 'cHNi'") | ||
val wallet = Wallet(externalDescriptor, changeDescriptor, persistenceFilePath, Network.TESTNET) | ||
val esploraClient = EsploraClient("https://esplora.testnet.kuutamo.cloud/") | ||
val update = esploraClient.fullScan(wallet, 10uL, 1uL) | ||
wallet.applyUpdate(update) | ||
println("Balance: ${wallet.getBalance().total}") | ||
|
||
assert(wallet.getBalance().total > 0uL) | ||
|
||
val recipient1: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.TESTNET) | ||
val recipient2: Address = Address("tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", Network.TESTNET) | ||
val allRecipients: List<ScriptAmount> = listOf( | ||
ScriptAmount(recipient1.scriptPubkey(), 4200uL), | ||
ScriptAmount(recipient2.scriptPubkey(), 4200uL), | ||
) | ||
|
||
val psbt: PartiallySignedTransaction = TxBuilder() | ||
.setRecipients(allRecipients) | ||
.feeRate(FeeRate.fromSatPerVb(4.0f)) | ||
.changePolicy(ChangeSpendPolicy.CHANGE_FORBIDDEN) | ||
.enableRbf() | ||
.finish(wallet) | ||
|
||
wallet.sign(psbt) | ||
assertTrue(psbt.serialize().startsWith("cHNi"), "PSBT should start with 'cHNi'") | ||
} | ||
} |
Oops, something went wrong.