@@ -110,14 +110,105 @@ fn channel_open_fails_when_funds_insufficient() {
110110 Err ( NodeError :: InsufficientFunds ) ,
111111 node_a. open_channel(
112112 node_b. node_id( ) ,
113- node_b. listening_addresses( ) . unwrap( ) . first( ) . unwrap( ) . clone( ) ,
113+ Some ( node_b. listening_addresses( ) . unwrap( ) . first( ) . unwrap( ) . clone( ) ) ,
114114 120000 ,
115115 None ,
116116 None ,
117117 )
118118 ) ;
119119}
120120
121+ #[ test]
122+ fn channel_open_with_no_address ( ) {
123+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
124+ let chain_source = TestChainSource :: Esplora ( & electrsd) ;
125+ let ( node_a, node_b) = setup_two_nodes ( & chain_source, false , true , false ) ;
126+
127+ let addr_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
128+ let addr_b = node_b. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
129+
130+ let premine_amount_sat = 1_100_000 ;
131+ premine_and_distribute_funds (
132+ & bitcoind. client ,
133+ & electrsd. client ,
134+ vec ! [ addr_a, addr_b] ,
135+ Amount :: from_sat ( premine_amount_sat) ,
136+ ) ;
137+
138+ node_a. sync_wallets ( ) . unwrap ( ) ;
139+ node_b. sync_wallets ( ) . unwrap ( ) ;
140+
141+ // Test 1: Opening channel without address and no existing connection should fail
142+ assert_eq ! (
143+ Err ( NodeError :: ConnectionFailed ) ,
144+ node_a. open_channel(
145+ node_b. node_id( ) ,
146+ None ,
147+ 100_000 ,
148+ None ,
149+ None ,
150+ )
151+ ) ;
152+
153+ // Test 2: Connect first, then open channel without address should succeed
154+ node_a. connect (
155+ node_b. node_id ( ) ,
156+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
157+ true ,
158+ ) . unwrap ( ) ;
159+
160+ // Now opening without address should work since we're connected
161+ node_a. open_channel (
162+ node_b. node_id ( ) ,
163+ None ,
164+ 100_000 ,
165+ None ,
166+ None ,
167+ ) . unwrap ( ) ;
168+
169+ // Verify channel was created successfully
170+ let funding_txo = expect_channel_pending_event ! ( node_a, node_b. node_id( ) ) ;
171+ wait_for_tx ( & electrsd. client , funding_txo. txid ) ;
172+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) ;
173+
174+ // Test 3: Opening announced channel without address and no connection should fail
175+ node_a. disconnect ( node_b. node_id ( ) ) . unwrap ( ) ;
176+ assert_eq ! (
177+ Err ( NodeError :: ConnectionFailed ) ,
178+ node_a. open_announced_channel(
179+ node_b. node_id( ) ,
180+ None ,
181+ 100_000 ,
182+ None ,
183+ None ,
184+ )
185+ ) ;
186+
187+ // Test 4: Connect first, then open announced channel without address should succeed
188+ node_a. connect (
189+ node_b. node_id ( ) ,
190+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
191+ true ,
192+ ) . unwrap ( ) ;
193+
194+ // Now opening announced channel without address should work
195+ node_a. open_announced_channel (
196+ node_b. node_id ( ) ,
197+ None ,
198+ 100_000 ,
199+ None ,
200+ None ,
201+ ) . unwrap ( ) ;
202+
203+ // Verify announced channel was created successfully
204+ let funding_txo = expect_channel_pending_event ! ( node_a, node_b. node_id( ) ) ;
205+ wait_for_tx ( & electrsd. client , funding_txo. txid ) ;
206+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) ;
207+
208+ node_a. stop ( ) . unwrap ( ) ;
209+ node_b. stop ( ) . unwrap ( ) ;
210+ }
211+
121212#[ test]
122213fn multi_hop_sending ( ) {
123214 let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
0 commit comments