regtests: swaps: add test for forward-swap success case
What changed, and why it matters
This commit only adds a new automated test for a successful forward cryptocurrency swap and renames an existing reverse-swap test. It also adds a minor code comment noting an inconsistent field name. There are no user-facing changes and no security fixes or vulnerabilities are present in the diff.
No security action required. This is a routine test-coverage addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is test-only infrastructure: it splits test_swapserver_success into swapserver_success_reverse and swapserver_success_forward, adds the shell-script logic to exercise normal_swap (forward swap) on a regtest network, and adds a FIXME comment in electrum/commands.py about renaming txid to funding_txid for consistency with the reverse_swap command. No production logic is modified.
Changed components
tests/regtest.pytests/regtest/regtest.shelectrum/commands.py (comment only)Inspect captured patch +29 / −5
diff --git a/electrum/commands.py b/electrum/commands.py
index 1291e8d..ea57c78 100644
--- a/electrum/commands.py
+++ b/electrum/commands.py
@@ -2117,7 +2117,7 @@ class Commands(Logger):
)
return {
- 'txid': txid,
+ 'txid': txid, # FIXME sync name with reverse_swap cmd that uses "funding_txid"
'lightning_amount': format_satoshis(lightning_amount_sat),
'onchain_amount': format_satoshis(onchain_amount_sat),
}
diff --git a/tests/regtest.py b/tests/regtest.py
index ae18044..9c2de7b 100644
--- a/tests/regtest.py
+++ b/tests/regtest.py
@@ -101,8 +101,11 @@ class TestLightningSwapserver(TestLightning):
}
}
- def test_swapserver_success(self):
- self.run_shell(['swapserver_success'])
+ def test_swapserver_success_forward(self):
+ self.run_shell(['swapserver_success_forward'])
+
+ def test_swapserver_success_reverse(self):
+ self.run_shell(['swapserver_success_reverse'])
def test_swapserver_forceclose(self):
self.run_shell(['swapserver_forceclose'])
diff --git a/tests/regtest/regtest.sh b/tests/regtest/regtest.sh
index f5df1e5..f0a66f3 100755
--- a/tests/regtest/regtest.sh
+++ b/tests/regtest/regtest.sh
@@ -292,26 +292,47 @@ if [[ $1 == "collaborative_close" ]]; then
fi
-if [[ $1 == "swapserver_success" ]]; then
+if [[ $1 == "swapserver_success_reverse" ]]; then
wait_for_balance alice 1
echo "alice opens channel"
bob_node=$($bob nodeid)
channel=$($alice open_channel $bob_node 0.15 --password='')
new_blocks 3
wait_until_channel_open alice
- echo "alice initiates swap"
+ echo "alice initiates reverse-swap"
dryrun=$($alice reverse_swap 0.02 dryrun)
onchain_amount=$(echo $dryrun| jq -r ".onchain_amount")
prepayment=$(echo $dryrun| jq -r ".prepayment")
swap=$($alice reverse_swap 0.02 $onchain_amount --prepayment $prepayment)
echo $swap | jq
funding_txid=$(echo $swap| jq -r ".funding_txid")
+ assert_utxo_exists $funding_txid 0
new_blocks 1
wait_until_spent $funding_txid 0
wait_until_htlcs_settled alice
fi
+if [[ $1 == "swapserver_success_forward" ]]; then
+ wait_for_balance alice 1
+ echo "alice opens channel"
+ bob_node=$($bob nodeid)
+ channel=$($alice open_channel $bob_node 0.15 --password='' --push_amount=0.075)
+ new_blocks 3
+ wait_until_channel_open alice
+ echo "alice initiates forward-swap"
+ dryrun=$($alice normal_swap 0.02 dryrun)
+ lightning_amount=$(echo $dryrun| jq -r ".lightning_amount")
+ swap=$($alice normal_swap 0.02 $lightning_amount)
+ echo $swap | jq
+ funding_txid=$(echo $swap| jq -r ".txid")
+ assert_utxo_exists $funding_txid 0
+ new_blocks 1
+ wait_until_spent $funding_txid 0
+ wait_until_htlcs_settled bob
+fi
+
+
if [[ $1 == "swapserver_forceclose" ]]; then
# Alice starts reverse-swap with Bob.
# Alice sends hold-HTLCs via LN, Bob funds locking script onchain.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.