chore(fmt): Fix formatting of new python files.
What changed, and why it matters
This commit only reformats Python test files and a test plugin. It adjusts whitespace, quote style, line breaks, and removes a couple of unused local variables. There is no change to production code, no security fix, and no behavior change in the software users run.
No security action needed. Treat as routine code-quality/maintenance cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure formatting patch (chore(fmt)) on tests/plugins/lsps2_policy.py and tests/test_cln_lsps.py. It applies style-only changes: docstring spacing, single vs double quotes, indentation, trailing commas, and removal of dead code (unused now/valid_until computation in lsps2_getchannelcapacity). It also adds an import pytest and converts a test assertion to use pytest.raises(ValueError). No functional logic in Core Lightning’s runtime is modified.
Changed components
tests/plugins/lsps2_policy.pytests/test_cln_lsps.pyInspect captured patch +162 / −139
diff --git a/tests/plugins/lsps2_policy.py b/tests/plugins/lsps2_policy.py
index 7588712d..9294bbec 100755
--- a/tests/plugins/lsps2_policy.py
+++ b/tests/plugins/lsps2_policy.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-""" A simple implementation of a LSPS2 compatible policy plugin. It is the job
+"""A simple implementation of a LSPS2 compatible policy plugin. It is the job
of this plugin to deliver a fee options menu to the LSPS2 service plugin.
"""
@@ -12,45 +12,40 @@ plugin = Plugin()
@plugin.method("dev-lsps2-getpolicy")
def lsps2_getpolicy(request):
- """ Returns an opening fee menu for the LSPS2 plugin.
- """
+ """Returns an opening fee menu for the LSPS2 plugin."""
now = datetime.now(timezone.utc)
# Is ISO 8601 format "YYYY-MM-DDThh:mm:ss.uuuZ"
- valid_until = (now + timedelta(hours=1)).isoformat().replace('+00:00', 'Z')
-
- return { "policy_opening_fee_params_menu": [
- {
- "min_fee_msat": "1000",
- "proportional": 1000,
- "valid_until": valid_until,
- "min_lifetime": 2000,
- "max_client_to_self_delay": 2016,
- "min_payment_size_msat": "1000",
- "max_payment_size_msat": "100000000",
- },
- {
- "min_fee_msat": "1092000",
- "proportional": 2400,
- "valid_until": valid_until,
- "min_lifetime": 1008,
- "max_client_to_self_delay": 2016,
- "min_payment_size_msat": "1000",
- "max_payment_size_msat": "1000000",
- }
- ]
-}
+ valid_until = (now + timedelta(hours=1)).isoformat().replace("+00:00", "Z")
+
+ return {
+ "policy_opening_fee_params_menu": [
+ {
+ "min_fee_msat": "1000",
+ "proportional": 1000,
+ "valid_until": valid_until,
+ "min_lifetime": 2000,
+ "max_client_to_self_delay": 2016,
+ "min_payment_size_msat": "1000",
+ "max_payment_size_msat": "100000000",
+ },
+ {
+ "min_fee_msat": "1092000",
+ "proportional": 2400,
+ "valid_until": valid_until,
+ "min_lifetime": 1008,
+ "max_client_to_self_delay": 2016,
+ "min_payment_size_msat": "1000",
+ "max_payment_size_msat": "1000000",
+ },
+ ]
+ }
+
@plugin.method("dev-lsps2-getchannelcapacity")
def lsps2_getchannelcapacity(request, init_payment_size, scid, opening_fee_params):
- """ Returns an opening fee menu for the LSPS2 plugin.
- """
- now = datetime.now(timezone.utc)
-
- # Is ISO 8601 format "YYYY-MM-DDThh:mm:ss.uuuZ"
- valid_until = (now + timedelta(hours=1)).isoformat().replace('+00:00', 'Z')
-
- return { "channel_capacity_msat": 100000000 }
+ """Returns an opening fee menu for the LSPS2 plugin."""
+ return {"channel_capacity_msat": 100000000}
plugin.run()
diff --git a/tests/test_cln_lsps.py b/tests/test_cln_lsps.py
index a7b66eb4..290a3e29 100644
--- a/tests/test_cln_lsps.py
+++ b/tests/test_cln_lsps.py
@@ -2,6 +2,7 @@ from fixtures import * # noqa: F401,F403
from pyln.testing.utils import RUST
from utils import only_one
import os
+import pytest
import unittest
RUST_PROFILE = os.environ.get("RUST_PROFILE", "debug")
@@ -20,78 +21,87 @@ def test_lsps_service_disabled(node_factory):
@unittest.skipUnless(RUST, 'RUST is not enabled')
def test_lsps0_listprotocols(node_factory):
- l1, l2 = node_factory.get_nodes(2, opts=[
- {"dev-lsps-client-enabled": None}, {"dev-lsps-service-enabled": None}
- ])
+ l1, l2 = node_factory.get_nodes(
+ 2, opts=[{"dev-lsps-client-enabled": None}, {"dev-lsps-service-enabled": None}]
+ )
# We don't need a channel to query for lsps services
node_factory.join_nodes([l1, l2], fundchannel=False)
- res = l1.rpc.lsps_listprotocols(lsp_id=l2.info['id'])
+ res = l1.rpc.lsps_listprotocols(lsp_id=l2.info["id"])
assert res
def test_lsps2_enabled(node_factory):
- l1, l2 = node_factory.get_nodes(2, opts=[
- {"dev-lsps-client-enabled": None},
- {
- "dev-lsps-service-enabled": None,
- "dev-lsps2-service-enabled": None,
- "dev-lsps2-promise-secret": "0" * 64
- }
- ])
+ l1, l2 = node_factory.get_nodes(
+ 2,
+ opts=[
+ {"dev-lsps-client-enabled": None},
+ {
+ "dev-lsps-service-enabled": None,
+ "dev-lsps2-service-enabled": None,
+ "dev-lsps2-promise-secret": "0" * 64,
+ },
+ ],
+ )
node_factory.join_nodes([l1, l2], fundchannel=False)
- res = l1.rpc.lsps_listprotocols(lsp_id=l2.info['id'])
- assert res['protocols'] == [2]
+ res = l1.rpc.lsps_listprotocols(lsp_id=l2.info["id"])
+ assert res["protocols"] == [2]
def test_lsps2_getinfo(node_factory):
- plugin = os.path.join(os.path.dirname(__file__), 'plugins/lsps2_policy.py')
-
- l1, l2 = node_factory.get_nodes(2, opts=[
- {"dev-lsps-client-enabled": None},
- {
- "dev-lsps-service-enabled": None,
- "dev-lsps2-service-enabled": None,
- "dev-lsps2-promise-secret": "0" * 64,
- "plugin": plugin
- }
- ])
+ plugin = os.path.join(os.path.dirname(__file__), "plugins/lsps2_policy.py")
+
+ l1, l2 = node_factory.get_nodes(
+ 2,
+ opts=[
+ {"dev-lsps-client-enabled": None},
+ {
+ "dev-lsps-service-enabled": None,
+ "dev-lsps2-service-enabled": None,
+ "dev-lsps2-promise-secret": "0" * 64,
+ "plugin": plugin,
+ },
+ ],
+ )
node_factory.join_nodes([l1, l2], fundchannel=False)
- res = l1.rpc.lsps_lsps2_getinfo(lsp_id=l2.info['id'])
+ res = l1.rpc.lsps_lsps2_getinfo(lsp_id=l2.info["id"])
assert res["opening_fee_params_menu"]
def test_lsps2_buy(node_factory):
# We need a policy service to fetch from.
- plugin = os.path.join(os.path.dirname(__file__), 'plugins/lsps2_policy.py')
-
- l1, l2 = node_factory.get_nodes(2, opts=[
- {"dev-lsps-client-enabled": None},
- {
- "dev-lsps-service-enabled": None,
- "dev-lsps2-service-enabled": None,
- "dev-lsps2-promise-secret": "0" * 64,
- "plugin": plugin
- }
- ])
+ plugin = os.path.join(os.path.dirname(__file__), "plugins/lsps2_policy.py")
+
+ l1, l2 = node_factory.get_nodes(
+ 2,
+ opts=[
+ {"dev-lsps-client-enabled": None},
+ {
+ "dev-lsps-service-enabled": None,
+ "dev-lsps2-service-enabled": None,
+ "dev-lsps2-promise-secret": "0" * 64,
+ "plugin": plugin,
+ },
+ ],
+ )
# We don't need a channel to query for lsps services
node_factory.join_nodes([l1, l2], fundchannel=False)
- res = l1.rpc.lsps_lsps2_getinfo(lsp_id=l2.info['id'])
+ res = l1.rpc.lsps_lsps2_getinfo(lsp_id=l2.info["id"])
params = res["opening_fee_params_menu"][0]
- res = l1.rpc.lsps_lsps2_buy(lsp_id=l2.info['id'], opening_fee_params=params)
+ res = l1.rpc.lsps_lsps2_buy(lsp_id=l2.info["id"], opening_fee_params=params)
assert res
def test_lsps2_buyjitchannel_no_mpp_var_invoice(node_factory, bitcoind):
- """ Tests the creation of a "Just-In-Time-Channel" (jit-channel).
+ """Tests the creation of a "Just-In-Time-Channel" (jit-channel).
At the beginning we have the following situation where l2 acts as the LSP
(LSP)
@@ -108,117 +118,135 @@ def test_lsps2_buyjitchannel_no_mpp_var_invoice(node_factory, bitcoind):
l1----l2----l3
"""
# We need a policy service to fetch from.
- plugin = os.path.join(os.path.dirname(__file__), 'plugins/lsps2_policy.py')
-
- l1, l2, l3= node_factory.get_nodes(3, opts=[
- {"dev-lsps-client-enabled": None},
- {
- "dev-lsps-service-enabled": None,
- "dev-lsps2-service-enabled": None,
- "dev-lsps2-promise-secret": "00" * 32,
- "plugin": plugin,
- "fee-base": 0, # We are going to deduct our fee anyways,
- "fee-per-satoshi": 0, # We are going to deduct our fee anyways,
- },
- {},
- ])
+ plugin = os.path.join(os.path.dirname(__file__), "plugins/lsps2_policy.py")
+
+ l1, l2, l3 = node_factory.get_nodes(
+ 3,
+ opts=[
+ {"dev-lsps-client-enabled": None},
+ {
+ "dev-lsps-service-enabled": None,
+ "dev-lsps2-service-enabled": None,
+ "dev-lsps2-promise-secret": "00" * 32,
+ "plugin": plugin,
+ "fee-base": 0, # We are going to deduct our fee anyways,
+ "fee-per-satoshi": 0, # We are going to deduct our fee anyways,
+ },
+ {},
+ ],
+ )
# Give the LSP some funds to open jit-channels
- addr = l2.rpc.newaddr()['bech32']
+ addr = l2.rpc.newaddr()["bech32"]
bitcoind.rpc.sendtoaddress(addr, 1)
bitcoind.generate_block(1)
node_factory.join_nodes([l3, l2], fundchannel=True, wait_for_announce=True)
node_factory.join_nodes([l1, l2], fundchannel=False)
- chanid = only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['short_channel_id']
+ chanid = only_one(l3.rpc.listpeerchannels(l2.info["id"])["channels"])[
+ "short_channel_id"
+ ]
inv = l1.rpc.lsps_jitchannel(
- lsp_id=l2.info['id'],
+ lsp_id=l2.info["id"],
amount_msat="any",
description="lsp-jit-channel-0",
- label="lsp-jit-channel-0"
+ label="lsp-jit-channel-0",
)
assert inv
- dec = l3.rpc.decode(inv['bolt11'])
+ dec = l3.rpc.decode(inv["bolt11"])
assert dec
- routehint = only_one(only_one(dec['routes']))
+ routehint = only_one(only_one(dec["routes"]))
amt = 10000000
- fee = amt * 10 // 1000000 + 1
-
- route = [{'amount_msat': amt,
- 'id': l2.info['id'],
- 'delay': 14,
- 'channel': chanid},
- {'amount_msat': amt,
- 'id': l1.info['id'],
- 'delay': 8,
- 'channel': routehint['short_channel_id']}]
- l3.rpc.sendpay(route, dec['payment_hash'], payment_secret=inv['payment_secret'], bolt11=inv['bolt11'], partid=0)
+ route = [
+ {"amount_msat": amt, "id": l2.info["id"], "delay": 14, "channel": chanid},
+ {
+ "amount_msat": amt,
+ "id": l1.info["id"],
+ "delay": 8,
+ "channel": routehint["short_channel_id"],
+ },
+ ]
+
+ l3.rpc.sendpay(
+ route,
+ dec["payment_hash"],
+ payment_secret=inv["payment_secret"],
+ bolt11=inv["bolt11"],
+ partid=0,
+ )
- res = l3.rpc.waitsendpay(dec['payment_hash'])
- assert res['payment_preimage']
+ res = l3.rpc.waitsendpay(dec["payment_hash"])
+ assert res["payment_preimage"]
# l1 should have gotten a jit-channel.
- chs = l1.rpc.listpeerchannels()['channels']
+ chs = l1.rpc.listpeerchannels()["channels"]
assert len(chs) == 1
def test_lsps2_non_approved_zero_conf(node_factory, bitcoind):
- """ Checks that we don't allow zerof_conf channels from an LSP if we did
- not approve it first.
+ """Checks that we don't allow zerof_conf channels from an LSP if we did
+ not approve it first.
"""
# We need a policy service to fetch from.
- plugin = os.path.join(os.path.dirname(__file__), 'plugins/lsps2_policy.py')
-
- l1, l2, l3= node_factory.get_nodes(3, opts=[
- {"dev-lsps-client-enabled": None},
- {
- "dev-lsps-service-enabled": None,
- "dev-lsps2-service-enabled": None,
- "dev-lsps2-promise-secret": "00" * 32,
- "plugin": plugin,
- "fee-base": 0, # We are going to deduct our fee anyways,
- "fee-per-satoshi": 0, # We are going to deduct our fee anyways,
- },
- {"disable-mpp": None},
- ])
+ plugin = os.path.join(os.path.dirname(__file__), "plugins/lsps2_policy.py")
+
+ l1, l2, l3 = node_factory.get_nodes(
+ 3,
+ opts=[
+ {"dev-lsps-client-enabled": None},
+ {
+ "dev-lsps-service-enabled": None,
+ "dev-lsps2-service-enabled": None,
+ "dev-lsps2-promise-secret": "00" * 32,
+ "plugin": plugin,
+ "fee-base": 0, # We are going to deduct our fee anyways,
+ "fee-per-satoshi": 0, # We are going to deduct our fee anyways,
+ },
+ {"disable-mpp": None},
+ ],
+ )
# Give the LSP some funds to open jit-channels
- addr = l2.rpc.newaddr()['bech32']
+ addr = l2.rpc.newaddr()["bech32"]
bitcoind.rpc.sendtoaddress(addr, 1)
bitcoind.generate_block(1)
node_factory.join_nodes([l3, l2], fundchannel=True, wait_for_announce=True)
node_factory.join_nodes([l1, l2], fundchannel=False)
- chanid = only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['short_channel_id']
-
- fee_opt = l1.rpc.lsps_lsps2_getinfo(lsp_id=l2.info['id'])['opening_fee_params_menu'][0]
- buy_res = l1.rpc.lsps_lsps2_buy(lsp_id=l2.info['id'], opening_fee_params=fee_opt)
-
- hint = [[{
- "id": l2.info['id'],
- "short_channel_id": buy_res['jit_channel_scid'],
- "fee_base_msat": 0,
- "fee_proportional_millionths": 0,
- "cltv_expiry_delta": buy_res['lsp_cltv_expiry_delta'],
- }]]
+ fee_opt = l1.rpc.lsps_lsps2_getinfo(lsp_id=l2.info["id"])[
+ "opening_fee_params_menu"
+ ][0]
+ buy_res = l1.rpc.lsps_lsps2_buy(lsp_id=l2.info["id"], opening_fee_params=fee_opt)
+
+ hint = [
+ [
+ {
+ "id": l2.info["id"],
+ "short_channel_id": buy_res["jit_channel_scid"],
+ "fee_base_msat": 0,
+ "fee_proportional_millionths": 0,
+ "cltv_expiry_delta": buy_res["lsp_cltv_expiry_delta"],
+ }
+ ]
+ ]
bolt11 = l1.dev_invoice(
amount_msat="any",
description="lsp-invoice-1",
label="lsp-invoice-1",
dev_routes=hint,
- )['bolt11']
+ )["bolt11"]
with pytest.raises(ValueError):
l3.rpc.pay(bolt11, amount_msat=10000000)
# l1 shouldn't have a new channel.
- chs = l1.rpc.listpeerchannels()['channels']
+ chs = l1.rpc.listpeerchannels()["channels"]
assert len(chs) == 0
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.