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

Function checkPluginJSON

contrib/pyln-testing/pyln/testing/fixtures.py:750–803  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

748
749
750def checkPluginJSON(node):
751 if node.bad_notifications:
752 return 0
753
754 try:
755 notificationfiles = os.listdir("doc/schemas/notification")
756 except FileNotFoundError:
757 notificationfiles = []
758
759 notifications = {}
760 for fname in notificationfiles:
761 if fname.endswith(".json"):
762 base = fname.replace(".json", "")
763 # Request is 0 and Response is 1
764 notifications[base] = _load_schema(
765 os.path.join("doc/schemas/notification", fname)
766 )
767
768 # FIXME: add doc/schemas/hook/
769 hooks = {}
770
771 for f in (Path(node.daemon.lightning_dir) / "plugin-io").iterdir():
772 # e.g. hook_in-peer_connected-124567-358
773 io = json.loads(f.read_text())
774 parts = f.name.split("-")
775 if parts[0] == "hook_in":
776 schema = hooks.get(parts[1])
777 req = io["result"]
778 direction = 1
779 elif parts[0] == "hook_out":
780 schema = hooks.get(parts[1])
781 req = io["params"]
782 direction = 0
783 else:
784 assert parts[0] == "notification_out"
785 schema = notifications.get(parts[1])
786 # The notification is wrapped in an object of its own name.
787 req = io["params"][parts[1]]
788 direction = 1
789
790 # Until v26.09, with channel_state_changed.null_scid, that notification will be non-schema compliant.
791 if (
792 f.name.startswith("notification_out-channel_state_changed-")
793 and node.daemon.opts.get("allow-deprecated-apis", True) is True
794 ):
795 continue
796
797 if schema is not None:
798 try:
799 schema[direction].validate(req)
800 except jsonschema.exceptions.ValidationError as e:
801 print(f"Failed validating {f}: {e}")
802 return 1
803 return 0
804
805
806def checkBadReestablish(node):

Callers

nothing calls this directly

Calls 4

_load_schemaFunction · 0.85
joinMethod · 0.80
validateMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected