pytest: add tests for channel_state_changed into the CLOSED state.
What changed, and why it matters
This commit only adds and adjusts Python test code for the Core Lightning project. It extends existing tests to verify that a 'channel_state_changed' notification is correctly emitted when a payment channel transitions into the CLOSED state. There are no changes to production code, no bug fixes, and no security-sensitive behavior being altered.
No security action needed. This is a normal test-only commit. Reviewers may optionally verify that the new assertions accurately reflect expected CLOSED-state notification semantics.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/test_plugin.py. It changes block generation counts from 100 to 99 (so an additional single block can be generated separately) and adds assertions checking that both nodes in bilateral and unilateral close scenarios emit a channel_state_changed event with old_state=’ONCHAIN’ and new_state=’CLOSED’. This is purely test coverage for plugin notification behavior.
Changed components
tests/test_plugin.pyInspect captured patch +28 / −3
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 3f26208e..61cb6b59 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -940,7 +940,7 @@ def test_channel_state_changed_bilateral(node_factory, bitcoind):
assert(event2['cause'] == "remote")
assert(event2['message'] == "Closing complete")
- bitcoind.generate_block(100, wait_for_mempool=1) # so it gets settled
+ bitcoind.generate_block(99, wait_for_mempool=1) # so it gets settled
event1 = wait_for_event(l1)
assert(event1['old_state'] == "CLOSINGD_COMPLETE")
@@ -964,6 +964,18 @@ def test_channel_state_changed_bilateral(node_factory, bitcoind):
assert(event2['cause'] == "remote")
assert(event2['message'] == "Onchain init reply")
+ bitcoind.generate_block(1)
+ event1 = wait_for_event(l1)
+ assert(event1['old_state'] == "ONCHAIN")
+ assert(event1['new_state'] == "CLOSED")
+ assert(event1['cause'] == "unknown")
+ assert('message' not in event1)
+ event2 = wait_for_event(l2)
+ assert(event2['old_state'] == "ONCHAIN")
+ assert(event2['new_state'] == "CLOSED")
+ assert(event2['cause'] == "unknown")
+ assert('message' not in event2)
+
@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@@ -1058,8 +1070,8 @@ def test_channel_state_changed_unilateral(node_factory, bitcoind):
assert(event1['cause'] == "protocol")
assert(event1['message'] == "channeld: received ERROR channel {}: Forcibly closed by `close` command timeout".format(cid))
- # settle the channel closure
- bitcoind.generate_block(100)
+ # Almost settle the channel closure
+ bitcoind.generate_block(99, wait_for_mempool=1)
event2 = wait_for_event(l2)
assert(event2['old_state'] == "AWAITING_UNILATERAL")
@@ -1087,6 +1099,19 @@ def test_channel_state_changed_unilateral(node_factory, bitcoind):
assert(event1['cause'] == "onchain")
assert(event1['message'] == "Onchain init reply")
+ bitcoind.generate_block(1)
+ event1 = wait_for_event(l1)
+ assert(event1['old_state'] == "ONCHAIN")
+ assert(event1['new_state'] == "CLOSED")
+ assert(event1['cause'] == "unknown")
+ assert('message' not in event1)
+
+ event2 = wait_for_event(l2)
+ assert(event2['old_state'] == "ONCHAIN")
+ assert(event2['new_state'] == "CLOSED")
+ assert(event2['cause'] == "unknown")
+ assert('message' not in event2)
+
@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
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.