MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_channel_state_changed_unilateral

Function test_channel_state_changed_unilateral

tests/test_plugin.py:896–1004  ·  view source on GitHub ↗

We open, disconnect, force-close a channel and check for notifications. The misc_notifications.py plugin logs `channel_state_changed` events.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

894@pytest.mark.openchannel('v1')
895@pytest.mark.openchannel('v2')
896def test_channel_state_changed_unilateral(node_factory, bitcoind):
897 """ We open, disconnect, force-close a channel and check for notifications.
898
899 The misc_notifications.py plugin logs `channel_state_changed` events.
900 """
901 opts = {"plugin": os.path.join(os.getcwd(), "tests/plugins/misc_notifications.py"),
902 "allow_warning": True,
903 'may_reconnect': True}
904
905 l1, l2 = node_factory.line_graph(2, opts=opts)
906
907 l1_id = l1.rpc.getinfo()["id"]
908 cid = l1.get_channel_id(l2)
909 scid = l1.get_channel_scid(l2)
910
911 # a helper that gives us the next channel_state_changed log entry
912 def wait_for_event(node):
913 msg = node.daemon.wait_for_log("channel_state_changed.*new_state.*")
914 event = ast.literal_eval(re.findall(".*({.*}).*", msg)[0])
915 return event
916
917 event2 = wait_for_event(l2)
918 assert(event2['peer_id'] == l1_id)
919 assert(event2['channel_id'] == cid)
920 assert(event2['short_channel_id'] is None)
921 assert(event2['cause'] == "remote")
922
923 if l2.config('experimental-dual-fund'):
924 assert(event2['old_state'] == "DUALOPEND_OPEN_INIT")
925 assert(event2['new_state'] == "DUALOPEND_AWAITING_LOCKIN")
926 assert(event2['message'] == "Sigs exchanged, waiting for lock-in")
927 else:
928 assert(event2['old_state'] == "unknown")
929 assert(event2['new_state'] == "CHANNELD_AWAITING_LOCKIN")
930 assert(event2['message'] == "new channel opened")
931
932 event2 = wait_for_event(l2)
933 assert(event2['short_channel_id'] == scid)
934 if l2.config('experimental-dual-fund'):
935 assert(event2['old_state'] == "DUALOPEND_AWAITING_LOCKIN")
936 else:
937 assert(event2['old_state'] == "CHANNELD_AWAITING_LOCKIN")
938 assert(event2['new_state'] == "CHANNELD_NORMAL")
939 assert(event2['cause'] == "remote")
940 assert(event2['message'] == "Lockin complete")
941
942 # close channel unilaterally and look for stateful events
943 l1.rpc.stop()
944 wait_for(lambda: not only_one(l2.rpc.listpeers()['peers'])['connected'])
945 l2.rpc.close(scid, 1) # force close after 1sec timeout
946
947 event2 = wait_for_event(l2)
948 assert(event2['old_state'] == "CHANNELD_NORMAL")
949 assert(event2['new_state'] == "CHANNELD_SHUTTING_DOWN")
950 assert(event2['cause'] == "user")
951 assert(event2['message'] == "User or plugin invoked close command")
952 event2 = wait_for_event(l2)
953 assert(event2['old_state'] == "CHANNELD_SHUTTING_DOWN")

Callers

nothing calls this directly

Calls 15

wait_forFunction · 0.90
only_oneFunction · 0.90
wait_for_eventFunction · 0.85
joinMethod · 0.80
line_graphMethod · 0.80
get_channel_idMethod · 0.80
get_channel_scidMethod · 0.80
configMethod · 0.80
restartMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80
getinfoMethod · 0.45

Tested by

no test coverage detected