Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderwiederin committed Nov 6, 2023
1 parent 8a91d0c commit bf507b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
3 changes: 3 additions & 0 deletions bindings/kotlin/ldk-node-jvm/lib/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
interval: 5s
timeout: 10s
retries: 5

electrs:
image: blockstream/esplora:electrs-latest
platform: linux/amd64
Expand All @@ -39,6 +40,8 @@ services:
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
]
ports:
- "3002:3002"
networks:
- bitcoin-electrs

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/*
* This Kotlin source file was generated by the Gradle 'init' task.
*/
package org.lightningdevkit.ldknode

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import kotlin.UInt
import kotlin.io.path.createTempDirectory
import kotlin.test.Test
import kotlin.test.assertEquals

fun runCommandAndWait(vararg cmd: String): String {
Expand All @@ -25,8 +22,8 @@ fun runCommandAndWait(vararg cmd: String): String {
}

fun mine(blocks: UInt): String {
val address = runCommandAndWait("bitcoin-cli", "-regtest", "getnewaddress")
val output = runCommandAndWait("bitcoin-cli", "-regtest", "generatetoaddress", blocks.toString(), address)
val address = runCommandAndWait("docker", "exec", "lib-bitcoin-1", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getnewaddress")
val output = runCommandAndWait("docker", "exec", "lib-bitcoin-1", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "generatetoaddress", blocks.toString(), address)
println("Mining output: $output")
val re = Regex("\n.+\n\\]$")
val lastBlock = re.find(output)!!.value.replace("]", "").replace("\"", "").replace("\n", "").trim()
Expand All @@ -41,17 +38,10 @@ fun mineAndWait(esploraEndpoint: String, blocks: UInt) {

fun sendToAddress(address: String, amountSats: UInt): String {
val amountBtc = amountSats.toDouble() / 100000000.0
val output = runCommandAndWait("bitcoin-cli", "-regtest", "sendtoaddress", address, amountBtc.toString())
val output = runCommandAndWait("docker", "exec", "lib-bitcoin-1", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "sendtoaddress", address, amountBtc.toString())
return output
}

fun setup() {
runCommandAndWait("bitcoin-cli", "-regtest", "createwallet", "ldk_node_test")
runCommandAndWait("bitcoin-cli", "-regtest", "loadwallet", "ldk_node_test", "true")
mine(101u)
Thread.sleep(5_000)
}

fun waitForTx(esploraEndpoint: String, txid: String) {
var esploraPickedUpTx = false
val re = Regex("\"txid\":\"$txid\"")
Expand Down Expand Up @@ -83,8 +73,15 @@ fun waitForBlock(esploraEndpoint: String, blockHash: String) {
Thread.sleep(500)
}
}

class LibraryTest {
@BeforeEach
fun setup() {
runCommandAndWait("docker", "exec", "lib-bitcoin-1", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "createwallet", "ldk_node_test")
runCommandAndWait("docker", "exec", "lib-bitcoin-1", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "loadwallet", "ldk_node_test", "true")
mine(101u)
Thread.sleep(5_000)
}

@Test fun fullCycle() {
val esploraEndpoint = "http://127.0.0.1:3002"
setup()
Expand Down

0 comments on commit bf507b2

Please sign in to comment.