From 62a998f382b7329b36debb861534e2281f3fc235 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 31 May 2023 19:35:27 +0000 Subject: [PATCH] [Java] Add a trivial test of constructing a phantom invoice We had a user report that this was broken, though it was actually an NPE. --- src/test/java/org/ldk/HumanObjectPeerTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index b0128a5b..9eb8e62a 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -189,6 +189,7 @@ class HumanObjectPeerTestInstance { NioPeerHandler nio_peer_handler; short nio_port; final byte seed; + final byte[] key_seed = new byte[32]; final Logger logger; final FeeEstimator fee_estimator; final BroadcasterInterface tx_broadcaster; @@ -297,7 +298,6 @@ class HumanObjectPeerTestInstance { chain_watch = chain_monitor.as_Watch(); } - byte[] key_seed = new byte[32]; for (byte i = 0; i < 32; i++) { key_seed[i] = (byte) (i ^ seed); } @@ -899,6 +899,22 @@ class HumanObjectPeerTestInstance { String description_string = raw_invoice_description.into_inner(); assert description_string.equals("Invoice Description"); + // Do a trivial test of constructing a phantom invoice + Result_InvoiceSignOrCreationErrorZ phantom_invoice = UtilMethods.create_phantom_invoice( + Option_u64Z.some(42000), + new byte[32], // TODO: This needs to be an option/null, not interpreting all-0s as None + "Phantom Invoice", 7200, + new PhantomRouteHints[]{ peer2.chan_manager.get_phantom_route_hints() }, + peer2.entropy_source, + PhantomKeysManager.of(peer2.key_seed, 42, 42, new byte[32]).as_NodeSigner(), + peer2.logger, Currency.LDKCurrency_Bitcoin, Option_u16Z.none(), + System.currentTimeMillis() / 1000); + assert phantom_invoice.is_ok(); + RouteHint[] hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK)phantom_invoice).res.route_hints(); + assert hints.length == 1; + RouteHintHop[] val = hints[0].get_a(); + assert hints[0].get_a().length == 1; // Our one channel is public so we should just have a single-hop hint + if (!use_invoice_payer) { byte[] payment_hash = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash(); byte[] payment_secret = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_secret(); -- 2.39.5