Skip to content

Commit bab6429

Browse files
ShahanaFarooquirustyrussell
authored andcommitted
tests: add sql json function tests
1 parent d5c7318 commit bab6429

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_plugin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,6 +3925,21 @@ def test_sql(node_factory, bitcoind):
39253925
l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
39263926
wait_for(lambda: l3.rpc.sql("SELECT * FROM nodes WHERE alias = '{}'".format(alias))['rows'] != [])
39273927

3928+
# Test json functions
3929+
l1.fundchannel(l2)
3930+
bitcoind.generate_block(6)
3931+
l1.rpc.pay(l2.rpc.invoice(amount_msat=1000000, label='inv1000', description='description 1000 msat')['bolt11'])
3932+
ret = l1.rpc.sql("SELECT json_object('peer_id', hex(pc.peer_id), 'alias', alias, 'htlcs',"
3933+
" (SELECT json_group_array(json_object('id', hex(id), 'amount_msat', amount_msat))"
3934+
" FROM peerchannels_htlcs ph WHERE ph.row = pc.rowid)) FROM peerchannels pc JOIN nodes n"
3935+
" ON pc.peer_id = n.nodeid ORDER BY n.alias, pc.peer_id;")
3936+
assert len(ret['rows']) == 2
3937+
row1 = json.loads(ret['rows'][0][0])
3938+
row2 = json.loads(ret['rows'][1][0])
3939+
assert row1['peer_id'] == format(l2.info['id'].upper())
3940+
assert len(row2['htlcs']) == 1
3941+
assert row2['htlcs'][0]['amount_msat'] == 1000000
3942+
39283943

39293944
def test_sql_deprecated(node_factory, bitcoind):
39303945
l1, l2 = node_factory.line_graph(2, opts=[{'allow-deprecated-apis': True}, {}])

0 commit comments

Comments
 (0)