Skip to content

Commit

Permalink
feat: add compact block filter client
Browse files Browse the repository at this point in the history
temp 2

temp 3

temp 4

pass wallet to builder

remove async builder

make ip a type, bump bdk-kyoto, add connections

add more configurations

fix datadir builder

bump kyoto

add trait bound for logger

update logger

update bdk-ffi
  • Loading branch information
thunderbiscuit authored and rustaceanrob committed Nov 14, 2024
1 parent 8cf23df commit f57905a
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 43 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.bitcoindevkit
import org.rustbitcoin.bitcoin.Network

import kotlin.test.AfterTest
import kotlin.test.assertNotNull

import java.nio.file.Files
import java.nio.file.Paths
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.deleteRecursively

import org.junit.Test
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.runBlocking
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LiveKyotoTest {
private val descriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.SIGNET)
private val changeDescriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", Network.SIGNET)
private val ip: IpAddress = IpAddress.fromIpv4(68u, 47u, 229u, 218u)
private val peer: Peer = Peer(ip, null, false)
private val currentPath = Paths.get(".").toAbsolutePath().normalize()
private val persistenceFilePath = Files.createTempDirectory(currentPath, "tempDirPrefix_")

@OptIn(ExperimentalPathApi::class)
@AfterTest
fun cleanup() {
persistenceFilePath.deleteRecursively()
}

@Test
fun testKyoto() {
val conn: Connection = Connection.newInMemory()
val wallet: Wallet = Wallet(descriptor, changeDescriptor, Network.SIGNET, conn)
val peers = listOf(peer)
runBlocking {
val nodePair = buildLightClient(wallet, peers, 1u, null, persistenceFilePath.toString())
val client = nodePair.client
val node = nodePair.node
println("Node running")
runNode(node)
val updateOpt: Update? = client.update(null)
val update = assertNotNull(updateOpt)
wallet.applyUpdate(update)
assert(wallet.balance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address} and try again."
}
client.shutdown()
println("Test completed successfully")
}
}
}
19 changes: 0 additions & 19 deletions bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/KyotoTest.kt

This file was deleted.

49 changes: 49 additions & 0 deletions bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveKyotoTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.bitcoindevkit
import org.rustbitcoin.bitcoin.Network

import kotlinx.coroutines.runBlocking
import kotlin.test.Test
import kotlin.test.AfterTest
import kotlin.test.assertNotNull

import java.nio.file.Files
import java.nio.file.Paths
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.deleteRecursively

class LiveKyotoTest {
private val descriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.SIGNET)
private val changeDescriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", Network.SIGNET)
private val ip: IpAddress = IpAddress.fromIpv4(68u, 47u, 229u, 218u)
private val peer: Peer = Peer(ip, null, false)
private val currentPath = Paths.get(".").toAbsolutePath().normalize()
private val persistenceFilePath = Files.createTempDirectory(currentPath, "tempDirPrefix_")

@OptIn(ExperimentalPathApi::class)
@AfterTest
fun cleanup() {
persistenceFilePath.deleteRecursively()
}

@Test
fun testKyoto() {
val conn: Connection = Connection.newInMemory()
val wallet: Wallet = Wallet(descriptor, changeDescriptor, Network.SIGNET, conn)
val peers = listOf(peer)
runBlocking {
val nodePair = buildLightClient(wallet, peers, 1u, null, persistenceFilePath.toString())
val client = nodePair.client
val node = nodePair.node
println("Node running")
runNode(node)
val updateOpt: Update? = client.update(null)
val update = assertNotNull(updateOpt)
wallet.applyUpdate(update)
assert(wallet.balance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address} and try again."
}
client.shutdown()
println("Test completed successfully")
}
}
}
54 changes: 54 additions & 0 deletions bdk-python/tests/test_live_kyoto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from bdkpython import *
from bdkpython.bitcoin import *
import unittest
import os

network: Network = Network.SIGNET

ip: IpAddress = IpAddress.from_ipv4(68, 47, 229, 218)
peer: Peer = Peer(address=ip, port=None, v2_transport=False)

descriptor: Descriptor = Descriptor(
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
network=network
)
change_descriptor: Descriptor = Descriptor(
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)",
network=network
)

class LiveKyotoTest(unittest.IsolatedAsyncioTestCase):

def tearDown(self) -> None:
if os.path.exists("./bdk_persistence.sqlite"):
os.remove("./bdk_persistence.sqlite")
if os.path.exists("./data/signet/headers.db"):
os.remove("./data/signet/headers.db")
if os.path.exists("./data/signet/peers.db"):
os.remove("./data/signet/peers.db")

async def testKyoto(self) -> None:
connection: Connection = Connection.new_in_memory()
wallet: Wallet = Wallet(
descriptor,
change_descriptor,
network,
connection
)
peers = [peer]
node_pair: NodePair = build_light_client(wallet, peers, 1, None, ".")
client: LightClient = node_pair.client
node: LightNode = node_pair.node
run_node(node)
update: Update = await client.update(None)
self.assertIsNotNone(update, "Update is None. This should not be possible.")
wallet.apply_update(update)
self.assertGreater(
wallet.balance().total.to_sat(),
0,
f"Wallet balance must be greater than 0! Please send funds to {wallet.reveal_next_address(KeychainKind.EXTERNAL).address} and try again."
)
await client.shutdown()

if __name__ == "__main__":
unittest.main()

0 comments on commit f57905a

Please sign in to comment.