tests: add sql json function tests
What changed, and why it matters
This commit only adds new automated tests for SQL JSON functions in the Core Lightning project. It does not change any production code, fix a bug, or introduce a security feature. There is no security relevance.
No security action needed. Treat as routine test coverage improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff appends a new test case to tests/test_plugin.py that exercises the SQL json_object and json_group_array functions against the peerchannels and peerchannels_htlcs tables. It verifies that JSON output contains expected peer IDs and HTLC amounts. No source code, RPC handlers, or database logic is modified.
Changed components
tests/test_plugin.pyInspect captured patch +15 / −0
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 761d82df..ece9a020 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -3925,6 +3925,21 @@ def test_sql(node_factory, bitcoind):
l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
wait_for(lambda: l3.rpc.sql("SELECT * FROM nodes WHERE alias = '{}'".format(alias))['rows'] != [])
+ # Test json functions
+ l1.fundchannel(l2)
+ bitcoind.generate_block(6)
+ l1.rpc.pay(l2.rpc.invoice(amount_msat=1000000, label='inv1000', description='description 1000 msat')['bolt11'])
+ ret = l1.rpc.sql("SELECT json_object('peer_id', hex(pc.peer_id), 'alias', alias, 'htlcs',"
+ " (SELECT json_group_array(json_object('id', hex(id), 'amount_msat', amount_msat))"
+ " FROM peerchannels_htlcs ph WHERE ph.row = pc.rowid)) FROM peerchannels pc JOIN nodes n"
+ " ON pc.peer_id = n.nodeid ORDER BY n.alias, pc.peer_id;")
+ assert len(ret['rows']) == 2
+ row1 = json.loads(ret['rows'][0][0])
+ row2 = json.loads(ret['rows'][1][0])
+ assert row1['peer_id'] == format(l2.info['id'].upper())
+ assert len(row2['htlcs']) == 1
+ assert row2['htlcs'][0]['amount_msat'] == 1000000
+
def test_sql_deprecated(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, opts=[{'allow-deprecated-apis': True}, {}])
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.