From 65f5bb263824e939fae37e85dc22448cc7541441 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 22 Mar 2022 19:22:13 +1030 Subject: [PATCH] pytest: test for compat code. Signed-off-by: Rusty Russell --- plugins/offers_invreq_hook.c | 7 +++++-- tests/test_pay.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index c5fd0bb5b..13cb896a1 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -419,7 +419,8 @@ static struct command_result *check_previous_invoice(struct command *cmd, /* BOLT-offers #12: * - MUST fail the request if `signature` is not correct. */ -static bool check_payer_sig(const struct tlv_invoice_request *invreq, +static bool check_payer_sig(struct command *cmd, + const struct tlv_invoice_request *invreq, const struct point32 *payer_key, const struct bip340sig *sig) { @@ -436,6 +437,8 @@ static bool check_payer_sig(const struct tlv_invoice_request *invreq, return false; /* Try old name */ + plugin_log(cmd->plugin, LOG_DBG, + "Testing invoice_request with old name 'payer_signature'"); sighash_from_merkle("invoice_request", "payer_signature", &merkle, &sighash); @@ -728,7 +731,7 @@ static struct command_result *listoffers_done(struct command *cmd, err = invreq_must_have(cmd, ir, signature); if (err) return err; - if (!check_payer_sig(ir->invreq, + if (!check_payer_sig(cmd, ir->invreq, ir->invreq->payer_key, ir->invreq->signature)) { return fail_invreq(cmd, ir, "bad signature"); diff --git a/tests/test_pay.py b/tests/test_pay.py index 12a5c8b62..d55dade1d 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -4453,6 +4453,20 @@ def test_offer(node_factory, bitcoind): assert 'recurrence: every 600 seconds paywindow -10 to +600 (pay proportional)\n' in output +def test_deprecated_offer(node_factory, bitcoind): + """Test that we allow old invreq name `payer_signature` with deprecated_apis""" + l1, l2 = node_factory.line_graph(2, opts={'experimental-offers': None, + 'allow-deprecated-apis': True}) + + offer = l2.rpc.call('offer', {'amount': 10000, + 'description': 'test'})['bolt12'] + + inv = l1.rpc.call('fetchinvoice', {'offer': offer})['invoice'] + l2.daemon.wait_for_log("Testing invoice_request with old name 'payer_signature'") + + l1.rpc.pay(inv) + + @pytest.mark.developer("dev-no-modern-onion is DEVELOPER-only") def test_fetchinvoice_3hop(node_factory, bitcoind): l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True,