1
0

swapserver: add test for refund path

This commit is contained in:
ThomasV
2023-06-28 14:23:32 +02:00
parent 351ff1e4b5
commit 1411b75584
6 changed files with 70 additions and 18 deletions

View File

@@ -15,6 +15,19 @@ function new_blocks()
$bitcoin_cli generatetoaddress $1 $($bitcoin_cli getnewaddress) > /dev/null
}
function wait_until_htlcs_settled()
{
msg="wait until $1's local_unsettled_sent is zero"
cmd="./run_electrum --regtest -D /tmp/$1"
while unsettled=$($alice list_channels | jq '.[] | .local_unsettled_sent') && [ $unsettled != "0" ]; do
sleep 1
msg="$msg."
printf "$msg\r"
done
printf "\n"
}
function wait_for_balance()
{
msg="wait until $1's balance reaches $2"
@@ -171,7 +184,7 @@ if [[ $1 == "collaborative_close" ]]; then
fi
if [[ $1 == "reverse_swap" ]]; then
if [[ $1 == "swapserver_success" ]]; then
wait_for_balance alice 1
echo "alice opens channel"
bob_node=$($bob nodeid)
@@ -180,12 +193,34 @@ if [[ $1 == "reverse_swap" ]]; then
wait_until_channel_open alice
echo "alice initiates swap"
dryrun=$($alice reverse_swap 0.02 dryrun)
echo $dryrun | jq
onchain_amount=$(echo $dryrun| jq -r ".onchain_amount")
$alice reverse_swap 0.02 $onchain_amount
swap=$($alice reverse_swap 0.02 $onchain_amount)
echo $swap | jq
funding_txid=$(echo $swap| jq -r ".funding_txid")
new_blocks 1
sleep 1
wait_until_spent $funding_txid 0
wait_until_htlcs_settled alice
fi
if [[ $1 == "swapserver_refund" ]]; then
$alice setconfig test_swapserver_refund true
wait_for_balance alice 1
echo "alice opens channel"
bob_node=$($bob nodeid)
channel=$($alice open_channel $bob_node 0.15)
new_blocks 3
wait_until_channel_open alice
echo "alice initiates swap"
dryrun=$($alice reverse_swap 0.02 dryrun)
onchain_amount=$(echo $dryrun| jq -r ".onchain_amount")
swap=$($alice reverse_swap 0.02 $onchain_amount)
echo $swap | jq
funding_txid=$(echo $swap| jq -r ".funding_txid")
new_blocks 140
wait_until_spent $funding_txid 0
new_blocks 1
wait_until_htlcs_settled alice
fi