Skip to content

Commit 09a0906

Browse files
committed
[Java] Update tests to LDK 0.0.115
1 parent 4a36fa9 commit 09a0906

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.ldk;
22

3+
import org.bitcoinj.base.BitcoinNetwork;
4+
import org.bitcoinj.base.Coin;
5+
import org.bitcoinj.base.Sha256Hash;
36
import org.bitcoinj.core.*;
7+
import org.bitcoinj.params.BitcoinNetworkParams;
48
import org.bitcoinj.script.Script;
59
import org.junit.jupiter.api.Test;
610
import org.ldk.batteries.ChannelManagerConstructor;
@@ -425,11 +429,11 @@ public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters para
425429
}
426430
}
427431
return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, Score.new_impl(new Score.ScoreInterface() {
428-
@Override public void payment_path_failed(RouteHop[] path, long scid) {}
432+
@Override public void payment_path_failed(Path path, long scid) {}
429433
@Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage) { return 0; }
430-
@Override public void payment_path_successful(RouteHop[] path) {}
431-
@Override public void probe_failed(RouteHop[] path, long short_channel_id) { assert false; }
432-
@Override public void probe_successful(RouteHop[] path) { assert false; }
434+
@Override public void payment_path_successful(Path path) {}
435+
@Override public void probe_failed(Path path, long short_channel_id) { assert false; }
436+
@Override public void probe_successful(Path path) { assert false; }
433437
@Override public byte[] write() { assert false; return null; }
434438
}), new byte[32]);
435439
}
@@ -530,11 +534,11 @@ public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters para
530534
}
531535
}
532536
return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, Score.new_impl(new Score.ScoreInterface() {
533-
@Override public void payment_path_failed(RouteHop[] path, long scid) {}
537+
@Override public void payment_path_failed(Path path, long scid) {}
534538
@Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage) { return 0; }
535-
@Override public void payment_path_successful(RouteHop[] path) {}
536-
@Override public void probe_failed(RouteHop[] path, long short_channel_id) { assert false; }
537-
@Override public void probe_successful(RouteHop[] path) { assert false; }
539+
@Override public void payment_path_successful(Path path) {}
540+
@Override public void probe_failed(Path path, long short_channel_id) { assert false; }
541+
@Override public void probe_successful(Path path) { assert false; }
538542
@Override public byte[] write() { assert false; return null; }
539543
}), new byte[32]);
540544
}
@@ -817,7 +821,7 @@ TestState do_test_message_handler() throws InterruptedException {
817821
assert funding_spk.length == 34 && funding_spk[0] == 0 && funding_spk[1] == 32; // P2WSH
818822
byte[] chan_id = ((Event.FundingGenerationReady) events[0]).temporary_channel_id;
819823

820-
NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
824+
BitcoinNetworkParams bitcoinj_net = BitcoinNetworkParams.of(BitcoinNetwork.MAINNET);
821825

822826
Transaction funding = new Transaction(bitcoinj_net);
823827
funding.addInput(new TransactionInput(bitcoinj_net, funding, new byte[0]));
@@ -836,6 +840,12 @@ TestState do_test_message_handler() throws InterruptedException {
836840
}
837841
}
838842

843+
events = peer1.get_manager_events(1, peer1, peer2);
844+
assert events[0] instanceof Event.ChannelPending;
845+
846+
events = peer2.get_manager_events(1, peer1, peer2);
847+
assert events[0] instanceof Event.ChannelPending;
848+
839849
assert peer1.broadcast_set.size() == 1;
840850
assert Arrays.equals(peer1.broadcast_set.get(0), funding.bitcoinSerialize());
841851
peer1.broadcast_set.clear();
@@ -877,6 +887,7 @@ TestState do_test_message_handler() throws InterruptedException {
877887

878888
Result_InvoiceParseOrSemanticErrorZ parsed_invoice = Invoice.from_str(((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str());
879889
assert parsed_invoice instanceof Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK;
890+
//assert ((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res.fallback_addresses().length == 0;
880891
assert Arrays.equals(((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res.payment_hash(), ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash());
881892
SignedRawInvoice signed_raw = ((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res.into_signed_raw();
882893
RawInvoice raw_invoice = signed_raw.raw_invoice();
@@ -893,30 +904,32 @@ TestState do_test_message_handler() throws InterruptedException {
893904
InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features();
894905
RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints();
895906

896-
PaymentParameters payee = PaymentParameters.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none(), 6*24*14, (byte)1, (byte)2, new long[0], 42);
907+
PaymentParameters payee = PaymentParameters.of(peer2.node_id, invoice_features, Hints.clear(route_hints), Option_u64Z.none(), 6*24*14, (byte)1, (byte)2, new long[0], 42);
897908
RouteParameters route_params = RouteParameters.of(payee, 10000000);
898909
Result_RouteLightningErrorZ route_res = UtilMethods.find_route(
899910
peer1.chan_manager.get_our_node_id(), route_params, peer1.net_graph,
900911
peer1_chans, peer1.logger, ProbabilisticScorer.of(ProbabilisticScoringParameters.with_default(), peer1.net_graph, peer1.logger).as_Score(), new byte[32]);
901912
assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK;
902913
Route route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res;
903914
assert route.get_paths().length == 1;
904-
assert route.get_paths()[0].length == 1;
905-
assert route.get_paths()[0][0].get_fee_msat() == 10000000;
915+
assert route.get_paths()[0].get_hops().length == 1;
916+
assert route.get_paths()[0].final_value_msat() == 10000000;
906917

907918
byte[] payment_id = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
908-
Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret, payment_id);
919+
Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment_with_route(route, payment_hash, RecipientOnionFields.secret_only(payment_secret), payment_id);
909920
assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK;
910921

911-
RouteHop[][] hops = new RouteHop[1][1];
922+
RouteHop[] hops = new RouteHop[1];
912923
byte[] hop_pubkey = new byte[33];
913924
hop_pubkey[0] = 3;
914925
hop_pubkey[1] = 42;
915926
NodeFeatures node_features = NodeFeatures.empty();
916927
ChannelFeatures channel_features = ChannelFeatures.empty();
917-
hops[0][0] = RouteHop.of(hop_pubkey, node_features, 42, channel_features, 100, 0);
918-
Route r2 = Route.of(hops, payee);
919-
payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret, payment_id);
928+
hops[0] = RouteHop.of(hop_pubkey, node_features, 42, channel_features, 100, 0);
929+
Path[] paths = new Path[1];
930+
paths[0] = Path.of(hops, null);
931+
Route r2 = Route.of(paths, payee);
932+
payment_res = peer1.chan_manager.send_payment_with_route(r2, payment_hash, RecipientOnionFields.secret_only(payment_secret), payment_id);
920933
assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err;
921934
} else {
922935
Result_PaymentIdPaymentErrorZ send_res = UtilMethods.pay_invoice(((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res, Retry.attempts(0), peer1.chan_manager);
@@ -1050,7 +1063,7 @@ void do_test_message_handler_b(TestState state) throws Exception {
10501063
}
10511064

10521065
if (!nice_close) {
1053-
NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
1066+
BitcoinNetworkParams bitcoinj_net = BitcoinNetworkParams.of(BitcoinNetwork.MAINNET);
10541067
Transaction tx = new Transaction(bitcoinj_net, state.peer1.broadcast_set.getFirst());
10551068
Block b = new Block(bitcoinj_net, 2, state.best_blockhash, Sha256Hash.ZERO_HASH, 42, 0, 0,
10561069
Arrays.asList(new Transaction[]{tx}));

0 commit comments

Comments
 (0)