1
- /*
2
- * This Kotlin source file was generated by the Gradle 'init' task.
3
- */
4
1
package org.lightningdevkit.ldknode
5
2
6
3
import kotlin.UInt
@@ -11,6 +8,8 @@ import java.net.URI
11
8
import java.net.http.HttpClient
12
9
import java.net.http.HttpRequest
13
10
import java.net.http.HttpResponse
11
+ import kotlin.io.path.createTempDirectory
12
+ import kotlin.test.assertEquals
14
13
15
14
fun runCommandAndWait (vararg cmd : String ): String {
16
15
println (" Running command \" ${cmd.joinToString(" " )} \" " )
@@ -29,7 +28,7 @@ fun mine(blocks: UInt): String {
29
28
val output = runCommandAndWait(" bitcoin-cli" , " -regtest" , " generatetoaddress" , blocks.toString(), address)
30
29
println (" Mining output: $output " )
31
30
val re = Regex (" \n .+\n\\ ]$" )
32
- val lastBlock = re.find(output)!! .value.replace(" ]" ," " ).replace(" \" " , " " ).replace(" \n " ," " ).trim()
31
+ val lastBlock = re.find(output)!! .value.replace(" ]" , " " ).replace(" \" " , " " ).replace(" \n " , " " ).trim()
33
32
println (" Last block: $lastBlock " )
34
33
return lastBlock
35
34
}
@@ -54,32 +53,32 @@ fun setup() {
54
53
55
54
fun waitForTx (esploraEndpoint : String , txid : String ) {
56
55
var esploraPickedUpTx = false
57
- val re = Regex (" \" txid\" :\" $txid \" " );
56
+ val re = Regex (" \" txid\" :\" $txid \" " )
58
57
while (! esploraPickedUpTx) {
59
58
val client = HttpClient .newBuilder().build()
60
59
val request = HttpRequest .newBuilder()
61
60
.uri(URI .create(esploraEndpoint + " /tx/" + txid))
62
- .build();
61
+ .build()
63
62
64
- val response = client.send(request, HttpResponse .BodyHandlers .ofString());
63
+ val response = client.send(request, HttpResponse .BodyHandlers .ofString())
65
64
66
- esploraPickedUpTx = re.containsMatchIn(response.body());
65
+ esploraPickedUpTx = re.containsMatchIn(response.body())
67
66
Thread .sleep(500 )
68
67
}
69
68
}
70
69
71
70
fun waitForBlock (esploraEndpoint : String , blockHash : String ) {
72
71
var esploraPickedUpBlock = false
73
- val re = Regex (" \" in_best_chain\" :true" );
72
+ val re = Regex (" \" in_best_chain\" :true" )
74
73
while (! esploraPickedUpBlock) {
75
74
val client = HttpClient .newBuilder().build()
76
75
val request = HttpRequest .newBuilder()
77
76
.uri(URI .create(esploraEndpoint + " /block/" + blockHash + " /status" ))
78
- .build();
77
+ .build()
79
78
80
- val response = client.send(request, HttpResponse .BodyHandlers .ofString());
79
+ val response = client.send(request, HttpResponse .BodyHandlers .ofString())
81
80
82
- esploraPickedUpBlock = re.containsMatchIn(response.body());
81
+ esploraPickedUpBlock = re.containsMatchIn(response.body())
83
82
Thread .sleep(500 )
84
83
}
85
84
}
@@ -172,7 +171,7 @@ class LibraryTest {
172
171
173
172
val fundingTxid = when (channelPendingEvent1) {
174
173
is Event .ChannelPending -> channelPendingEvent1.fundingTxo.txid
175
- else -> return
174
+ else -> return
176
175
}
177
176
178
177
waitForTx(esploraEndpoint, fundingTxid)
@@ -202,7 +201,7 @@ class LibraryTest {
202
201
203
202
val channelId = when (channelReadyEvent2) {
204
203
is Event .ChannelReady -> channelReadyEvent2.channelId
205
- else -> return
204
+ else -> return
206
205
}
207
206
208
207
val invoice = node2.receivePayment(2500000u , " asdf" , 9217u )
0 commit comments