Skip to content

Commit 4958484

Browse files
committed
tests: adapt to new htlc_switch architecture
update tests / MockLNWallet to new htlc switch architecture. Also adapt hold invoice cli commands.
1 parent f11c2d7 commit 4958484

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

electrum/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ async def check_hold_invoice(self, payment_hash: str, wallet: Abstract_Wallet =
15061506
payment_key: str = wallet.lnworker._get_payment_key(bfh(payment_hash)).hex()
15071507
htlc_status = wallet.lnworker.received_mpp_htlcs[payment_key]
15081508
result["closest_htlc_expiry_height"] = min(
1509-
htlc.cltv_abs for _, htlc in htlc_status.htlc_set
1509+
mpp_htlc.htlc.cltv_abs for mpp_htlc in htlc_status.htlcs
15101510
)
15111511
elif wallet.lnworker.get_preimage_hex(payment_hash) is not None \
15121512
and payment_hash not in wallet.lnworker.dont_settle_htlcs:

tests/test_commands.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,13 @@ async def test_hold_invoice_commands(self, mock_save_db):
540540
)
541541

542542
mock_htlc1 = mock.Mock()
543-
mock_htlc1.cltv_abs = 800_000
544-
mock_htlc1.amount_msat = 4_500_000
543+
mock_htlc1.htlc.cltv_abs = 800_000
544+
mock_htlc1.htlc.amount_msat = 4_500_000
545545
mock_htlc2 = mock.Mock()
546-
mock_htlc2.cltv_abs = 800_144
547-
mock_htlc2.amount_msat = 5_500_000
546+
mock_htlc2.htlc.cltv_abs = 800_144
547+
mock_htlc2.htlc.amount_msat = 5_500_000
548548
mock_htlc_status = mock.Mock()
549-
mock_htlc_status.htlc_set = [(None, mock_htlc1), (None, mock_htlc2)]
549+
mock_htlc_status.htlcs = [mock_htlc1, mock_htlc2]
550550
mock_htlc_status.resolution = RecvMPPResolution.COMPLETE
551551

552552
payment_key = wallet.lnworker._get_payment_key(bytes.fromhex(payment_hash)).hex()

tests/test_lnpeer.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ async def create_routes_from_invoice(self, amount_msat: int, decoded_invoice: Ln
301301
set_request_status = LNWallet.set_request_status
302302
set_payment_status = LNWallet.set_payment_status
303303
get_payment_status = LNWallet.get_payment_status
304-
check_mpp_status = LNWallet.check_mpp_status
305304
htlc_fulfilled = LNWallet.htlc_fulfilled
306305
htlc_failed = LNWallet.htlc_failed
307306
save_preimage = LNWallet.save_preimage
@@ -334,11 +333,9 @@ async def create_routes_from_invoice(self, amount_msat: int, decoded_invoice: Ln
334333
unregister_hold_invoice = LNWallet.unregister_hold_invoice
335334
add_payment_info_for_hold_invoice = LNWallet.add_payment_info_for_hold_invoice
336335

337-
update_mpp_with_received_htlc = LNWallet.update_mpp_with_received_htlc
336+
update_or_create_mpp_with_received_htlc = LNWallet.update_or_create_mpp_with_received_htlc
338337
set_mpp_resolution = LNWallet.set_mpp_resolution
339-
is_mpp_amount_reached = LNWallet.is_mpp_amount_reached
340338
get_mpp_amounts = LNWallet.get_mpp_amounts
341-
get_first_timestamp_of_mpp = LNWallet.get_first_timestamp_of_mpp
342339
bundle_payments = LNWallet.bundle_payments
343340
get_payment_bundle = LNWallet.get_payment_bundle
344341
_get_payment_key = LNWallet._get_payment_key
@@ -347,8 +344,14 @@ async def create_routes_from_invoice(self, amount_msat: int, decoded_invoice: Ln
347344
maybe_cleanup_forwarding = LNWallet.maybe_cleanup_forwarding
348345
current_target_feerate_per_kw = LNWallet.current_target_feerate_per_kw
349346
current_low_feerate_per_kw_srk_channel = LNWallet.current_low_feerate_per_kw_srk_channel
350-
maybe_cleanup_mpp = LNWallet.maybe_cleanup_mpp
351347
create_onion_for_route = LNWallet.create_onion_for_route
348+
maybe_forward_htlc_set = LNWallet.maybe_forward_htlc_set
349+
_maybe_forward_htlc = LNWallet._maybe_forward_htlc
350+
_maybe_forward_trampoline = LNWallet._maybe_forward_trampoline
351+
_maybe_refuse_to_forward_htlc_that_corresponds_to_payreq_we_created = LNWallet._maybe_refuse_to_forward_htlc_that_corresponds_to_payreq_we_created
352+
set_htlc_set_error = LNWallet.set_htlc_set_error
353+
is_payment_bundle_complete = LNWallet.is_payment_bundle_complete
354+
delete_payment_bundle = LNWallet.delete_payment_bundle
352355

353356

354357
class MockTransport:
@@ -709,7 +712,7 @@ async def bob_sends_reest():
709712

710713
@staticmethod
711714
def _send_fake_htlc(peer: Peer, chan: Channel) -> UpdateAddHtlc:
712-
htlc = UpdateAddHtlc(amount_msat=10000, payment_hash=os.urandom(32), cltv_abs=999, timestamp=1)
715+
htlc = UpdateAddHtlc(amount_msat=10000, rhash=os.urandom(32).hex(), cltv_abs=999, timestamp=1)
713716
htlc = chan.add_htlc(htlc)
714717
peer.send_message(
715718
"update_add_htlc",

tests/test_lnutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_commitment_tx_with_all_five_HTLCs_untrimmed_minimum_feerate(self):
562562
(1, 2000 * 1000),
563563
(3, 3000 * 1000),
564564
(4, 4000 * 1000)]:
565-
htlc_obj[num] = UpdateAddHtlc(amount_msat=msat, payment_hash=bitcoin.sha256(htlc_payment_preimage[num]), cltv_abs=0, htlc_id=None, timestamp=0)
565+
htlc_obj[num] = UpdateAddHtlc(amount_msat=msat, rhash=bitcoin.sha256(htlc_payment_preimage[num]).hex(), cltv_abs=0, htlc_id=None, timestamp=0)
566566
htlcs = [ScriptHtlc(htlc[x], htlc_obj[x]) for x in range(5)]
567567

568568
our_commit_tx = make_commitment(
@@ -848,7 +848,7 @@ def _test_commitment_tx_anchors_test_vectors(self):
848848
has_anchors=True)
849849
update_add_htlc = UpdateAddHtlc(
850850
amount_msat=test_htlc['amount'],
851-
payment_hash=bitcoin.sha256(bfh(test_htlc['preimage'])),
851+
rhash=bitcoin.sha256(bfh(test_htlc['preimage'])).hex(),
852852
cltv_abs=test_htlc['expiry'],
853853
htlc_id=None,
854854
timestamp=0)

0 commit comments

Comments
 (0)