@@ -30,8 +30,8 @@ fn channel_full_cycle() {
30
30
) ;
31
31
node_a. sync_wallets ( ) . unwrap ( ) ;
32
32
node_b. sync_wallets ( ) . unwrap ( ) ;
33
- assert_eq ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
34
- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
33
+ assert_eq ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
34
+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
35
35
36
36
println ! ( "\n A -- connect_open_channel -> B" ) ;
37
37
let funding_amount_sat = 80_000 ;
@@ -60,12 +60,12 @@ fn channel_full_cycle() {
60
60
node_b. sync_wallets ( ) . unwrap ( ) ;
61
61
62
62
let onchain_fee_buffer_sat = 1500 ;
63
- let node_a_balance = node_a. on_chain_balance ( ) . unwrap ( ) ;
63
+ let node_a_balance = node_a. onchain_balance ( ) . unwrap ( ) ;
64
64
let node_a_upper_bound_sat = premine_amount_sat - funding_amount_sat;
65
65
let node_a_lower_bound_sat = premine_amount_sat - funding_amount_sat - onchain_fee_buffer_sat;
66
66
assert ! ( node_a_balance. get_spendable( ) < node_a_upper_bound_sat) ;
67
67
assert ! ( node_a_balance. get_spendable( ) > node_a_lower_bound_sat) ;
68
- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
68
+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
69
69
70
70
expect_event ! ( node_a, ChannelReady ) ;
71
71
@@ -188,13 +188,10 @@ fn channel_full_cycle() {
188
188
let node_a_upper_bound_sat =
189
189
( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
190
190
let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
191
- assert ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) > node_a_lower_bound_sat) ;
192
- assert ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) < node_a_upper_bound_sat) ;
191
+ assert ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) > node_a_lower_bound_sat) ;
192
+ assert ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) < node_a_upper_bound_sat) ;
193
193
let expected_final_amount_node_b_sat = premine_amount_sat + sum_of_all_payments_sat;
194
- assert_eq ! (
195
- node_b. on_chain_balance( ) . unwrap( ) . get_spendable( ) ,
196
- expected_final_amount_node_b_sat
197
- ) ;
194
+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , expected_final_amount_node_b_sat) ;
198
195
199
196
node_a. stop ( ) . unwrap ( ) ;
200
197
println ! ( "\n A stopped" ) ;
@@ -228,8 +225,8 @@ fn channel_open_fails_when_funds_insufficient() {
228
225
) ;
229
226
node_a. sync_wallets ( ) . unwrap ( ) ;
230
227
node_b. sync_wallets ( ) . unwrap ( ) ;
231
- assert_eq ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
232
- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
228
+ assert_eq ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
229
+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
233
230
234
231
println ! ( "\n A -- connect_open_channel -> B" ) ;
235
232
let node_b_addr = format ! ( "{}@{}" , node_b. node_id( ) , node_b. listening_address( ) . unwrap( ) ) ;
@@ -264,13 +261,13 @@ fn start_stop_reinit() {
264
261
let expected_amount = Amount :: from_sat ( 100000 ) ;
265
262
266
263
premine_and_distribute_funds ( & bitcoind, & electrsd, vec ! [ funding_address] , expected_amount) ;
267
- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
264
+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
268
265
269
266
node. start ( ) . unwrap ( ) ;
270
267
assert_eq ! ( node. start( ) , Err ( Error :: AlreadyRunning ) ) ;
271
268
272
269
node. sync_wallets ( ) . unwrap ( ) ;
273
- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
270
+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
274
271
275
272
node. stop ( ) . unwrap ( ) ;
276
273
assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
@@ -288,15 +285,55 @@ fn start_stop_reinit() {
288
285
reinitialized_node. start ( ) . unwrap ( ) ;
289
286
290
287
assert_eq ! (
291
- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
288
+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
292
289
expected_amount. to_sat( )
293
290
) ;
294
291
295
292
reinitialized_node. sync_wallets ( ) . unwrap ( ) ;
296
293
assert_eq ! (
297
- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
294
+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
298
295
expected_amount. to_sat( )
299
296
) ;
300
297
301
298
reinitialized_node. stop ( ) . unwrap ( ) ;
302
299
}
300
+
301
+ #[ test]
302
+ fn onchain_spend_receive ( ) {
303
+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
304
+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
305
+
306
+ let config_a = random_config ( esplora_url) ;
307
+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
308
+ node_a. start ( ) . unwrap ( ) ;
309
+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
310
+
311
+ let config_b = random_config ( esplora_url) ;
312
+ let node_b = Builder :: from_config ( config_b) . build ( ) ;
313
+ node_b. start ( ) . unwrap ( ) ;
314
+ let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
315
+
316
+ premine_and_distribute_funds (
317
+ & bitcoind,
318
+ & electrsd,
319
+ vec ! [ addr_b. clone( ) ] ,
320
+ Amount :: from_sat ( 100000 ) ,
321
+ ) ;
322
+
323
+ node_a. sync_wallets ( ) . unwrap ( ) ;
324
+ node_b. sync_wallets ( ) . unwrap ( ) ;
325
+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
326
+
327
+ assert_eq ! ( Err ( Error :: InsufficientFunds ) , node_a. send_onchain_payment( & addr_b, 1000 ) ) ;
328
+
329
+ let txid = node_b. send_onchain_payment ( & addr_a, 1000 ) . unwrap ( ) ;
330
+ generate_blocks_and_wait ( & bitcoind, & electrsd, 6 ) ;
331
+ wait_for_tx ( & electrsd, txid) ;
332
+
333
+ node_a. sync_wallets ( ) . unwrap ( ) ;
334
+ node_b. sync_wallets ( ) . unwrap ( ) ;
335
+
336
+ assert_eq ! ( node_a. onchain_balance( ) . unwrap( ) . get_spendable( ) , 1000 ) ;
337
+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) > 98000 ) ;
338
+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
339
+ }
0 commit comments