@@ -3925,6 +3925,30 @@ 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),"
3933+ " 'alias', alias, 'peer_connected', peer_connected,"
3934+ " 'state', state, 'short_channel_id', hex(short_channel_id),"
3935+ " 'channel_id', hex(channel_id), 'funding_txid', hex(funding_txid),"
3936+ " 'private', private, 'to_us_msat', to_us_msat, 'to_them_msat', (total_msat - to_us_msat),"
3937+ " 'total_msat', total_msat, 'their_reserve_msat', their_reserve_msat,"
3938+ " 'our_reserve_msat', our_reserve_msat, 'spendable_msat', spendable_msat,"
3939+ " 'direction', direction, 'receivable_msat', receivable_msat, 'fee_base_msat', fee_base_msat,"
3940+ " 'fee_proportional_millionths', fee_proportional_millionths, 'dust_limit_msat', dust_limit_msat,"
3941+ " 'htlcs', (SELECT json_group_array(json_object('id', hex(id), 'expiry', expiry,"
3942+ " 'amount_msat', amount_msat, 'payment_hash', hex(payment_hash), 'state', state))"
3943+ " FROM peerchannels_htlcs ph WHERE ph.row = pc.rowid)) FROM peerchannels pc JOIN nodes n"
3944+ " ON pc.peer_id = n.nodeid ORDER BY n.alias, pc.peer_id;" )
3945+ assert len (ret ['rows' ]) == 2
3946+ row1 = json .loads (ret ['rows' ][0 ][0 ])
3947+ row2 = json .loads (ret ['rows' ][1 ][0 ])
3948+ assert row1 ['peer_id' ] == format (l2 .info ['id' ].upper ())
3949+ assert len (row2 ['htlcs' ]) == 1
3950+ assert row2 ['htlcs' ][0 ]['amount_msat' ] == 1000000
3951+
39283952
39293953def test_sql_deprecated (node_factory , bitcoind ):
39303954 l1 , l2 = node_factory .line_graph (2 , opts = [{'allow-deprecated-apis' : True }, {}])
0 commit comments