]> git.bitcoin.ninja Git - ldk-java/commitdiff
[Java] Add a trivial test of constructing a phantom invoice
authorMatt Corallo <git@bluematt.me>
Wed, 31 May 2023 19:35:27 +0000 (19:35 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 1 Jun 2023 20:23:10 +0000 (20:23 +0000)
We had a user report that this was broken, though it was actually
an NPE.

src/test/java/org/ldk/HumanObjectPeerTest.java

index b0128a5b4b1ac50dc251711e09a599d0cf598d9b..9eb8e62a386cc3b3ecc1dfe16d91f0a219880251 100644 (file)
@@ -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();