@@ -138,6 +138,92 @@ fn channel_open_fails_when_funds_insufficient() {
138138 ) ;
139139}
140140
141+ #[ test]
142+ fn channel_open_fails_when_inbound_channels_config_rejects_announced_channels ( ) {
143+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
144+ let chain_source = TestChainSource :: Esplora ( & electrsd) ;
145+ let config_a = random_config ( true ) ;
146+ let node_a = setup_node ( & chain_source, config_a, None ) ;
147+ let mut config_b = random_config ( true ) ;
148+ config_b. node_config . inbound_channels_config . reject_announced_channel_requests = true ;
149+
150+ let node_b = setup_node ( & chain_source, config_b, None ) ;
151+
152+ let addr_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
153+ let addr_b = node_b. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
154+
155+ let premine_amount_sat = 100_000 ;
156+
157+ premine_and_distribute_funds (
158+ & bitcoind. client ,
159+ & electrsd. client ,
160+ vec ! [ addr_a, addr_b] ,
161+ Amount :: from_sat ( premine_amount_sat) ,
162+ ) ;
163+ node_a. sync_wallets ( ) . unwrap ( ) ;
164+ node_b. sync_wallets ( ) . unwrap ( ) ;
165+ assert_eq ! ( node_a. list_balances( ) . spendable_onchain_balance_sats, premine_amount_sat) ;
166+ assert_eq ! ( node_b. list_balances( ) . spendable_onchain_balance_sats, premine_amount_sat) ;
167+
168+ println ! ( "\n A -- open_channel -> B" ) ;
169+ node_a
170+ . open_announced_channel (
171+ node_b. node_id ( ) ,
172+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
173+ 20_000 ,
174+ None ,
175+ None ,
176+ )
177+ . unwrap ( ) ;
178+
179+ assert_eq ! ( node_a. list_peers( ) . first( ) . unwrap( ) . node_id, node_b. node_id( ) ) ;
180+ assert ! ( node_a. list_peers( ) . first( ) . unwrap( ) . is_persisted) ;
181+ expect_event ! ( node_a, ChannelClosed ) ;
182+ }
183+
184+ #[ test]
185+ fn channel_open_fails_when_inbound_channels_config_has_min_channel_size ( ) {
186+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
187+ let chain_source = TestChainSource :: Esplora ( & electrsd) ;
188+ let config_a = random_config ( true ) ;
189+ let node_a = setup_node ( & chain_source, config_a, None ) ;
190+ let mut config_b = random_config ( true ) ;
191+ config_b. node_config . inbound_channels_config . minimum_channel_size = Some ( 100_000 ) ;
192+
193+ let node_b = setup_node ( & chain_source, config_b, None ) ;
194+
195+ let addr_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
196+ let addr_b = node_b. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
197+
198+ let premine_amount_sat = 100_000 ;
199+
200+ premine_and_distribute_funds (
201+ & bitcoind. client ,
202+ & electrsd. client ,
203+ vec ! [ addr_a, addr_b] ,
204+ Amount :: from_sat ( premine_amount_sat) ,
205+ ) ;
206+ node_a. sync_wallets ( ) . unwrap ( ) ;
207+ node_b. sync_wallets ( ) . unwrap ( ) ;
208+ assert_eq ! ( node_a. list_balances( ) . spendable_onchain_balance_sats, premine_amount_sat) ;
209+ assert_eq ! ( node_b. list_balances( ) . spendable_onchain_balance_sats, premine_amount_sat) ;
210+
211+ println ! ( "\n A -- open_channel -> B" ) ;
212+ node_a
213+ . open_announced_channel (
214+ node_b. node_id ( ) ,
215+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
216+ 20_000 ,
217+ None ,
218+ None ,
219+ )
220+ . unwrap ( ) ;
221+
222+ assert_eq ! ( node_a. list_peers( ) . first( ) . unwrap( ) . node_id, node_b. node_id( ) ) ;
223+ assert ! ( node_a. list_peers( ) . first( ) . unwrap( ) . is_persisted) ;
224+ expect_event ! ( node_a, ChannelClosed ) ;
225+ }
226+
141227#[ test]
142228fn multi_hop_sending ( ) {
143229 let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
0 commit comments