Skip to content

Commit 6276383

Browse files
committed
Add test for gossip data fetching
This tests the changes in #114 for regression, and failed prior to #114.
1 parent 096b386 commit 6276383

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,17 @@ private ChannelMonitor test_mon_roundtrip(OutPoint expected_id, byte[] data) {
211211
// ChannelMonitor is. This used to be broken.
212212
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ roundtrip_monitor = UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(data, keys_interface);
213213
assert roundtrip_monitor instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
214+
must_free_objs.add(new WeakReference<>(roundtrip_monitor));
214215
TwoTuple_OutPointScriptZ funding_txo = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_monitor).res.get_b().get_funding_txo();
216+
must_free_objs.add(new WeakReference<>(funding_txo));
215217
System.gc(); System.runFinalization(); // Give the GC a chance to run.
216218
assert Arrays.equals(funding_txo.get_a().get_txid(), expected_id.get_txid());
217219
assert funding_txo.get_a().get_index() == expected_id.get_index();
218220
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ roundtrip_two = UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(data, keys_interface);
219221
assert roundtrip_two instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
222+
must_free_objs.add(new WeakReference<>(((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_two).res.get_b()));
223+
must_free_objs.add(new WeakReference<>(((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_two).res));
224+
must_free_objs.add(new WeakReference<>(roundtrip_two));
220225
return ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_two).res.get_b();
221226
}
222227

@@ -399,11 +404,25 @@ private void setup_route_handler() {
399404
this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() {
400405
@Override
401406
public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, byte[] payment_hash, ChannelDetails[] first_hops, Score scorer) {
402-
// Take a read lock on the NetworkGraph just to make sure we even can.
403-
try (ReadOnlyNetworkGraph graph = router.read_only()) {
404-
assert graph.channel(424242) == null;
405-
return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer, new byte[32]);
407+
while (true) {
408+
try (ReadOnlyNetworkGraph graph = router.read_only()) {
409+
assert graph.channel(424242) == null;
410+
long[] channels = graph.list_channels();
411+
if (channels.length != 1) {
412+
// If we're using a NioPeerHandler, the handling of announcement signatures and
413+
// channel broadcasting may be done async, so just wait until the channel shows up.
414+
// TODO: Once https://github.com/lightningdevkit/rust-lightning/pull/1666 lands swap this for a continue and add the assertion
415+
//assert !use_nio_peer_handler;
416+
break;
417+
}
418+
ChannelInfo chan = graph.channel(channels[0]);
419+
assert Arrays.equals(chan.get_node_one().as_slice(), chan.get_node_one().write());
420+
assert Arrays.equals(chan.get_node_one().as_slice(), chan_manager.get_our_node_id()) ||
421+
Arrays.equals(chan.get_node_two().as_slice(), chan_manager.get_our_node_id());
422+
break;
423+
}
406424
}
425+
return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer, new byte[32]);
407426
}
408427
}), MultiThreadedLockableScore.of(Score.new_impl(new Score.ScoreInterface() {
409428
@Override public void payment_path_failed(RouteHop[] path, long scid) {}

0 commit comments

Comments
 (0)