1+ use crate :: io:: KVStore ;
12use crate :: test:: utils:: * ;
23use crate :: test:: utils:: { expect_event, random_config} ;
3- use crate :: { Builder , Error , Event , PaymentDirection , PaymentStatus } ;
4+ use crate :: { Builder , Error , Event , Node , PaymentDirection , PaymentStatus } ;
45
56use bitcoin:: Amount ;
7+ use electrsd:: bitcoind:: BitcoinD ;
8+ use electrsd:: ElectrsD ;
9+
10+ use std:: sync:: Arc ;
611
712#[ test]
813fn channel_full_cycle ( ) {
@@ -12,12 +17,39 @@ fn channel_full_cycle() {
1217 let config_a = random_config ( esplora_url) ;
1318 let node_a = Builder :: from_config ( config_a) . build ( ) ;
1419 node_a. start ( ) . unwrap ( ) ;
15- let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
1620
1721 println ! ( "\n == Node B ==" ) ;
1822 let config_b = random_config ( esplora_url) ;
1923 let node_b = Builder :: from_config ( config_b) . build ( ) ;
2024 node_b. start ( ) . unwrap ( ) ;
25+
26+ do_channel_full_cycle ( node_a, node_b, & bitcoind, & electrsd, false ) ;
27+ }
28+
29+ #[ test]
30+ fn channel_full_cycle_0conf ( ) {
31+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
32+ println ! ( "== Node A ==" ) ;
33+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
34+ let config_a = random_config ( esplora_url) ;
35+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
36+ node_a. start ( ) . unwrap ( ) ;
37+
38+ println ! ( "\n == Node B ==" ) ;
39+ let mut config_b = random_config ( esplora_url) ;
40+ config_b. peers_trusted_0conf . push ( node_a. node_id ( ) ) ;
41+
42+ let node_b = Builder :: from_config ( config_b) . build ( ) ;
43+ node_b. start ( ) . unwrap ( ) ;
44+
45+ do_channel_full_cycle ( node_a, node_b, & bitcoind, & electrsd, true )
46+ }
47+
48+ fn do_channel_full_cycle < K : KVStore + Sync + Send > (
49+ node_a : Arc < Node < K > > , node_b : Arc < Node < K > > , bitcoind : & BitcoinD , electrsd : & ElectrsD ,
50+ allow_0conf : bool ,
51+ ) {
52+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
2153 let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
2254
2355 let premine_amount_sat = 100_000 ;
@@ -67,8 +99,11 @@ fn channel_full_cycle() {
6799
68100 wait_for_tx ( & electrsd, funding_txo. txid ) ;
69101
70- println ! ( "\n .. generating blocks, syncing wallets .. " ) ;
71- generate_blocks_and_wait ( & bitcoind, & electrsd, 6 ) ;
102+ if !allow_0conf {
103+ println ! ( "\n .. generating blocks .." ) ;
104+ generate_blocks_and_wait ( & bitcoind, & electrsd, 6 ) ;
105+ }
106+
72107 node_a. sync_wallets ( ) . unwrap ( ) ;
73108 node_b. sync_wallets ( ) . unwrap ( ) ;
74109
@@ -254,7 +289,7 @@ fn channel_open_fails_when_funds_insufficient() {
254289 node_b. listening_address( ) . unwrap( ) . into( ) ,
255290 120000 ,
256291 None ,
257- true
292+ true ,
258293 )
259294 ) ;
260295}
0 commit comments