]> git.bitcoin.ninja Git - ldk-java/blob - src/test/java/org/ldk/ManualMsgHandlingPeerTest.java
Merge pull request #91 from TheBlueMatt/main
[ldk-java] / src / test / java / org / ldk / ManualMsgHandlingPeerTest.java
1 package org.ldk;
2
3 import org.junit.jupiter.api.Test;
4 import org.ldk.impl.bindings;
5 import org.ldk.enums.*;
6 import org.ldk.structs.Record;
7
8 public class ManualMsgHandlingPeerTest {
9     @Test
10     void test_message_handler() {
11         long logger = bindings.LDKLogger_new((long arg)->{
12             System.out.println(bindings.Record_get_args(arg));
13             bindings.Record_free(arg);
14         });
15         long chan_handler = bindings.LDKChannelMessageHandler_new(new bindings.LDKChannelMessageHandler() {
16             @Override
17             public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
18
19             }
20
21             @Override
22             public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
23
24             }
25
26             @Override
27             public void handle_funding_created(byte[] their_node_id, long msg) {
28
29             }
30
31             @Override
32             public void handle_funding_signed(byte[] their_node_id, long msg) {
33
34             }
35
36             @Override
37             public void handle_funding_locked(byte[] their_node_id, long msg) {
38
39             }
40
41             @Override
42             public void handle_shutdown(byte[] their_node_id, long their_features, long msg) {
43
44             }
45
46             @Override
47             public void handle_closing_signed(byte[] their_node_id, long msg) {
48
49             }
50
51             @Override
52             public void handle_update_add_htlc(byte[] their_node_id, long msg) {
53
54             }
55
56             @Override
57             public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
58
59             }
60
61             @Override
62             public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
63
64             }
65
66             @Override
67             public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
68
69             }
70
71             @Override
72             public void handle_commitment_signed(byte[] their_node_id, long msg) {
73
74             }
75
76             @Override
77             public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
78
79             }
80
81             @Override
82             public void handle_update_fee(byte[] their_node_id, long msg) {
83
84             }
85
86             @Override
87             public void handle_announcement_signatures(byte[] their_node_id, long msg) {
88
89             }
90
91             @Override
92             public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
93
94             }
95
96             @Override
97             public void peer_connected(byte[] their_node_id, long msg) {
98
99             }
100
101             @Override
102             public void handle_channel_reestablish(byte[] their_node_id, long msg) {
103
104             }
105
106             @Override
107             public void handle_channel_update(byte[] their_node_id, long msg) {
108
109             }
110
111             @Override
112             public void handle_error(byte[] their_node_id, long msg) {
113
114             }
115         }, () -> new long[0]);
116         long route_handler = bindings.LDKRoutingMessageHandler_new(new bindings.LDKRoutingMessageHandler() {
117             @Override public long handle_node_announcement(long msg) {
118                 return 0;
119             }
120             @Override public long handle_channel_announcement(long msg) {
121                 return 0;
122             }
123             @Override public long handle_channel_update(long msg) {
124                 return 0;
125             }
126             @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) {
127                 return new long[0];
128             }
129             @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
130                 return new long[0];
131             }
132
133             @Override
134             public void sync_routing_table(byte[] their_node_id, long init) {
135
136             }
137
138             @Override
139             public long handle_reply_channel_range(byte[] their_node_id, long msg) {
140                 return 0;
141             }
142
143             @Override
144             public long handle_reply_short_channel_ids_end(byte[] their_node_id, long msg) {
145                 return 0;
146             }
147
148             @Override
149             public long handle_query_channel_range(byte[] their_node_id, long msg) {
150                 return 0;
151             }
152
153             @Override
154             public long handle_query_short_channel_ids(byte[] their_node_id, long msg) {
155                 return 0;
156             }
157         }, () -> new long[0]);
158         long message_handler = bindings.MessageHandler_new(chan_handler, route_handler);
159         byte[] our_node_secret = new byte[32];
160         byte[] random_data = new byte[32];
161         for (byte i = 0; i < 32; i++) { random_data[i] = i; our_node_secret[i] = (byte) (i ^ 0xff); }
162
163         long ignoring_message_handler = bindings.IgnoringMessageHandler_new();
164         long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, random_data, logger,
165                 bindings.IgnoringMessageHandler_as_CustomMessageHandler(ignoring_message_handler));
166
167         // Test Level_max() since its the only place we create a java object from a Rust-returned enum.
168         assert bindings.Level_max() == Level.LDKLevel_Gossip;
169
170         // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
171         bindings.Logger_free(logger);
172         bindings.ChannelMessageHandler_free(chan_handler);
173         bindings.RoutingMessageHandler_free(route_handler);
174         //bindings.MessageHandler_free(message_handler);
175         bindings.PeerManager_free(peer_manager);
176     }
177 }