@@ -29,8 +29,8 @@ fn channel_full_cycle() {
2929 ) ;
3030 node_a. sync_wallets ( ) . unwrap ( ) ;
3131 node_b. sync_wallets ( ) . unwrap ( ) ;
32- assert_eq ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
33- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
32+ assert_eq ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
33+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
3434
3535 println ! ( "\n A -- connect_open_channel -> B" ) ;
3636 let node_b_addr = format ! ( "{}@{}" , node_b. node_id( ) , node_b. listening_address( ) . unwrap( ) ) ;
@@ -53,10 +53,10 @@ fn channel_full_cycle() {
5353 node_a. sync_wallets ( ) . unwrap ( ) ;
5454 node_b. sync_wallets ( ) . unwrap ( ) ;
5555
56- let node_a_balance = node_a. on_chain_balance ( ) . unwrap ( ) ;
56+ let node_a_balance = node_a. onchain_balance ( ) . unwrap ( ) ;
5757 assert ! ( node_a_balance. get_spendable( ) < 50000 ) ;
5858 assert ! ( node_a_balance. get_spendable( ) > 40000 ) ;
59- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
59+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
6060
6161 expect_event ! ( node_a, ChannelReady ) ;
6262
@@ -174,8 +174,8 @@ fn channel_full_cycle() {
174174 node_a. sync_wallets ( ) . unwrap ( ) ;
175175 node_b. sync_wallets ( ) . unwrap ( ) ;
176176
177- assert ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) > 90000 ) ;
178- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , 103234 ) ;
177+ assert ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) > 90000 ) ;
178+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , 103234 ) ;
179179
180180 node_a. stop ( ) . unwrap ( ) ;
181181 println ! ( "\n A stopped" ) ;
@@ -207,8 +207,8 @@ fn channel_open_fails_when_funds_insufficient() {
207207 ) ;
208208 node_a. sync_wallets ( ) . unwrap ( ) ;
209209 node_b. sync_wallets ( ) . unwrap ( ) ;
210- assert_eq ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
211- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
210+ assert_eq ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
211+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
212212
213213 println ! ( "\n A -- connect_open_channel -> B" ) ;
214214 let node_b_addr = format ! ( "{}@{}" , node_b. node_id( ) , node_b. listening_address( ) . unwrap( ) ) ;
@@ -243,13 +243,13 @@ fn start_stop_reinit() {
243243 let expected_amount = Amount :: from_sat ( 100000 ) ;
244244
245245 premine_and_distribute_funds ( & bitcoind, & electrsd, vec ! [ funding_address] , expected_amount) ;
246- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
246+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
247247
248248 node. start ( ) . unwrap ( ) ;
249249 assert_eq ! ( node. start( ) , Err ( Error :: AlreadyRunning ) ) ;
250250
251251 node. sync_wallets ( ) . unwrap ( ) ;
252- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
252+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
253253
254254 node. stop ( ) . unwrap ( ) ;
255255 assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
@@ -267,15 +267,55 @@ fn start_stop_reinit() {
267267 reinitialized_node. start ( ) . unwrap ( ) ;
268268
269269 assert_eq ! (
270- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
270+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
271271 expected_amount. to_sat( )
272272 ) ;
273273
274274 reinitialized_node. sync_wallets ( ) . unwrap ( ) ;
275275 assert_eq ! (
276- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
276+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
277277 expected_amount. to_sat( )
278278 ) ;
279279
280280 reinitialized_node. stop ( ) . unwrap ( ) ;
281281}
282+
283+ #[ test]
284+ fn onchain_spend_receive ( ) {
285+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
286+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
287+
288+ let config_a = random_config ( esplora_url) ;
289+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
290+ node_a. start ( ) . unwrap ( ) ;
291+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
292+
293+ let config_b = random_config ( esplora_url) ;
294+ let node_b = Builder :: from_config ( config_b) . build ( ) ;
295+ node_b. start ( ) . unwrap ( ) ;
296+ let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
297+
298+ premine_and_distribute_funds (
299+ & bitcoind,
300+ & electrsd,
301+ vec ! [ addr_b. clone( ) ] ,
302+ Amount :: from_sat ( 100000 ) ,
303+ ) ;
304+
305+ node_a. sync_wallets ( ) . unwrap ( ) ;
306+ node_b. sync_wallets ( ) . unwrap ( ) ;
307+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
308+
309+ assert_eq ! ( Err ( Error :: InsufficientFunds ) , node_a. send_onchain_payment( & addr_b, 1000 ) ) ;
310+
311+ let txid = node_b. send_onchain_payment ( & addr_a, 1000 ) . unwrap ( ) ;
312+ generate_blocks_and_wait ( & bitcoind, & electrsd, 6 ) ;
313+ wait_for_tx ( & electrsd, txid) ;
314+
315+ node_a. sync_wallets ( ) . unwrap ( ) ;
316+ node_b. sync_wallets ( ) . unwrap ( ) ;
317+
318+ assert_eq ! ( node_a. onchain_balance( ) . unwrap( ) . get_spendable( ) , 1000 ) ;
319+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) > 98000 ) ;
320+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
321+ }
0 commit comments