add tests, make single start command, and fix clightning race
This commit is contained in:
parent
5c938bb6d4
commit
dfd181e0be
6 changed files with 214 additions and 68 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
export COMPOSE_PROJECT_NAME=lnbits-legend
|
||||
|
||||
bitcoin-cli-sim(){
|
||||
bitcoin-cli-sim() {
|
||||
docker exec lnbits-legend-bitcoind-1 bitcoin-cli -rpcuser=lnbits -rpcpassword=lnbits -regtest $@
|
||||
}
|
||||
|
||||
|
|
@ -36,25 +36,27 @@ fund_lnd_node() {
|
|||
# args(i, j)
|
||||
connect_clightning_node() {
|
||||
pubkey=$(lightning-cli-sim $2 getinfo | jq -r '.id')
|
||||
lightning-cli-sim $1 connect $pubkey@lnbits-legend-clightning-$2-1
|
||||
lightning-cli-sim $1 connect $pubkey@lnbits-legend-clightning-$2-1 | jq -r '.id'
|
||||
}
|
||||
|
||||
lnbits-regtest-start(){
|
||||
lnbits-regtest-stop
|
||||
docker compose up -d --remove-orphans
|
||||
lnbits-regtest-init
|
||||
}
|
||||
|
||||
lnbits-regtest-start-log(){
|
||||
lnbits-regtest-stop
|
||||
docker compose up --remove-orphans
|
||||
lnbits-regtest-init
|
||||
}
|
||||
|
||||
lnbits-regtest-stop(){
|
||||
docker compose down --volumes
|
||||
# clean up lightning node data
|
||||
sudo rm -rf ./data/clightning-1 ./data/clightning-2 ./data/clightning-3 ./data/lnd-1 ./data/lnd-2 ./data/boltz/boltz.db
|
||||
sudo rm -rf ./data/clightning-1 ./data/clightning-2 ./data/lnd-1 ./data/lnd-2 ./data/boltz/boltz.db
|
||||
# recreate lightning node data folders preventing permission errors
|
||||
mkdir ./data/clightning-1 ./data/clightning-2 ./data/clightning-3 ./data/lnd-1 ./data/lnd-2
|
||||
mkdir ./data/clightning-1 ./data/clightning-2 ./data/lnd-1 ./data/lnd-2
|
||||
}
|
||||
|
||||
lnbits-regtest-restart(){
|
||||
|
|
@ -62,69 +64,101 @@ lnbits-regtest-restart(){
|
|||
lnbits-regtest-start
|
||||
}
|
||||
|
||||
lnbits-regtest-init(){
|
||||
lnbits-bitcoin-init(){
|
||||
echo "init_bitcoin_wallet..."
|
||||
bitcoin-cli-sim createwallet lnbits || bitcoin-cli-sim loadwallet lnbits echo "mining 150 blocks..."
|
||||
bitcoin-cli-sim createwallet lnbits || bitcoin-cli-sim loadwallet lnbits
|
||||
echo "mining 150 blocks..."
|
||||
bitcoin-cli-sim -generate 150 > /dev/null
|
||||
}
|
||||
|
||||
lnbits-regtest-init(){
|
||||
lnbits-bitcoin-init
|
||||
lnbits-lightning-sync
|
||||
lnbits-lightning-init
|
||||
wait-for-lnbits
|
||||
}
|
||||
|
||||
lnbits-lightning-sync(){
|
||||
wait-for-clightning-sync 1
|
||||
wait-for-clightning-sync 2
|
||||
wait-for-lnd-sync 1
|
||||
wait-for-lnd-sync 2
|
||||
}
|
||||
|
||||
lnbits-lightning-init(){
|
||||
|
||||
# create 10 UTXOs for each node
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
for i in 0 1 2 3 4; do
|
||||
fund_clightning_node 1
|
||||
fund_clightning_node 2
|
||||
fund_clightning_node 3
|
||||
fund_lnd_node 1
|
||||
fund_lnd_node 2
|
||||
done
|
||||
|
||||
echo "mining 5 blocks... and waiting for the nodes to catch up"
|
||||
bitcoin-cli-sim -generate 5 > /dev/null
|
||||
wait-for-lnd-sync 1
|
||||
wait-for-lnd-sync 2
|
||||
echo "mining 10 blocks..."
|
||||
bitcoin-cli-sim -generate 10 > /dev/null
|
||||
|
||||
echo "wait for 10s..."
|
||||
sleep 10 # else blockheight tests fail for cln
|
||||
|
||||
lnbits-lightning-sync
|
||||
|
||||
channel_size=16000000 # 0.016 btc
|
||||
balance_size_msat=7000000000 # 0.07 btc
|
||||
balance_size=8000000 # 0.08 btc
|
||||
balance_size_msat=8000000000 # 0.08 btc
|
||||
|
||||
# open channels 1 -> 2, 2 -> 3, 3 -> 1
|
||||
# TODO: quickfix, https://github.com/lnbits/legend-regtest-enviroment/issues/2
|
||||
# connect_clightning_node 1 3
|
||||
# lightning-cli-sim 1 fundchannel -k id=$(connect_clightning_node 1 2 | jq -r '.id') amount=$channel_size push_msat=$balance_size_msat
|
||||
# connect_clightning_node 2 1
|
||||
# lightning-cli-sim 2 fundchannel -k id=$(connect_clightning_node 2 3 | jq -r '.id') amount=$channel_size push_msat=$balance_size_msat
|
||||
# connect_clightning_node 3 2
|
||||
# lightning-cli-sim 3 fundchannel -k id=$(connect_clightning_node 3 1 | jq -r '.id') amount=$channel_size push_msat=$balance_size_msat
|
||||
|
||||
# lnd node for boltz
|
||||
lncli-sim 1 connect $(lightning-cli-sim 1 getinfo | jq -r '.id')@lnbits-legend-clightning-1-1
|
||||
lncli-sim 1 openchannel $(lncli-sim 1 listpeers | jq -r '.peers[0].pub_key') $channel_size 8000000
|
||||
|
||||
# lnd doesnt like more than 1 pending channel?
|
||||
# lnd-1 -> lnd-2
|
||||
lncli-sim 1 connect $(lncli-sim 2 getinfo | jq -r '.identity_pubkey')@lnbits-legend-lnd-2-1 > /dev/null
|
||||
echo "open channel from lnd-1 to lnd-2"
|
||||
lncli-sim 1 openchannel $(lncli-sim 2 getinfo | jq -r '.identity_pubkey') $channel_size $balance_size > /dev/null
|
||||
bitcoin-cli-sim -generate 10 > /dev/null
|
||||
echo "waiting for lnd to catch up..."
|
||||
wait-for-lnd-channel 1
|
||||
|
||||
# fund lnbits lnd channel
|
||||
lncli-sim 1 connect $(lncli-sim 2 getinfo | jq -r '.identity_pubkey')@lnbits-legend-lnd-2-1
|
||||
lncli-sim 1 openchannel $(lncli-sim 1 listpeers | jq -r '.peers[1].pub_key') $channel_size 8000000
|
||||
|
||||
# lnd-1 -> cln-1
|
||||
lncli-sim 1 connect $(lightning-cli-sim 1 getinfo | jq -r '.id')@lnbits-legend-clightning-1-1 > /dev/null
|
||||
echo "open channel from lnd-1 to cln-1"
|
||||
lncli-sim 1 openchannel $(lightning-cli-sim 1 getinfo | jq -r '.id') $channel_size $balance_size > /dev/null
|
||||
bitcoin-cli-sim -generate 10 > /dev/null
|
||||
echo "waiting for lnd to catch up..."
|
||||
wait-for-lnd-channel 1
|
||||
|
||||
|
||||
# lnd node for lnbits
|
||||
lncli-sim 2 connect $(lightning-cli-sim 1 getinfo | jq -r '.id')@lnbits-legend-clightning-1-1
|
||||
lncli-sim 2 openchannel $(lncli-sim 2 listpeers | jq -r '.peers[0].pub_key') $channel_size 8000000
|
||||
|
||||
echo "waiting for lnd to catch up..."
|
||||
# lnd-2 -> cln-2
|
||||
lncli-sim 2 connect $(lightning-cli-sim 2 getinfo | jq -r '.id')@lnbits-legend-clightning-2-1 > /dev/null
|
||||
echo "open channel from lnd-2 to cln-2"
|
||||
lncli-sim 2 openchannel $(lightning-cli-sim 2 getinfo | jq -r '.id') $channel_size $balance_size > /dev/null
|
||||
bitcoin-cli-sim -generate 10 > /dev/null
|
||||
wait-for-lnd-channel 2
|
||||
|
||||
# TODO: eclair nodes?
|
||||
# cln-1 -> cln-2
|
||||
peerid=$(connect_clightning_node 1 2)
|
||||
echo "open channel from cln-1 to cln-2"
|
||||
lightning-cli-sim 1 fundchannel -k id=$peerid amount=$channel_size push_msat=$balance_size_msat > /dev/null
|
||||
|
||||
bitcoin-cli-sim -generate 10 > /dev/null
|
||||
|
||||
wait-for-clightning-channel 1
|
||||
wait-for-clightning-channel 2
|
||||
|
||||
lnbits-lightning-sync
|
||||
|
||||
}
|
||||
|
||||
wait-for-lnbits(){
|
||||
while true; do
|
||||
statuscode=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:5000")
|
||||
if [[ "$statuscode" == "200" ]]; then
|
||||
break
|
||||
echo "lnbits is online!"
|
||||
fi
|
||||
echo "waiting for lnbits to come online..."
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
wait-for-lnd-channel(){
|
||||
while true; do
|
||||
pending=$(lncli-sim $1 pendingchannels | jq -r '.pending_open_channels | length')
|
||||
echo "lnd-$1 pendingchannels: $pending"
|
||||
if [[ "$pending" == "0" ]]; then
|
||||
break
|
||||
fi
|
||||
|
|
@ -134,10 +168,41 @@ wait-for-lnd-channel(){
|
|||
|
||||
wait-for-lnd-sync(){
|
||||
while true; do
|
||||
if [[ "$(lncli-sim $1 getinfo 2>&1 | jq -r '.synced_to_chain')" == "true" ]]; then
|
||||
if [[ "$(lncli-sim $1 getinfo 2>&1 | jq -r '.synced_to_chain' 2> /dev/null)" == "true" ]]; then
|
||||
echo "lnd-$1 is synced!"
|
||||
break
|
||||
fi
|
||||
echo "waiting for lnd-$1 to sync..."
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
wait-for-clightning-channel(){
|
||||
while true; do
|
||||
pending=$(lightning-cli-sim $1 getinfo | jq -r '.num_pending_channels | length')
|
||||
echo "cln-$1 pendingchannels: $pending"
|
||||
if [[ "$pending" == "0" ]]; then
|
||||
if [[ "$(lightning-cli-sim $1 getinfo 2>&1 | jq -r '.warning_bitcoind_sync' 2> /dev/null)" == "null" ]]; then
|
||||
if [[ "$(lightning-cli-sim $1 getinfo 2>&1 | jq -r '.warning_lightningd_sync' 2> /dev/null)" == "null" ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
wait-for-clightning-sync(){
|
||||
while true; do
|
||||
if [[ ! "$(lightning-cli-sim $1 getinfo 2>&1 | jq -r '.id' 2> /dev/null)" == "null" ]]; then
|
||||
if [[ "$(lightning-cli-sim $1 getinfo 2>&1 | jq -r '.warning_bitcoind_sync' 2> /dev/null)" == "null" ]]; then
|
||||
if [[ "$(lightning-cli-sim $1 getinfo 2>&1 | jq -r '.warning_lightningd_sync' 2> /dev/null)" == "null" ]]; then
|
||||
echo "cln-$1 is synced!"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo "waiting for cln-$1 to sync..."
|
||||
sleep 1
|
||||
done
|
||||
sleep 5
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue