From 33be5c8d805a48d2a0904bbaf5f7ffb15d23438e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 6 Jun 2023 11:29:03 +0930 Subject: [PATCH] commando: integer command parameters can be compared with < and >. Previously any attempt would result in "is not an integer field"; we now recognize valid JSON integers as integer fields. Changelog-Fixed: Plugins: `commando` runes can now compare integer parameters using '<' and '>' as expected. Signed-off-by: Rusty Russell --- plugins/commando.c | 12 ++++++++++++ tests/test_plugin.py | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/commando.c b/plugins/commando.c index 5df9032f7..7871da531 100644 --- a/plugins/commando.c +++ b/plugins/commando.c @@ -427,6 +427,18 @@ static const char *check_condition(const tal_t *ctx, if (!ptok) return rune_alt_single_missing(ctx, alt); + /* Pass through valid integers as integers. */ + if (ptok->type == JSMN_PRIMITIVE) { + s64 val; + + if (json_to_s64(cinfo->buf, ptok, &val)) { + plugin_log(plugin, LOG_DBG, "It's an int %"PRId64, val); + return rune_alt_single_int(ctx, alt, val); + } + + /* Otherwise, treat it as a string (< and > will fail with + * "is not an integer field") */ + } return rune_alt_single_str(ctx, alt, cinfo->buf + ptok->start, ptok->end - ptok->start); diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 8cf3ca9bb..06879dd83 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2991,7 +2991,6 @@ def test_commando_listrunes(node_factory): assert not_our_rune['our_rune'] is False -@pytest.mark.xfail(strict=True) def test_commando_rune_pay_amount(node_factory): l1, l2 = node_factory.line_graph(2)