@@ -29,8 +29,8 @@ fn channel_full_cycle() {
29
29
) ;
30
30
node_a. sync_wallets ( ) . unwrap ( ) ;
31
31
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 ) ;
34
34
35
35
println ! ( "\n A -- connect_open_channel -> B" ) ;
36
36
let node_b_addr = format ! ( "{}@{}" , node_b. node_id( ) , node_b. listening_address( ) . unwrap( ) ) ;
@@ -53,10 +53,10 @@ fn channel_full_cycle() {
53
53
node_a. sync_wallets ( ) . unwrap ( ) ;
54
54
node_b. sync_wallets ( ) . unwrap ( ) ;
55
55
56
- let node_a_balance = node_a. on_chain_balance ( ) . unwrap ( ) ;
56
+ let node_a_balance = node_a. onchain_balance ( ) . unwrap ( ) ;
57
57
assert ! ( node_a_balance. get_spendable( ) < 50000 ) ;
58
58
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 ) ;
60
60
61
61
expect_event ! ( node_a, ChannelReady ) ;
62
62
@@ -174,8 +174,8 @@ fn channel_full_cycle() {
174
174
node_a. sync_wallets ( ) . unwrap ( ) ;
175
175
node_b. sync_wallets ( ) . unwrap ( ) ;
176
176
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 ) ;
179
179
180
180
node_a. stop ( ) . unwrap ( ) ;
181
181
println ! ( "\n A stopped" ) ;
@@ -207,8 +207,8 @@ fn channel_open_fails_when_funds_insufficient() {
207
207
) ;
208
208
node_a. sync_wallets ( ) . unwrap ( ) ;
209
209
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 ) ;
212
212
213
213
println ! ( "\n A -- connect_open_channel -> B" ) ;
214
214
let node_b_addr = format ! ( "{}@{}" , node_b. node_id( ) , node_b. listening_address( ) . unwrap( ) ) ;
@@ -243,13 +243,13 @@ fn start_stop_reinit() {
243
243
let expected_amount = Amount :: from_sat ( 100000 ) ;
244
244
245
245
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 ) ;
247
247
248
248
node. start ( ) . unwrap ( ) ;
249
249
assert_eq ! ( node. start( ) , Err ( Error :: AlreadyRunning ) ) ;
250
250
251
251
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( ) ) ;
253
253
254
254
node. stop ( ) . unwrap ( ) ;
255
255
assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
@@ -267,15 +267,55 @@ fn start_stop_reinit() {
267
267
reinitialized_node. start ( ) . unwrap ( ) ;
268
268
269
269
assert_eq ! (
270
- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
270
+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
271
271
expected_amount. to_sat( )
272
272
) ;
273
273
274
274
reinitialized_node. sync_wallets ( ) . unwrap ( ) ;
275
275
assert_eq ! (
276
- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
276
+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
277
277
expected_amount. to_sat( )
278
278
) ;
279
279
280
280
reinitialized_node. stop ( ) . unwrap ( ) ;
281
281
}
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