Skip to content

Commit

Permalink
tests: update jvm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Oct 9, 2023
1 parent 861c75e commit bbaa606
Showing 1 changed file with 15 additions and 51 deletions.
66 changes: 15 additions & 51 deletions bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/JvmLibTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,26 @@ import java.nio.file.Files
*/
class JvmLibTest {

private fun getTestDataDir(): String {
return Files.createTempDirectory("bdk-test").toString()
}

private fun cleanupTestDataDir(testDataDir: String) {
File(testDataDir).deleteRecursively()
}

class LogProgress : Progress {
private val log: Logger = LoggerFactory.getLogger(JvmLibTest::class.java)

override fun update(progress: Float, message: String?) {
log.debug("Syncing...")
}
}

private val descriptor = Descriptor("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", Network.TESTNET)

private val databaseConfig = DatabaseConfig.Memory

private val blockchainConfig = BlockchainConfig.Electrum(
ElectrumConfig(
"ssl://electrum.blockstream.info:60002",
null,
5u,
null,
100u,
true,
)
)

@Test
fun memoryWalletNewAddress() {
val wallet = Wallet(descriptor, null, Network.TESTNET, databaseConfig)
val address = wallet.getAddress(AddressIndex.New).address.asString()
assertEquals("tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e", address)
fun testNetwork() {
val signetNetwork = Network.SIGNET
}

@Test
fun memoryWalletSyncGetBalance() {
val wallet = Wallet(descriptor, null, Network.TESTNET, databaseConfig)
val blockchain = Blockchain(blockchainConfig)
wallet.sync(blockchain, LogProgress())
val balance: Balance = wallet.getBalance()
assertTrue(balance.total > 0u)
fun testDescriptorBip86() {
val mnemonic = Mnemonic(WordCount.WORDS12)
val descriptorSecretKey = DescriptorSecretKey(Network.TESTNET, mnemonic, null)
val descriptor = Descriptor.newBip86(descriptorSecretKey, KeychainKind.EXTERNAL, Network.TESTNET)
}

@Test
fun sqliteWalletSyncGetBalance() {
val testDataDir = getTestDataDir() + "/bdk-wallet.sqlite"
val databaseConfig = DatabaseConfig.Sqlite(SqliteDbConfiguration(testDataDir))
val wallet = Wallet(descriptor, null, Network.TESTNET, databaseConfig)
val blockchain = Blockchain(blockchainConfig)
wallet.sync(blockchain, LogProgress())
val balance: Balance = wallet.getBalance()
assertTrue(balance.total > 0u)
cleanupTestDataDir(testDataDir)
}
fun testUsedWallet() {
val descriptor1 = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET)
// val mnemonic = Mnemonic(WordCount.WORDS12)
// val descriptorSecretKey = DescriptorSecretKey(Network.TESTNET, mnemonic, null)
// val descriptor = Descriptor.newBip86(descriptorSecretKey, KeychainKind.EXTERNAL, Network.TESTNET)
val wallet = Wallet(descriptor1, null, Network.TESTNET, WalletType.MEMORY)
val (index, address, keychain) = wallet.getAddress(AddressIndex.LastUnused)
println("Address ${address.asString()} at index $index")
}
}

0 comments on commit bbaa606

Please sign in to comment.