1
1
use crate :: builder:: NodeBuilder ;
2
2
use crate :: io:: test_utils:: TestSyncStore ;
3
- use crate :: { Config , Node } ;
3
+ use crate :: { Config , Event , Node } ;
4
4
use lightning:: ln:: msgs:: SocketAddress ;
5
5
use lightning:: util:: logger:: { Level , Logger , Record } ;
6
+ use lightning:: util:: persist:: KVStore ;
6
7
7
8
use bitcoin:: { Address , Amount , Network , OutPoint , Txid } ;
8
9
@@ -26,7 +27,7 @@ macro_rules! expect_event {
26
27
( $node: expr, $event_type: ident) => { {
27
28
match $node. wait_next_event( ) {
28
29
ref e @ Event :: $event_type { .. } => {
29
- println!( "{} got event {:?}" , std :: stringify! ( $node) , e) ;
30
+ println!( "{} got event {:?}" , $node. node_id ( ) , e) ;
30
31
$node. event_handled( ) ;
31
32
}
32
33
ref e => {
@@ -38,6 +39,24 @@ macro_rules! expect_event {
38
39
39
40
pub ( crate ) use expect_event;
40
41
42
+ macro_rules! expect_channel_pending_event {
43
+ ( $node: expr, $counterparty_node_id: expr) => { {
44
+ match $node. wait_next_event( ) {
45
+ ref e @ Event :: ChannelPending { funding_txo, counterparty_node_id, .. } => {
46
+ println!( "{} got event {:?}" , $node. node_id( ) , e) ;
47
+ assert_eq!( counterparty_node_id, $counterparty_node_id) ;
48
+ $node. event_handled( ) ;
49
+ funding_txo
50
+ }
51
+ ref e => {
52
+ panic!( "{} got unexpected event!: {:?}" , std:: stringify!( $node) , e) ;
53
+ }
54
+ }
55
+ } } ;
56
+ }
57
+
58
+ pub ( crate ) use expect_channel_pending_event;
59
+
41
60
// Copied over from upstream LDK
42
61
#[ allow( dead_code) ]
43
62
pub struct TestLogger {
@@ -162,7 +181,7 @@ pub fn random_config() -> Config {
162
181
println ! ( "Setting random LDK listening addresses: {:?}" , rand_listening_addresses) ;
163
182
config. listening_addresses = Some ( rand_listening_addresses) ;
164
183
165
- config. log_level = Level :: Trace ;
184
+ config. log_level = Level :: Gossip ;
166
185
167
186
config
168
187
}
@@ -214,6 +233,7 @@ pub(crate) fn setup_node(electrsd: &ElectrsD, config: Config) -> Node<TestSyncSt
214
233
}
215
234
216
235
pub fn generate_blocks_and_wait ( bitcoind : & BitcoinD , electrsd : & ElectrsD , num : usize ) {
236
+ print ! ( "Generating {} blocks..." , num) ;
217
237
let cur_height = bitcoind. client . get_block_count ( ) . expect ( "failed to get current block height" ) ;
218
238
let address = bitcoind
219
239
. client
@@ -222,6 +242,8 @@ pub fn generate_blocks_and_wait(bitcoind: &BitcoinD, electrsd: &ElectrsD, num: u
222
242
// TODO: expect this Result once the WouldBlock issue is resolved upstream.
223
243
let _block_hashes_res = bitcoind. client . generate_to_address ( num as u64 , & address) ;
224
244
wait_for_block ( electrsd, cur_height as usize + num) ;
245
+ print ! ( " Done!" ) ;
246
+ println ! ( "\n " ) ;
225
247
}
226
248
227
249
pub fn wait_for_block ( electrsd : & ElectrsD , min_height : usize ) {
@@ -314,3 +336,25 @@ pub fn premine_and_distribute_funds(
314
336
315
337
generate_blocks_and_wait ( bitcoind, electrsd, 1 ) ;
316
338
}
339
+
340
+ pub fn open_channel < K : KVStore + Sync + Send > (
341
+ node_a : & Node < K > , node_b : & Node < K > , funding_amount_sat : u64 , announce : bool ,
342
+ electrsd : & ElectrsD ,
343
+ ) {
344
+ node_a
345
+ . connect_open_channel (
346
+ node_b. node_id ( ) ,
347
+ node_b. listening_address ( ) . unwrap ( ) . into ( ) ,
348
+ funding_amount_sat,
349
+ None ,
350
+ None ,
351
+ announce,
352
+ )
353
+ . unwrap ( ) ;
354
+ assert ! ( node_a. list_peers( ) . iter( ) . find( |c| { c. node_id == node_b. node_id( ) } ) . is_some( ) ) ;
355
+
356
+ let funding_txo_a = expect_channel_pending_event ! ( node_a, node_b. node_id( ) ) ;
357
+ let funding_txo_b = expect_channel_pending_event ! ( node_b, node_a. node_id( ) ) ;
358
+ assert_eq ! ( funding_txo_a, funding_txo_b) ;
359
+ wait_for_tx ( & electrsd, funding_txo_a. txid ) ;
360
+ }
0 commit comments