What changed, and why it matters
This commit only changes test code. It makes anchor channels the default setting for Electrum's Lightning test suite and removes the need to pass an explicit 'has_anchors' flag when creating mock wallets in tests. There is no change to the actual wallet or Lightning code that users run, so it does not affect real-world security.
No security action needed; this is a test-only refactoring. Reviewers may optionally verify that the new non-anchor test subclasses still exercise the legacy channel type as intended.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the test harness in tests/init.py so that TEST_ANCHOR_CHANNELS defaults to True and create_mock_lnwallet derives has_anchors from that class attribute instead of taking it as a parameter. Call sites across test_lnchannel.py, test_lnpeer.py, test_lnpeermgr.py, test_lnwallet.py, and test_onion_message.py are updated accordingly. Existing anchor-specific test subclasses are replaced with non-anchor subclasses that override TEST_ANCHOR_CHANNELS to False. No production code is modified.
Changed components
tests/__init__.pytests/test_lnchannel.pytests/test_lnpeer.pytests/test_lnpeermgr.pytests/test_lnwallet.pytests/test_onion_message.pyInspect captured patch +27 / −25
diff --git a/tests/__init__.py b/tests/__init__.py
index 0890fd0..fd2143d 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -37,7 +37,7 @@ class ElectrumTestCase(unittest.IsolatedAsyncioTestCase, Logger):
TESTNET = False # there is also an @as_testnet decorator to run single tests in testnet mode
REGTEST = False
- TEST_ANCHOR_CHANNELS = False
+ TEST_ANCHOR_CHANNELS = True
WALLET_FILES_DIR = os.path.join(os.path.dirname(__file__), "test_storage_upgrade")
# maxDiff = None # for debugging
@@ -103,11 +103,10 @@ class ElectrumTestCase(unittest.IsolatedAsyncioTestCase, Logger):
self,
*,
name: str,
- has_anchors: bool,
) -> 'MockLNWallet':
from .test_lnpeer import _create_mock_lnwallet
data_dir = tempfile.mkdtemp(prefix="lnwallet-", dir=self.unittest_base_path)
- lnwallet = _create_mock_lnwallet(name=name, has_anchors=has_anchors, data_dir=data_dir)
+ lnwallet = _create_mock_lnwallet(name=name, has_anchors=self.TEST_ANCHOR_CHANNELS, data_dir=data_dir)
self._lnworkers_created.append(lnwallet)
return lnwallet
diff --git a/tests/test_lnchannel.py b/tests/test_lnchannel.py
index 759fd22..972855f 100644
--- a/tests/test_lnchannel.py
+++ b/tests/test_lnchannel.py
@@ -266,8 +266,8 @@ class TestFee(ElectrumTestCase):
async def asyncSetUp(self):
await super().asyncSetUp()
- self.alice_lnwallet = self.create_mock_lnwallet(name="alice", has_anchors=self.TEST_ANCHOR_CHANNELS)
- self.bob_lnwallet = self.create_mock_lnwallet(name="bob", has_anchors=self.TEST_ANCHOR_CHANNELS)
+ self.alice_lnwallet = self.create_mock_lnwallet(name="alice")
+ self.bob_lnwallet = self.create_mock_lnwallet(name="bob")
async def test_fee(self):
alice_channel, bob_channel = create_test_channels(
@@ -301,8 +301,8 @@ class TestChannel(ElectrumTestCase):
async def asyncSetUp(self):
await super().asyncSetUp()
- self.alice_lnwallet = self.create_mock_lnwallet(name="alice", has_anchors=self.TEST_ANCHOR_CHANNELS)
- self.bob_lnwallet = self.create_mock_lnwallet(name="bob", has_anchors=self.TEST_ANCHOR_CHANNELS)
+ self.alice_lnwallet = self.create_mock_lnwallet(name="alice")
+ self.bob_lnwallet = self.create_mock_lnwallet(name="bob")
# Create a test channel which will be used for the duration of this
# unittest. The channel will be funded evenly with Alice having 5 BTC,
@@ -856,8 +856,8 @@ class TestChannelAnchors(TestChannel):
class TestAvailableToSpend(ElectrumTestCase):
async def asyncSetUp(self):
await super().asyncSetUp()
- self.alice_lnwallet = self.create_mock_lnwallet(name="alice", has_anchors=self.TEST_ANCHOR_CHANNELS)
- self.bob_lnwallet = self.create_mock_lnwallet(name="bob", has_anchors=self.TEST_ANCHOR_CHANNELS)
+ self.alice_lnwallet = self.create_mock_lnwallet(name="alice")
+ self.bob_lnwallet = self.create_mock_lnwallet(name="bob")
async def test_DesyncHTLCs(self):
alice_channel, bob_channel = create_test_channels(
@@ -972,8 +972,8 @@ class TestAvailableToSpendAnchors(TestAvailableToSpend):
class TestChanReserve(ElectrumTestCase):
async def asyncSetUp(self):
await super().asyncSetUp()
- alice_lnwallet = self.create_mock_lnwallet(name="alice", has_anchors=self.TEST_ANCHOR_CHANNELS)
- bob_lnwallet = self.create_mock_lnwallet(name="bob", has_anchors=self.TEST_ANCHOR_CHANNELS)
+ alice_lnwallet = self.create_mock_lnwallet(name="alice")
+ bob_lnwallet = self.create_mock_lnwallet(name="bob")
alice_channel, bob_channel = create_test_channels(alice_lnwallet=alice_lnwallet, bob_lnwallet=bob_lnwallet)
alice_min_reserve = int(.5 * one_bitcoin_in_msat // 1000)
# We set Bob's channel reserve to a value that is larger than
@@ -1109,8 +1109,8 @@ class TestChanReserveAnchors(TestChanReserve):
class TestDust(ElectrumTestCase):
async def asyncSetUp(self):
await super().asyncSetUp()
- self.alice_lnwallet = self.create_mock_lnwallet(name="alice", has_anchors=self.TEST_ANCHOR_CHANNELS)
- self.bob_lnwallet = self.create_mock_lnwallet(name="bob", has_anchors=self.TEST_ANCHOR_CHANNELS)
+ self.alice_lnwallet = self.create_mock_lnwallet(name="alice")
+ self.bob_lnwallet = self.create_mock_lnwallet(name="bob")
async def test_DustLimit(self):
"""Test that addition of an HTLC below the dust limit changes the balances."""
diff --git a/tests/test_lnpeer.py b/tests/test_lnpeer.py
index 9d4d106..e88a53b 100644
--- a/tests/test_lnpeer.py
+++ b/tests/test_lnpeer.py
@@ -484,7 +484,7 @@ class TestPeer(ElectrumTestCase):
def prepare_lnwallets(self, graph_definition) -> Mapping[str, MockLNWallet]:
workers = {} # type: Dict[str, MockLNWallet]
for a, definition in graph_definition.items():
- workers[a] = self.create_mock_lnwallet(name=a, has_anchors=self.TEST_ANCHOR_CHANNELS)
+ workers[a] = self.create_mock_lnwallet(name=a)
return workers
def prepare_chans_and_peers_in_graph(
@@ -3047,11 +3047,13 @@ class TestPeerForwarding(TestPeer):
await run_test(trampoline)
-class TestPeerDirectAnchors(TestPeerDirect):
- TEST_ANCHOR_CHANNELS = True
+class TestPeerDirectNoAnchors(TestPeerDirect):
+ assert TestPeerDirect.TEST_ANCHOR_CHANNELS is True
+ TEST_ANCHOR_CHANNELS = False
-class TestPeerForwardingAnchors(TestPeerForwarding):
- TEST_ANCHOR_CHANNELS = True
+class TestPeerForwardinNoAnchors(TestPeerForwarding):
+ assert TestPeerForwarding.TEST_ANCHOR_CHANNELS is True
+ TEST_ANCHOR_CHANNELS = False
def run(coro):
diff --git a/tests/test_lnpeermgr.py b/tests/test_lnpeermgr.py
index 01f9444..7603346 100644
--- a/tests/test_lnpeermgr.py
+++ b/tests/test_lnpeermgr.py
@@ -19,7 +19,7 @@ class TestLNPeerManager(ElectrumTestCase):
console_stderr_handler.setLevel(logging.DEBUG)
async def asyncSetUp(self):
- lnwallet = self.create_mock_lnwallet(name='mock_lnwallet_anchors', has_anchors=True)
+ lnwallet = self.create_mock_lnwallet(name='mock_lnwallet_anchors')
self.lnpeermgr = lnwallet.lnpeermgr
await super().asyncSetUp()
diff --git a/tests/test_lnwallet.py b/tests/test_lnwallet.py
index d4f94ce..8c82866 100644
--- a/tests/test_lnwallet.py
+++ b/tests/test_lnwallet.py
@@ -21,6 +21,7 @@ from electrum.crypto import sha256
class TestLNWallet(ElectrumTestCase):
TESTNET = True
+ TEST_ANCHOR_CHANNELS = True
@classmethod
def setUpClass(cls):
@@ -28,7 +29,7 @@ class TestLNWallet(ElectrumTestCase):
console_stderr_handler.setLevel(logging.DEBUG)
async def asyncSetUp(self):
- self.lnwallet_anchors = self.create_mock_lnwallet(name='mock_lnwallet_anchors', has_anchors=True)
+ self.lnwallet_anchors = self.create_mock_lnwallet(name='mock_lnwallet_anchors')
await super().asyncSetUp()
def test_create_payment_info(self):
@@ -73,10 +74,10 @@ class TestLNWallet(ElectrumTestCase):
wallet = self.lnwallet_anchors
self.assertFalse(wallet.uses_trampoline())
- trampoline_peer = self.create_mock_lnwallet(name='trampoline_peer', has_anchors=True)
+ trampoline_peer = self.create_mock_lnwallet(name='trampoline_peer')
trampoline_pubkey = trampoline_peer.node_keypair.pubkey
- regular_peer = self.create_mock_lnwallet(name='regular_peer', has_anchors=True)
+ regular_peer = self.create_mock_lnwallet(name='regular_peer')
regular_pubkey = regular_peer.node_keypair.pubkey
chan_t, _ = create_test_channels(alice_lnwallet=wallet, bob_lnwallet=trampoline_peer)
diff --git a/tests/test_onion_message.py b/tests/test_onion_message.py
index 63e5803..b3fb76d 100644
--- a/tests/test_onion_message.py
+++ b/tests/test_onion_message.py
@@ -373,7 +373,7 @@ class TestOnionMessageManager(ElectrumTestCase):
async def test_request_and_reply(self):
n = MockNetwork()
- lnw = self.create_mock_lnwallet(name='test_request_and_reply', has_anchors=False)
+ lnw = self.create_mock_lnwallet(name='test_request_and_reply')
# mock add_peer for direct connection fallback
async def mock__add_peer(host, port, node_id):
@@ -431,7 +431,7 @@ class TestOnionMessageManager(ElectrumTestCase):
async def test_forward(self):
n = MockNetwork()
- lnw = self.create_mock_lnwallet(name='alice', has_anchors=False)
+ lnw = self.create_mock_lnwallet(name='alice')
lnw.node_keypair = self.alice
self.was_sent = False
@@ -468,7 +468,7 @@ class TestOnionMessageManager(ElectrumTestCase):
async def test_receive_unsolicited(self):
n = MockNetwork()
- lnw = self.create_mock_lnwallet(name='dave', has_anchors=False)
+ lnw = self.create_mock_lnwallet(name='dave')
lnw.node_keypair = self.dave
t = OnionMessageManager(lnw)
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.