Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ jobs:
test:
name: "Build library and run unit tests"
runs-on: ubuntu-24.04

services:
bitcoin-regtest:
image: ghcr.io/thunderbiscuit/podman-regtest-infinity-pro:0.3.2
ports:
- 18443:18443
- 18444:18444
- 3002:3002
- 3003:3003
- 60401:60401
# The container initialization step will wait until everything is ready before allowing other steps to run
options: >-
--health-cmd "test $(bitcoin-cli -regtest -rpcuser=regtest -rpcpassword=password getblockcount) -gt 0"
--health-interval 10s
--health-timeout 5s
--health-retries 6

steps:
- name: "Check out PR branch"
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {

// Tests
testImplementation(kotlin("test"))
testImplementation("org.kotlinbitcointools:regtest-toolbox:0.1.0")
}

mavenPublishing {
Expand Down
55 changes: 55 additions & 0 deletions lib/src/test/kotlin/org/bitcoindevkit/CbfSyncTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.bitcoindevkit

import org.junit.jupiter.api.Nested
import org.kotlinbitcointools.regtesttoolbox.regenv.RegEnv
import kotlinx.coroutines.runBlocking
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.test.Test

class CbfSyncTest {
private val conn: Persister = Persister.newInMemory()

@Nested
inner class Success {
@Test
fun `Successful sync using a Kyoto client`() {
runBlocking {
val regtestEnv = RegEnv.connectTo(walletName = "faucet", username = "regtest", password = "password")

val wallet: Wallet = Wallet.createSingle(
descriptor = TEST_BIP86_DESCRIPTOR,
network = Network.REGTEST,
persister = conn
)
val newAddress = wallet.revealNextAddress(KeychainKind.EXTERNAL).address

regtestEnv.send(newAddress.toString(), 0.12345678, 2.0)
regtestEnv.mine(2)

val persistenceDir: Path = Paths.get("src/test/data").toAbsolutePath().normalize()
Files.createDirectories(persistenceDir)
val persistenceFilePath: Path = Files.createTempDirectory(persistenceDir, "kyoto_data_")

val ip: IpAddress = IpAddress.fromIpv4(127u, 0u, 0u, 1u)
val peer1: Peer = Peer(ip, 18444u, false)
val peers: List<Peer> = listOf(peer1)
val (client, node) = CbfBuilder()
.peers(peers)
.connections(1u)
.scanType(ScanType.Sync)
.dataDir(persistenceFilePath.toString())
.build(wallet)

node.run()
val update: Update = client.update()
wallet.applyUpdate(update)

val balance = wallet.balance().total.toSat()
assert(balance > 0uL)
client.shutdown()
}
}
}
}
Loading