mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 01:43:50 +01:00
Improve Lightning test scripts (#3435)
This commit is contained in:
parent
300d84c5d8
commit
3fa694c65f
@ -249,7 +249,9 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "35531:8080"
|
- "35531:8080"
|
||||||
expose:
|
expose:
|
||||||
|
- "8080"
|
||||||
- "9735"
|
- "9735"
|
||||||
|
- "10009"
|
||||||
volumes:
|
volumes:
|
||||||
- "merchant_lnd_datadir:/data"
|
- "merchant_lnd_datadir:/data"
|
||||||
- "bitcoin_datadir:/deps/.bitcoin"
|
- "bitcoin_datadir:/deps/.bitcoin"
|
||||||
@ -274,7 +276,7 @@ services:
|
|||||||
bitcoind.rpcpass=DwubwWsoo3
|
bitcoind.rpcpass=DwubwWsoo3
|
||||||
bitcoind.zmqpubrawblock=tcp://bitcoind:28332
|
bitcoind.zmqpubrawblock=tcp://bitcoind:28332
|
||||||
bitcoind.zmqpubrawtx=tcp://bitcoind:28333
|
bitcoind.zmqpubrawtx=tcp://bitcoind:28333
|
||||||
externalip=customer_lnd:10009
|
externalip=customer_lnd:9735
|
||||||
bitcoin.defaultchanconfs=1
|
bitcoin.defaultchanconfs=1
|
||||||
no-macaroons=1
|
no-macaroons=1
|
||||||
debuglevel=debug
|
debuglevel=debug
|
||||||
@ -284,6 +286,7 @@ services:
|
|||||||
- "35532:8080"
|
- "35532:8080"
|
||||||
expose:
|
expose:
|
||||||
- "8080"
|
- "8080"
|
||||||
|
- "9735"
|
||||||
- "10009"
|
- "10009"
|
||||||
volumes:
|
volumes:
|
||||||
- "customer_lnd_datadir:/root/.lnd"
|
- "customer_lnd_datadir:/root/.lnd"
|
||||||
|
4
BTCPayServer.Tests/docker-customer-lncli.sh
Executable file
4
BTCPayServer.Tests/docker-customer-lncli.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
container_id="$(docker ps -q --filter label=com.docker.compose.project=btcpayservertests --filter label=com.docker.compose.service=customer_lnd)"
|
||||||
|
docker exec -ti $container_id lncli --no-macaroons --rpcserver localhost:10008 "$@"
|
@ -3,67 +3,102 @@
|
|||||||
# Commands
|
# Commands
|
||||||
BCMD=./docker-bitcoin-cli.sh
|
BCMD=./docker-bitcoin-cli.sh
|
||||||
GCMD=./docker-bitcoin-generate.sh
|
GCMD=./docker-bitcoin-generate.sh
|
||||||
CCMD=./docker-customer-lightning-cli.sh
|
C_LN=./docker-customer-lncli.sh
|
||||||
MCMD=./docker-merchant-lightning-cli.sh
|
M_LN=./docker-merchant-lncli.sh
|
||||||
|
C_CL=./docker-customer-lightning-cli.sh
|
||||||
|
M_CL=./docker-merchant-lightning-cli.sh
|
||||||
|
|
||||||
function channel_count () {
|
function channel_count () {
|
||||||
local cmd=$1; local id=$2;
|
local cmd="$1"; local id="$2";
|
||||||
local count=$($cmd listchannels | jq -r ".channels | map(select(.destination == \"$id\")) | length | tonumber") 2>/dev/null
|
if [[ $cmd =~ "lightning-cli" ]]; then
|
||||||
|
local count=$($cmd listchannels | jq -r ".channels | map(select(.destination == \"$id\" and .active == true)) | length | tonumber") 2>/dev/null
|
||||||
|
elif [[ $cmd =~ "lncli" ]]; then
|
||||||
|
local count=$($cmd listchannels | jq -r ".channels | map(select(.remote_pubkey == \"$id\" and .active == true)) | length | tonumber") 2>/dev/null
|
||||||
|
fi
|
||||||
return $count
|
return $count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function connect () {
|
||||||
|
local cmd="$1"; local uri="$2"; local desc="$3";
|
||||||
|
local connid=`$cmd connect $uri` 2>/dev/null
|
||||||
|
if [[ $connid =~ "already connected" ]]; then
|
||||||
|
printf "%s %s\n\r" "✅" "$desc"
|
||||||
|
else
|
||||||
|
printf "%s %s\n\r" $([[ $uri =~ ^$(echo $connid | jq -r '.id')* ]] && echo "✅" || echo "❌") "$desc"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function create_channel () {
|
function create_channel () {
|
||||||
local cmd=$1; local id=$2;
|
local cmd="$1"; local id="$2"; local desc="$3"; local opts="$4";
|
||||||
local btcaddr=$($cmd newaddr | jq -r '.address')
|
channel_count "$cmd" "$id"
|
||||||
$BCMD sendtoaddress $btcaddr 0.15 >/dev/null
|
|
||||||
$GCMD 10 >/dev/null
|
|
||||||
local fundres=$($cmd fundchannel $id 14500000 5000 | jq -r '.channel_id')
|
|
||||||
$GCMD 20 >/dev/null
|
|
||||||
sleep 2
|
|
||||||
channel_count $cmd $id
|
|
||||||
local count=$?
|
local count=$?
|
||||||
return $count
|
if [[ $count -eq 0 ]]; then
|
||||||
|
# fund onchain wallet
|
||||||
|
if [[ $cmd =~ "lightning-cli" ]]; then
|
||||||
|
local btcaddr=$($cmd newaddr | jq -r '.bech32')
|
||||||
|
elif [[ $cmd =~ "lncli" ]]; then
|
||||||
|
local btcaddr=$($cmd newaddress p2wkh | jq -r '.address')
|
||||||
|
fi
|
||||||
|
$BCMD sendtoaddress $btcaddr 0.615 >/dev/null
|
||||||
|
$GCMD 10 >/dev/null
|
||||||
|
# open channel
|
||||||
|
if [[ $cmd =~ "lightning-cli" ]]; then
|
||||||
|
$cmd -k fundchannel id=$id amount=5000000 push_msat=2450000 $opts >/dev/null
|
||||||
|
elif [[ $cmd =~ "lncli" ]]; then
|
||||||
|
$cmd openchannel $id 5000000 2450000 $opts >/dev/null
|
||||||
|
fi
|
||||||
|
$GCMD 20 >/dev/null
|
||||||
|
sleep 1
|
||||||
|
channel_count "$cmd" "$id"
|
||||||
|
local count=$?
|
||||||
|
fi
|
||||||
|
printf "%s %s\n\r" $([[ $count -gt 0 ]] && echo "✅" || echo "❌") "$desc"
|
||||||
}
|
}
|
||||||
|
|
||||||
# General information
|
# Nodes
|
||||||
cinfo=$($CCMD getinfo | jq '.' 2>/dev/null)
|
c_cl_info=$($C_CL getinfo | jq '.' 2>/dev/null)
|
||||||
minfo=$($MCMD getinfo | jq '.' 2>/dev/null)
|
m_cl_info=$($M_CL getinfo | jq '.' 2>/dev/null)
|
||||||
cid=$(echo $cinfo | jq -r '.id')
|
c_cl_id=$(echo $c_cl_info | jq -r '.id')
|
||||||
mid=$(echo $minfo | jq -r '.id')
|
m_cl_id=$(echo $m_cl_info | jq -r '.id')
|
||||||
caddr=$(echo $cinfo | jq -r '.address[] | "\(.address):\(.port)"')
|
c_cl_addr=$(echo $c_cl_info | jq -r '.address[] | "\(.address):\(.port)"')
|
||||||
maddr=$(echo $minfo | jq -r '.address[] | "\(.address):\(.port)"')
|
m_cl_addr=$(echo $m_cl_info | jq -r '.address[] | "\(.address):\(.port)"')
|
||||||
|
c_cl_uri=$(echo "$c_cl_id@$c_cl_addr")
|
||||||
|
m_cl_uri=$(echo "$m_cl_id@$m_cl_addr")
|
||||||
|
|
||||||
printf "Customer ID: %s@%s\n\r" $cid $caddr
|
c_ln_info=$($C_LN getinfo | jq '.' 2>/dev/null)
|
||||||
printf "Merchant ID: %s@%s\n\r" $mid $maddr
|
m_ln_info=$($M_LN getinfo | jq '.' 2>/dev/null)
|
||||||
|
c_ln_id=$(echo $c_ln_info | jq -r '.identity_pubkey' 2>/dev/null)
|
||||||
|
m_ln_id=$(echo $m_ln_info | jq -r '.identity_pubkey' 2>/dev/null)
|
||||||
|
c_ln_uri=$(echo $c_ln_info | jq -r '.uris[]' 2>/dev/null)
|
||||||
|
m_ln_uri=$(echo $m_ln_info | jq -r '.uris[]' 2>/dev/null)
|
||||||
|
|
||||||
|
printf "\n\rNodes\n\r-----\n\r"
|
||||||
|
printf "Merchant c-lightning: %s\n\r" $m_cl_uri
|
||||||
|
printf "Merchant LND: %s\n\r" $m_ln_uri
|
||||||
|
printf "Customer c-lightning: %s\n\r" $c_cl_uri
|
||||||
|
printf "Customer LND: %s\n\r" $c_ln_uri
|
||||||
|
|
||||||
# Connections
|
# Connections
|
||||||
printf "\n\rConnecting both parties …\n\r"
|
printf "\n\rConnecting all parties\n\r----------------------\n\r"
|
||||||
|
|
||||||
cconnid=$($CCMD connect "$mid@$maddr" | jq -r '.id' 2>/dev/null)
|
connect $M_CL $c_cl_uri "Merchant (c-lightning) to Customer (c-lightning)"
|
||||||
mconnid=$($MCMD connect "$cid@$caddr" | jq -r '.id' 2>/dev/null)
|
connect $M_CL $c_ln_uri "Merchant (c-lightning) to Customer (LND)"
|
||||||
|
connect $M_CL $m_ln_uri "Merchant (c-lightning) to Merchant (LND)"
|
||||||
printf "Customer to merchant %s\n\r" $([[ $cconnid == $mid ]] && echo "succeeded" || echo "failed")
|
connect $C_CL $m_cl_uri "Customer (c-lightning) to Merchant (c-lightning)"
|
||||||
printf "Merchant to customer %s\n\r" $([[ $mconnid == $cid ]] && echo "succeeded" || echo "failed")
|
connect $C_CL $m_ln_uri "Customer (c-lightning) to Merchant (LND)"
|
||||||
|
connect $C_CL $c_ln_uri "Customer (c-lightning) to Customer (LND)"
|
||||||
|
connect $M_LN $c_cl_uri "Merchant (LND) to Customer (c-lightning)"
|
||||||
|
connect $M_LN $c_cl_uri "Merchant (LND) to Customer (c-lightning)"
|
||||||
|
connect $M_LN $c_ln_uri "Merchant (LND) to Customer (LND)"
|
||||||
|
connect $C_LN $m_cl_uri "Customer (LND) to Merchant (c-lightning)"
|
||||||
|
connect $C_LN $c_cl_uri "Customer (LND) to Customer (c-lightning)"
|
||||||
|
connect $C_LN $m_ln_uri "Customer (LND) to Merchant (LND)"
|
||||||
|
|
||||||
# Channels
|
# Channels
|
||||||
printf "\n\rChecking channels …\n\r"
|
printf "\n\rEstablishing channels\n\r----------------------\n\r"
|
||||||
channel_count $CCMD $mid
|
|
||||||
cchanscount=$?
|
|
||||||
channel_count $MCMD $cid
|
|
||||||
mchanscount=$?
|
|
||||||
|
|
||||||
printf "Customer channel count to merchant: %d\n\r" $cchanscount
|
create_channel $C_CL $m_cl_id "Customer (c-lightning) to Merchant (c-lightning)"
|
||||||
printf "Merchant channel count to customer: %d\n\r" $mchanscount
|
create_channel $C_CL $m_ln_id "Customer (c-lightning) to Merchant (LND)"
|
||||||
|
create_channel $C_LN $c_cl_id "Customer (LND) to Customer (c-lightning)"
|
||||||
# Open channels if there are none, details: https://github.com/ElementsProject/lightning#opening-a-channel
|
create_channel $M_CL $m_ln_id "Merchant (c-lightning) to Merchant (LND)" "announce=false"
|
||||||
if [[ $cchanscount -eq 0 ]]; then
|
create_channel $C_LN $m_ln_id "Customer (LND) to Merchant (LND)" --private
|
||||||
create_channel $CCMD $mid
|
|
||||||
cchanres=$?
|
|
||||||
printf "Establishing channel from customer to merchant %s\n\r" $([[ $cchanres -gt 0 ]] && echo "succeeded" || echo "failed")
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $mchanscount -eq 0 ]]; then
|
|
||||||
create_channel $MCMD $cid
|
|
||||||
mchanres=$?
|
|
||||||
printf "Establishing channel from merchant to customer %s\n\r" $([[ $mchanres -gt 0 ]] && echo "succeeded" || echo "failed")
|
|
||||||
fi
|
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
|
||||||
|
./docker-customer-lncli.sh closeallchannels > /dev/null
|
||||||
|
./docker-merchant-lncli.sh closeallchannels > /dev/null
|
||||||
|
./docker-bitcoin-generate.sh 10 > /dev/null
|
||||||
|
|
||||||
channels=$(./docker-merchant-lightning-cli.sh listchannels | jq -cr '.channels | map(.short_channel_id) | unique')
|
channels=$(./docker-merchant-lightning-cli.sh listchannels | jq -cr '.channels | map(.short_channel_id) | unique')
|
||||||
printf "Channels: %s\n\r" $channels
|
|
||||||
|
|
||||||
for chanid in $(echo "${channels}" | jq -cr '.[]')
|
for chanid in $(echo "${channels}" | jq -cr '.[]')
|
||||||
do
|
do
|
||||||
printf "Closing channel ID: %s\n\r" $chanid
|
./docker-merchant-lightning-cli.sh close $chanid > /dev/null
|
||||||
./docker-merchant-lightning-cli.sh close $chanid
|
|
||||||
./docker-bitcoin-generate.sh 20 > /dev/null
|
|
||||||
done
|
done
|
||||||
|
./docker-bitcoin-generate.sh 10 > /dev/null
|
||||||
|
|
||||||
|
printf "All channels closed!\r\n"
|
||||||
|
4
BTCPayServer.Tests/docker-merchant-lncli.sh
Executable file
4
BTCPayServer.Tests/docker-merchant-lncli.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
container_id="$(docker ps -q --filter label=com.docker.compose.project=btcpayservertests --filter label=com.docker.compose.service=merchant_lnd)"
|
||||||
|
docker exec -ti $container_id lncli --no-macaroons --rpcserver localhost:10008 "$@"
|
Loading…
Reference in New Issue
Block a user