Skip to content

Commit 52c9694

Browse files
add github workflow to run kotlin tests against docker
1 parent 476446f commit 52c9694

File tree

4 files changed

+152
-17
lines changed

4 files changed

+152
-17
lines changed

.github/workflows/kotlin.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Continuous Integration Checks - Kotlin
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
check-kotlin:
7+
runs-on: ubuntu-latest
8+
9+
env:
10+
LDK_NODE_JVM_DIR: bindings/kotlin/ldk-node-jvm
11+
LDK_NODE_ANDROID_DIR: bindings/kotlin/ldk-node-android
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK
18+
uses: actions/setup-java@v3
19+
with:
20+
distribution: temurin
21+
java-version: 11
22+
23+
- name: Run ktlintCheck on ldk-node-jvm
24+
run: |
25+
cd $LDK_NODE_JVM_DIR
26+
./gradlew ktlintCheck
27+
28+
- name: Run ktlintCheck on ldk-node-android
29+
run: |
30+
cd $LDK_NODE_ANDROID_DIR
31+
./gradlew ktlintCheck
32+
33+
- name: Generate Kotlin JVM
34+
run: ./scripts/uniffi_bindgen_generate_kotlin.sh
35+
36+
- name: Start bitcoind and electrs
37+
run: docker compose up -d
38+
39+
- name: Run ldk-node-jvm tests
40+
run: |
41+
cd $LDK_NODE_JVM_DIR
42+
./gradlew test -Penv=ci
43+
44+
- name: Run ldk-node-android tests
45+
run: |
46+
cd $LDK_NODE_ANDROID_DIR
47+
./gradlew test

bindings/kotlin/ldk-node-jvm/lib/build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ tasks.named<Test>("test") {
6464
}
6565
}
6666

67+
tasks.test {
68+
doFirst {
69+
if (project.hasProperty("env") && project.property("env") == "ci") {
70+
environment("BITCOIN_CLI_BIN", "docker exec ldk-node-bitcoin-1 bitcoin-cli")
71+
environment("BITCOIND_RPC_USER", "user")
72+
environment("BITCOIND_RPC_PASSWORD", "pass")
73+
environment("ESPLORA_ENDPOINT", "http://127.0.0.1:3002")
74+
} else {
75+
// Adapt these to your local environment
76+
environment("BITCOIN_CLI_BIN", "bitcoin-cli")
77+
environment("BITCOIND_RPC_USER", "")
78+
environment("BITCOIND_RPC_PASSWORD", "")
79+
environment("ESPLORA_ENDPOINT", "http://127.0.0.1:3002")
80+
}
81+
}
82+
}
83+
6784
afterEvaluate {
6885
publishing {
6986
publications {

bindings/kotlin/ldk-node-jvm/lib/src/test/kotlin/org/lightningdevkit/ldknode/LibraryTest.kt

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.lightningdevkit.ldknode
22

3-
import kotlin.UInt
4-
import kotlin.test.Test
5-
import kotlin.test.assertEquals
6-
import kotlin.io.path.createTempDirectory
3+
import org.junit.jupiter.api.BeforeAll
4+
import org.junit.jupiter.api.Test
5+
import org.junit.jupiter.api.TestInstance
76
import java.net.URI
87
import java.net.http.HttpClient
98
import java.net.http.HttpRequest
@@ -23,9 +22,26 @@ fun runCommandAndWait(vararg cmd: String): String {
2322
return stdout + stderr
2423
}
2524

25+
fun bitcoinCli(vararg cmd: String): String {
26+
val bitcoinCliBin = System.getenv("BITCOIN_CLI_BIN")?.split(" ") ?: listOf("bitcoin-cli")
27+
val bitcoinDRpcUser = System.getenv("BITCOIND_RPC_USER") ?: ""
28+
val bitcoinDRpcPassword = System.getenv("BITCOIND_RPC_PASSWORD") ?: ""
29+
30+
val baseCommand = bitcoinCliBin + "-regtest"
31+
32+
val rpcAuth = if (bitcoinDRpcUser.isNotBlank() && bitcoinDRpcPassword.isNotBlank()) {
33+
listOf("-rpcuser=$bitcoinDRpcUser", "-rpcpassword=$bitcoinDRpcPassword")
34+
} else {
35+
emptyList()
36+
}
37+
38+
val fullCommand = baseCommand + rpcAuth + cmd.toList()
39+
return runCommandAndWait(*fullCommand.toTypedArray())
40+
}
41+
2642
fun mine(blocks: UInt): String {
27-
val address = runCommandAndWait("bitcoin-cli", "-regtest", "getnewaddress")
28-
val output = runCommandAndWait("bitcoin-cli", "-regtest", "generatetoaddress", blocks.toString(), address)
43+
val address = bitcoinCli("getnewaddress")
44+
val output = bitcoinCli("generatetoaddress", blocks.toString(), address)
2945
println("Mining output: $output")
3046
val re = Regex("\n.+\n\\]$")
3147
val lastBlock = re.find(output)!!.value.replace("]", "").replace("\"", "").replace("\n", "").trim()
@@ -40,17 +56,10 @@ fun mineAndWait(esploraEndpoint: String, blocks: UInt) {
4056

4157
fun sendToAddress(address: String, amountSats: UInt): String {
4258
val amountBtc = amountSats.toDouble() / 100000000.0
43-
val output = runCommandAndWait("bitcoin-cli", "-regtest", "sendtoaddress", address, amountBtc.toString())
59+
val output = bitcoinCli("sendtoaddress", address, amountBtc.toString())
4460
return output
4561
}
4662

47-
fun setup() {
48-
runCommandAndWait("bitcoin-cli", "-regtest", "createwallet", "ldk_node_test")
49-
runCommandAndWait("bitcoin-cli", "-regtest", "loadwallet", "ldk_node_test", "true")
50-
mine(101u)
51-
Thread.sleep(5_000)
52-
}
53-
5463
fun waitForTx(esploraEndpoint: String, txid: String) {
5564
var esploraPickedUpTx = false
5665
val re = Regex("\"txid\":\"$txid\"")
@@ -83,11 +92,20 @@ fun waitForBlock(esploraEndpoint: String, blockHash: String) {
8392
}
8493
}
8594

95+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
8696
class LibraryTest {
87-
@Test fun fullCycle() {
88-
val esploraEndpoint = "http://127.0.0.1:3002"
89-
setup()
9097

98+
val esploraEndpoint = System.getenv("ESPLORA_ENDPOINT")
99+
100+
@BeforeAll
101+
fun setup() {
102+
bitcoinCli("createwallet", "ldk_node_test")
103+
bitcoinCli("loadwallet", "ldk_node_test", "true")
104+
mine(101u)
105+
Thread.sleep(5_000)
106+
}
107+
108+
@Test fun fullCycle() {
91109
val tmpDir1 = createTempDirectory("ldk_node").toString()
92110
println("Random dir 1: $tmpDir1")
93111
val tmpDir2 = createTempDirectory("ldk_node").toString()

docker-compose.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
version: '3'
2+
3+
services:
4+
bitcoin:
5+
image: blockstream/bitcoind:24.1
6+
platform: linux/amd64
7+
command:
8+
[
9+
"bitcoind",
10+
"-printtoconsole",
11+
"-regtest=1",
12+
"-rpcallowip=0.0.0.0/0",
13+
"-rpcbind=0.0.0.0",
14+
"-rpcuser=user",
15+
"-rpcpassword=pass",
16+
"-fallbackfee=0.00001"
17+
]
18+
ports:
19+
- "18443:18443" # Regtest RPC port
20+
- "18444:18444" # Regtest P2P port
21+
networks:
22+
- bitcoin-electrs
23+
healthcheck:
24+
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
25+
interval: 5s
26+
timeout: 10s
27+
retries: 5
28+
29+
electrs:
30+
image: blockstream/esplora:electrs-cd9f90c115751eb9d2bca9a4da89d10d048ae931
31+
platform: linux/amd64
32+
depends_on:
33+
bitcoin:
34+
condition: service_healthy
35+
command:
36+
[
37+
"/app/electrs_bitcoin/bin/electrs",
38+
"-vvvv",
39+
"--timestamp",
40+
"--jsonrpc-import",
41+
"--cookie=user:pass",
42+
"--network=regtest",
43+
"--daemon-rpc-addr=bitcoin:18443",
44+
"--http-addr=0.0.0.0:3002"
45+
]
46+
ports:
47+
- "3002:3002"
48+
networks:
49+
- bitcoin-electrs
50+
51+
networks:
52+
bitcoin-electrs:
53+
driver: bridge

0 commit comments

Comments
 (0)