Skip to content

Commit 6be0982

Browse files
committed
pytest: clean up JSON sql test.
1. Establish a channel with l3; we already have one with l2. 2. Don't bother generating 6 more blocks (fundchannel ensures it's mined). 3. Allow htlcs to be empty: Whitslack reported that happens for him 4. Use only_one() to access where we insist there is only one element in the list. 5. Tighten tests to assert the exact contents, not just test some. Signed-off-by: Rusty Russell <[email protected]> Fixes: #8497
1 parent ef44e3c commit 6be0982

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/test_plugin.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4045,19 +4045,29 @@ def test_sql(node_factory, bitcoind):
40454045
wait_for(lambda: l3.rpc.sql("SELECT * FROM nodes WHERE alias = '{}'".format(alias))['rows'] != [])
40464046

40474047
# Test json functions
4048-
l1.fundchannel(l2)
4049-
bitcoind.generate_block(6)
4050-
l1.rpc.pay(l2.rpc.invoice(amount_msat=1000000, label='inv1000', description='description 1000 msat')['bolt11'])
4051-
ret = l1.rpc.sql("SELECT json_object('peer_id', hex(pc.peer_id), 'alias', alias, 'htlcs',"
4048+
scidl1l3, _ = l1.fundchannel(l3)
4049+
l1.rpc.pay(l3.rpc.invoice(amount_msat=1000000, label='inv1000', description='description 1000 msat')['bolt11'])
4050+
4051+
# Two channels, l1->l3 *may* have an HTLC in flight.
4052+
ret = l1.rpc.sql("SELECT json_object('peer_id', hex(pc.peer_id), 'alias', alias, 'scid', short_channel_id, 'htlcs',"
40524053
" (SELECT json_group_array(json_object('id', hex(id), 'amount_msat', amount_msat))"
40534054
" FROM peerchannels_htlcs ph WHERE ph.row = pc.rowid)) FROM peerchannels pc JOIN nodes n"
40544055
" ON pc.peer_id = n.nodeid ORDER BY n.alias, pc.peer_id;")
40554056
assert len(ret['rows']) == 2
4056-
row1 = json.loads(ret['rows'][0][0])
4057-
row2 = json.loads(ret['rows'][1][0])
4058-
assert row1['peer_id'] == format(l2.info['id'].upper())
4059-
assert len(row2['htlcs']) == 1
4060-
assert row2['htlcs'][0]['amount_msat'] == 1000000
4057+
row1 = json.loads(only_one(ret['rows'][0]))
4058+
row2 = json.loads(only_one(ret['rows'][1]))
4059+
assert row1 in ({"peer_id": format(l3.info['id'].upper()),
4060+
"alias": l3.rpc.getinfo()['alias'],
4061+
"scid": scidl1l3,
4062+
"htlcs": []},
4063+
{"peer_id": format(l3.info['id'].upper()),
4064+
"alias": l3.rpc.getinfo()['alias'],
4065+
"scid": scidl1l3,
4066+
"htlcs": [{"id": "30", "amount_msat": 1000000}]})
4067+
assert row2 == {"peer_id": format(l2.info['id'].upper()),
4068+
"alias": l2.rpc.getinfo()['alias'],
4069+
"scid": scid,
4070+
"htlcs": []}
40614071

40624072

40634073
def test_sql_deprecated(node_factory, bitcoind):

0 commit comments

Comments
 (0)