Skip to content

Commit b3302d4

Browse files
committed
Update tests to new Tuple mapping API
1 parent f92e8f5 commit b3302d4

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ public MonitorEvent[] release_pending_monitor_events() {
185185
ChannelManagerConstructor constructor = null;
186186
GcCheck obj = new GcCheck();
187187

188-
private TwoTuple<OutPoint, byte[]> test_mon_roundtrip(ChannelMonitor mon) {
188+
private TwoTuple_OutPointScriptZ test_mon_roundtrip(ChannelMonitor mon) {
189189
// Because get_funding_txo() returns an OutPoint in a tuple that is a reference to an OutPoint inside the
190190
// ChannelMonitor, its a good test to ensure that the OutPoint isn't freed (or is cloned) before the
191191
// ChannelMonitor is. This used to be broken.
192-
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ roundtrip_monitor = UtilMethods.BlockHashChannelMonitorZ_read(mon.write(), keys_interface);
192+
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ roundtrip_monitor = UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(mon.write(), keys_interface);
193193
assert roundtrip_monitor instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
194-
TwoTuple<OutPoint, byte[]> funding_txo = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_monitor).res.b.get_funding_txo();
194+
TwoTuple_OutPointScriptZ funding_txo = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_monitor).res.get_b().get_funding_txo();
195195
System.gc(); System.runFinalization(); // Give the GC a chance to run.
196196
return funding_txo;
197197
}
@@ -213,9 +213,9 @@ public Result_NoneChannelMonitorUpdateErrZ persist_new_channel(OutPoint id, Chan
213213
synchronized (monitors) {
214214
String key = Arrays.toString(id.to_channel_id());
215215
assert monitors.put(key, data) == null;
216-
TwoTuple<OutPoint, byte[]> res = test_mon_roundtrip(data);
217-
assert Arrays.equals(res.a.get_txid(), id.get_txid());
218-
assert res.a.get_index() == id.get_index();
216+
TwoTuple_OutPointScriptZ res = test_mon_roundtrip(data);
217+
assert Arrays.equals(res.get_a().get_txid(), id.get_txid());
218+
assert res.get_a().get_index() == id.get_index();
219219
}
220220
return Result_NoneChannelMonitorUpdateErrZ.ok();
221221
}
@@ -225,9 +225,9 @@ public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id,
225225
synchronized (monitors) {
226226
String key = Arrays.toString(id.to_channel_id());
227227
assert monitors.put(key, data) != null;
228-
TwoTuple<OutPoint, byte[]> res = test_mon_roundtrip(data);
229-
assert Arrays.equals(res.a.get_txid(), id.get_txid());
230-
assert res.a.get_index() == id.get_index();
228+
TwoTuple_OutPointScriptZ res = test_mon_roundtrip(data);
229+
assert Arrays.equals(res.get_a().get_txid(), id.get_txid());
230+
assert res.get_a().get_index() == id.get_index();
231231
}
232232
return Result_NoneChannelMonitorUpdateErrZ.ok();
233233
}
@@ -268,7 +268,7 @@ public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id,
268268
this.keys_interface = keys.as_KeysInterface();
269269
this.explicit_keys_manager = keys;
270270
}
271-
this.router = NetGraphMsgHandler.of(new byte[32], Option_AccessZ.some(Access.new_impl(new Access.AccessInterface() {
271+
this.router = NetGraphMsgHandler.of(NetworkGraph.of(new byte[32]), Option_AccessZ.some(Access.new_impl(new Access.AccessInterface() {
272272
@Override
273273
public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) {
274274
// We don't exchange any gossip, so should never actually get called, but providing a Some(Access)
@@ -289,16 +289,16 @@ public Result_NoneLightningErrorZ handle_custom_message(Type msg, byte[] sender_
289289
}
290290

291291
@Override
292-
public TwoTuple<byte[], Type>[] get_and_clear_pending_msg() {
292+
public TwoTuple_PublicKeyTypeZ[] get_and_clear_pending_msg() {
293293
byte[][] bytes;
294294
synchronized (custom_messages_to_send) {
295295
bytes = custom_messages_to_send.toArray(new byte[0][0]);
296296
custom_messages_to_send.clear();
297297
}
298-
TwoTuple[] ret = new TwoTuple[bytes.length];
298+
TwoTuple_PublicKeyTypeZ[] ret = new TwoTuple_PublicKeyTypeZ[bytes.length];
299299
for (int i = 0; i < bytes.length; i++) {
300300
final int msg_idx = i;
301-
ret[i] = new TwoTuple(connected_peer_node_id, Type.new_impl(new Type.TypeInterface() {
301+
ret[i] = TwoTuple_PublicKeyTypeZ.of(connected_peer_node_id, Type.new_impl(new Type.TypeInterface() {
302302
@Override public short type_id() { return 4096; }
303303
@Override public String debug_str() { return "Custom Java Message"; }
304304
@Override public byte[] write() { return bytes[msg_idx]; }
@@ -406,16 +406,16 @@ private void bind_nio() {
406406
} else {
407407
byte[] serialized = orig.monitors.values().stream().iterator().next().write();
408408
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res =
409-
UtilMethods.BlockHashChannelMonitorZ_read(serialized, this.keys_interface);
409+
UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(serialized, this.keys_interface);
410410
assert res instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
411-
monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.b;
411+
monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.get_b();
412412
}
413413
byte[] serialized = orig.chan_manager.write();
414414
Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res =
415-
UtilMethods.BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.with_default(), monitors);
415+
UtilMethods.C2Tuple_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.with_default(), monitors);
416416
assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK;
417-
this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b;
418-
this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]);
417+
this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.get_b();
418+
this.chain_watch.watch_channel(monitors[0].get_funding_txo().get_a(), monitors[0]);
419419
byte[] random_data = keys_interface.get_secure_random_bytes();
420420
this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler);
421421
if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) {
@@ -440,15 +440,15 @@ private void bind_nio() {
440440
}
441441
}
442442

443-
TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] connect_block(Block b, int height, long expected_monitor_update_len) {
443+
TwoTuple_TxidCVec_C2Tuple_u32TxOutZZZ[] connect_block(Block b, int height, long expected_monitor_update_len) {
444444
byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80);
445-
TwoTuple<Long, byte[]>[] txn;
445+
TwoTuple_usizeTransactionZ[] txn;
446446
if (b.hasTransactions()) {
447447
assert b.getTransactions().size() == 1;
448-
TwoTuple<Long, byte[]> txp = new TwoTuple<>((long) 0, b.getTransactions().get(0).bitcoinSerialize());
449-
txn = new TwoTuple[]{txp};
448+
TwoTuple_usizeTransactionZ txp = TwoTuple_usizeTransactionZ.of((long) 0, b.getTransactions().get(0).bitcoinSerialize());
449+
txn = new TwoTuple_usizeTransactionZ[]{txp};
450450
} else
451-
txn = new TwoTuple[0];
451+
txn = new TwoTuple_usizeTransactionZ[0];
452452
if (chain_monitor != null) {
453453
chan_manager.as_Listen().block_connected(b.bitcoinSerialize(), height);
454454
chain_monitor.as_Listen().block_connected(b.bitcoinSerialize(), height);
@@ -459,7 +459,7 @@ TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] connect_block(Block b, int height
459459
synchronized (monitors) {
460460
assert monitors.size() == 1;
461461
for (ChannelMonitor mon : monitors.values()) {
462-
TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
462+
TwoTuple_TxidCVec_C2Tuple_u32TxOutZZZ[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
463463
assert ret.length == expected_monitor_update_len;
464464
return ret;
465465
}
@@ -856,13 +856,13 @@ void do_test_message_handler_b(TestState state) throws InterruptedException {
856856
Transaction tx = new Transaction(bitcoinj_net, state.peer1.broadcast_set.getFirst());
857857
Block b = new Block(bitcoinj_net, 2, state.best_blockhash, Sha256Hash.ZERO_HASH, 42, 0, 0,
858858
Arrays.asList(new Transaction[]{tx}));
859-
TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] watch_outputs = state.peer2.connect_block(b, 10, 1);
859+
TwoTuple_TxidCVec_C2Tuple_u32TxOutZZZ[] watch_outputs = state.peer2.connect_block(b, 10, 1);
860860
if (watch_outputs != null) { // We only process watch_outputs manually when we use a manually-build Watch impl
861861
assert watch_outputs.length == 1;
862-
assert Arrays.equals(watch_outputs[0].a, tx.getTxId().getReversedBytes());
863-
assert watch_outputs[0].b.length == 2;
864-
assert watch_outputs[0].b[0].a == 0;
865-
assert watch_outputs[0].b[1].a == 1;
862+
assert Arrays.equals(watch_outputs[0].get_a(), tx.getTxId().getReversedBytes());
863+
assert watch_outputs[0].get_b().length == 2;
864+
assert watch_outputs[0].get_b()[0].get_a() == 0;
865+
assert watch_outputs[0].get_b()[1].get_a() == 1;
866866
}
867867

868868
for (int i = 11; i < 21; i++) {

src/test/java/org/ldk/PeerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public long send_data(byte[] data, boolean resume_read) {
286286
assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(route);
287287
bindings.NetworkGraph_free(netgraph);
288288
long payment_res = bindings.ChannelManager_send_payment(peer1.chan_manager, bindings.LDKCResult_RouteLightningErrorZ_get_ok(route),
289-
bindings.LDKC2Tuple_PaymentHashPaymentSecretZ_get_a(inbound_payment), bindings.LDKC2Tuple_PaymentHashPaymentSecretZ_get_b(inbound_payment));
289+
bindings.C2Tuple_PaymentHashPaymentSecretZ_get_a(inbound_payment), bindings.C2Tuple_PaymentHashPaymentSecretZ_get_b(inbound_payment));
290290
bindings.CResult_RouteLightningErrorZ_free(route);
291291
bindings.C2Tuple_PaymentHashPaymentSecretZ_free(inbound_payment);
292292
assert bindings.LDKCResult_NonePaymentSendFailureZ_result_ok(payment_res);

0 commit comments

Comments
 (0)