[Java] Add a trivial test of constructing a phantom invoice
[ldk-java] / src / test / java / org / ldk / HumanObjectPeerTest.java
index effa0460e7c46fc4eb995cb08997f95cf571dd64..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);
             }
@@ -379,7 +379,8 @@ class HumanObjectPeerTestInstance {
 
             if (use_chan_manager_constructor) {
                 this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, get_config(), new byte[32], 0,
-                        this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, this.net_graph,
+                        this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
+                        this.fee_estimator, this.chain_monitor, this.net_graph,
                         ProbabilisticScoringParameters.with_default(), (ChannelManagerConstructor.RouterWrapper)
                             (payer_node_id, route_params, first_hops, inflight_htlcs, payment_hash, payment_id, default_router) -> {
                                 assert payment_hash != null && payment_id != null;
@@ -466,7 +467,8 @@ class HumanObjectPeerTestInstance {
                         filter_nullable = ((Option_FilterZ.Some) this.filter).some;
                     }
                     this.constructor = new ChannelManagerConstructor(serialized, monitors, get_config(),
-                            this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, filter_nullable,
+                        this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
+                        this.fee_estimator, this.chain_monitor, filter_nullable,
                             serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer, null,
                             this.tx_broadcaster, this.logger);
                     try {
@@ -475,7 +477,8 @@ class HumanObjectPeerTestInstance {
                         monitors_dupd[0] = monitors[0];
                         monitors_dupd[1] = monitors[0];
                         ChannelManagerConstructor constr = new ChannelManagerConstructor(serialized, monitors_dupd, get_config(),
-                                this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, filter_nullable,
+                            this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
+                            this.fee_estimator, this.chain_monitor, filter_nullable,
                                 serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer, null,
                                 this.tx_broadcaster, this.logger);
                         assert false;
@@ -896,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();