Skip to content

Commit 7750dc8

Browse files
committed
add network script for integration testing with nigiri (LND and CLN)
Signed-off-by: Gustavo Chain <me@qustavo.cc>
1 parent 2ae53fb commit 7750dc8

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

scripts/network.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
# network.sh — start/stop Docker network for integration tests using nigiri
5+
6+
usage() {
7+
cat <<EOF
8+
Usage: $(basename "$0") <command>
9+
10+
Commands:
11+
start Start bitcoind + two LND nodes (alice, bob)
12+
stop Stop and remove all containers and the network
13+
14+
Examples:
15+
$(basename "$0") start
16+
$(basename "$0") stop
17+
EOF
18+
}
19+
20+
cmd_start() {
21+
echo "Starting l402 integration network..."
22+
nigiri start --ln
23+
echo
24+
25+
echo -n "✓ Waiting for LND to become active "
26+
until [[ $(nigiri lnd state | jq -r .state) == 'SERVER_ACTIVE' ]]; do
27+
sleep 1
28+
echo -n "."
29+
done
30+
echo
31+
32+
echo -n "✓ Waiting for LND to sync with the chain "
33+
until [[ $(nigiri lnd getinfo | jq -r .synced_to_chain) == 'true' ]]; do
34+
sleep 1
35+
echo -n "."
36+
done
37+
echo
38+
39+
echo -n "✓ Waiting for CLN to be ready "
40+
until [[ $(nigiri cln getinfo | jq -r .blockheight) != 0 ]]; do
41+
sleep 1
42+
echo -n "."
43+
done
44+
echo
45+
46+
echo -n "✓ Funding onchain wallets"
47+
nigiri faucet lnd 1
48+
nigiri faucet cln 1
49+
50+
echo "Opening channel LND -> CLN"
51+
CLN_PUBKEY=$(nigiri cln getinfo | jq -r .id)
52+
nigiri lnd connect $CLN_PUBKEY@cln:9935
53+
nigiri lnd openchannel --node_key $CLN_PUBKEY --local_amt 10000000
54+
nigiri rpc -generate 6 # mature the channel
55+
56+
echo -n "Waiting for channel to be active "
57+
until [[ $(nigiri lnd listchannels | jq '.channels[0].active') == true ]]; do
58+
sleep 1
59+
echo -n "."
60+
done
61+
echo
62+
63+
echo "Sending 10k sats from LND to CLN"
64+
INVOICE=$(nigiri cln invoice 10000000 $RANDOM test | jq -r .bolt11)
65+
nigiri lnd payinvoice $INVOICE -f
66+
67+
echo "✓ Network ready to test"
68+
}
69+
70+
cmd_stop() {
71+
echo "Stopping l402 integration network..."
72+
nigiri stop --delete
73+
echo "✓ Network stopped"
74+
}
75+
76+
main() {
77+
if [[ $# -eq 0 ]]; then
78+
usage
79+
exit 1
80+
fi
81+
82+
case "$1" in
83+
start)
84+
cmd_start
85+
;;
86+
stop)
87+
cmd_stop
88+
;;
89+
-h|--help|help)
90+
usage
91+
exit 0
92+
;;
93+
*)
94+
echo "Error: unknown command '$1'"
95+
usage
96+
exit 1
97+
;;
98+
esac
99+
}
100+
101+
main "$@"

0 commit comments

Comments
 (0)