Browse Source

tests: regtest.sh now uses consistent indentation

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
committed by ThomasV
parent
commit
a9295e495c
  1. 62
      electrum/tests/regtest/regtest.sh

62
electrum/tests/regtest/regtest.sh

@ -18,16 +18,16 @@ function new_blocks()
function wait_until_funded() function wait_until_funded()
{ {
while alice_balance=$($alice getbalance | jq '.confirmed' | tr -d '"') && [ $alice_balance != "1" ]; do while alice_balance=$($alice getbalance | jq '.confirmed' | tr -d '"') && [ $alice_balance != "1" ]; do
echo "waiting for alice balance" echo "waiting for alice balance"
sleep 1 sleep 1
done done
} }
function wait_until_channel_open() function wait_until_channel_open()
{ {
while channel_state=$($alice list_channels | jq '.[] | .state' | tr -d '"') && [ $channel_state != "OPEN" ]; do while channel_state=$($alice list_channels | jq '.[] | .state' | tr -d '"') && [ $channel_state != "OPEN" ]; do
echo "waiting for channel open" echo "waiting for channel open"
sleep 1 sleep 1
done done
} }
@ -85,7 +85,7 @@ if [[ $1 == "alice_pays_carol" ]]; then
carol_balance=$($carol list_channels | jq -r '.[0].local_balance') carol_balance=$($carol list_channels | jq -r '.[0].local_balance')
echo "carol balance: $carol_balance" echo "carol balance: $carol_balance"
if [[ $carol_balance != 110000 ]]; then if [[ $carol_balance != 110000 ]]; then
exit 1 exit 1
fi fi
fi fi
@ -123,7 +123,7 @@ if [[ $1 == "breach" ]]; then
balance=$($bob getbalance | jq '.confirmed | tonumber') balance=$($bob getbalance | jq '.confirmed | tonumber')
echo "balance of bob after breach: $balance" echo "balance of bob after breach: $balance"
if (( $(echo "$balance < 0.14" | bc -l) )); then if (( $(echo "$balance < 0.14" | bc -l) )); then
exit 1 exit 1
fi fi
fi fi
@ -143,7 +143,7 @@ if [[ $1 == "redeem_htlcs" ]]; then
sleep 1 sleep 1
settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length') settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length')
if [[ "$settled" != "0" ]]; then if [[ "$settled" != "0" ]]; then
echo 'SETTLE_DELAY did not work' echo 'SETTLE_DELAY did not work'
exit 1 exit 1
fi fi
# bob goes away # bob goes away
@ -168,8 +168,8 @@ if [[ $1 == "redeem_htlcs" ]]; then
echo "alice balance after CSV" $($alice getbalance) echo "alice balance after CSV" $($alice getbalance)
balance_after=$($alice getbalance | jq '[.confirmed, .unconfirmed] | to_entries | map(select(.value != null).value) | map(tonumber) | add ') balance_after=$($alice getbalance | jq '[.confirmed, .unconfirmed] | to_entries | map(select(.value != null).value) | map(tonumber) | add ')
if (( $(echo "$balance_before - $balance_after > 0.02" | bc -l) )); then if (( $(echo "$balance_before - $balance_after > 0.02" | bc -l) )); then
echo "htlc not redeemed." echo "htlc not redeemed."
exit 1 exit 1
fi fi
fi fi
@ -189,14 +189,14 @@ if [[ $1 == "breach_with_unspent_htlc" ]]; then
$alice lnpay $invoice --timeout=1 || true $alice lnpay $invoice --timeout=1 || true
settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length') settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length')
if [[ "$settled" != "0" ]]; then if [[ "$settled" != "0" ]]; then
echo "SETTLE_DELAY did not work, $settled != 0" echo "SETTLE_DELAY did not work, $settled != 0"
exit 1 exit 1
fi fi
ctx=$($alice get_channel_ctx $channel | jq '.hex' | tr -d '"') ctx=$($alice get_channel_ctx $channel | jq '.hex' | tr -d '"')
sleep 5 sleep 5
settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length') settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length')
if [[ "$settled" != "1" ]]; then if [[ "$settled" != "1" ]]; then
echo "SETTLE_DELAY did not work, $settled != 1" echo "SETTLE_DELAY did not work, $settled != 1"
exit 1 exit 1
fi fi
echo $($bob getbalance) echo $($bob getbalance)
@ -207,25 +207,25 @@ if [[ $1 == "breach_with_unspent_htlc" ]]; then
new_blocks 1 new_blocks 1
# wait until breach is confirmed # wait until breach is confirmed
while height2=$($bob daemon status | jq '.blockchain_height') && [ $(($height2 - $height1)) -ne 1 ]; do while height2=$($bob daemon status | jq '.blockchain_height') && [ $(($height2 - $height1)) -ne 1 ]; do
echo "waiting for block" echo "waiting for block"
sleep 1 sleep 1
done done
new_blocks 1 new_blocks 1
# wait until next block is confirmed, so that htlc tx and redeem tx are confirmed too # wait until next block is confirmed, so that htlc tx and redeem tx are confirmed too
while height3=$($bob daemon status | jq '.blockchain_height') && [ $(($height3 - $height2)) -ne 1 ]; do while height3=$($bob daemon status | jq '.blockchain_height') && [ $(($height3 - $height2)) -ne 1 ]; do
echo "waiting for block" echo "waiting for block"
sleep 1 sleep 1
done done
# wait until wallet is synchronized # wait until wallet is synchronized
while b=$($bob daemon status | jq '.wallets | ."/tmp/bob/regtest/wallets/default_wallet"') && [ "$b" != "true" ]; do while b=$($bob daemon status | jq '.wallets | ."/tmp/bob/regtest/wallets/default_wallet"') && [ "$b" != "true" ]; do
echo "waiting for wallet sync $b" echo "waiting for wallet sync $b"
sleep 1 sleep 1
done done
echo $($bob getbalance) echo $($bob getbalance)
balance_after=$($bob getbalance | jq '[.confirmed, .unconfirmed] | to_entries | map(select(.value != null).value) | map(tonumber) | add ') balance_after=$($bob getbalance | jq '[.confirmed, .unconfirmed] | to_entries | map(select(.value != null).value) | map(tonumber) | add ')
if (( $(echo "$balance_after < 0.14" | bc -l) )); then if (( $(echo "$balance_after < 0.14" | bc -l) )); then
echo "htlc not redeemed." echo "htlc not redeemed."
exit 1 exit 1
fi fi
fi fi
@ -245,7 +245,7 @@ if [[ $1 == "breach_with_spent_htlc" ]]; then
$alice lnpay $invoice --timeout=1 || true $alice lnpay $invoice --timeout=1 || true
settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length') settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length')
if [[ "$settled" != "0" ]]; then if [[ "$settled" != "0" ]]; then
echo "SETTLE_DELAY did not work, $settled != 0" echo "SETTLE_DELAY did not work, $settled != 0"
exit 1 exit 1
fi fi
ctx=$($alice get_channel_ctx $channel | jq '.hex' | tr -d '"') ctx=$($alice get_channel_ctx $channel | jq '.hex' | tr -d '"')
@ -253,7 +253,7 @@ if [[ $1 == "breach_with_spent_htlc" ]]; then
sleep 5 sleep 5
settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length') settled=$($alice list_channels | jq '.[] | .local_htlcs | .settles | length')
if [[ "$settled" != "1" ]]; then if [[ "$settled" != "1" ]]; then
echo "SETTLE_DELAY did not work, $settled != 1" echo "SETTLE_DELAY did not work, $settled != 1"
exit 1 exit 1
fi fi
echo $($bob getbalance) echo $($bob getbalance)
@ -263,8 +263,8 @@ if [[ $1 == "breach_with_spent_htlc" ]]; then
echo "alice breaches with old ctx:" $ctx_id echo "alice breaches with old ctx:" $ctx_id
new_blocks 1 new_blocks 1
if [[ $($bitcoin_cli gettxout $ctx_id 0 | jq '.confirmations') != "1" ]]; then if [[ $($bitcoin_cli gettxout $ctx_id 0 | jq '.confirmations') != "1" ]]; then
echo "breach tx not confirmed" echo "breach tx not confirmed"
exit 1 exit 1
fi fi
echo "wait for cltv_expiry blocks" echo "wait for cltv_expiry blocks"
# note: this will let alice redeem to_local # note: this will let alice redeem to_local
@ -277,28 +277,28 @@ if [[ $1 == "breach_with_spent_htlc" ]]; then
$alice daemon load_wallet $alice daemon load_wallet
# wait until alice has spent both ctx outputs # wait until alice has spent both ctx outputs
while [[ $($bitcoin_cli gettxout $ctx_id 0) ]]; do while [[ $($bitcoin_cli gettxout $ctx_id 0) ]]; do
echo "waiting until alice spends ctx outputs" echo "waiting until alice spends ctx outputs"
sleep 1 sleep 1
done done
while [[ $($bitcoin_cli gettxout $ctx_id 1) ]]; do while [[ $($bitcoin_cli gettxout $ctx_id 1) ]]; do
echo "waiting until alice spends ctx outputs" echo "waiting until alice spends ctx outputs"
sleep 1 sleep 1
done done
new_blocks 1 new_blocks 1
echo "bob comes back" echo "bob comes back"
$bob daemon -s 127.0.0.1:51001:t start $bob daemon -s 127.0.0.1:51001:t start
$bob daemon load_wallet $bob daemon load_wallet
while [[ $($bitcoin_cli getmempoolinfo | jq '.size') != "1" ]]; do while [[ $($bitcoin_cli getmempoolinfo | jq '.size') != "1" ]]; do
echo "waiting for bob's transaction" echo "waiting for bob's transaction"
sleep 1 sleep 1
done done
echo "mempool has 1 tx" echo "mempool has 1 tx"
new_blocks 1 new_blocks 1
sleep 5 sleep 5
balance=$($bob getbalance | jq '.confirmed') balance=$($bob getbalance | jq '.confirmed')
if (( $(echo "$balance < 0.049" | bc -l) )); then if (( $(echo "$balance < 0.049" | bc -l) )); then
echo "htlc not redeemed." echo "htlc not redeemed."
exit 1 exit 1
fi fi
echo "bob balance $balance" echo "bob balance $balance"
fi fi

Loading…
Cancel
Save