From 91207fb3f6796a007335ed5df4e3e96e1c542c41 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 11 Nov 2024 10:37:07 +0100 Subject: [PATCH] f Improve variable naming to clarify fee buffer etc --- tests/integration_tests_rust.rs | 58 ++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index e5ed82abd..7ba0edf30 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -300,31 +300,35 @@ fn onchain_spend_receive() { expect_channel_ready_event!(node_a, node_b.node_id()); expect_channel_ready_event!(node_b, node_a.node_id()); - let node_a_balance = premine_amount_sat - reserve_amount_sat; - let node_b_balance_lower = premine_amount_sat - channel_amount_sat - reserve_amount_sat - 1000; - let node_b_balance_upper = premine_amount_sat - channel_amount_sat - reserve_amount_sat; - assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, node_a_balance); - assert!(node_b.list_balances().spendable_onchain_balance_sats > node_b_balance_lower); - assert!(node_b.list_balances().spendable_onchain_balance_sats < node_b_balance_upper); + let onchain_fee_buffer_sat = 1000; + let expected_node_a_balance = premine_amount_sat - reserve_amount_sat; + let expected_node_b_balance_lower = + premine_amount_sat - channel_amount_sat - reserve_amount_sat - onchain_fee_buffer_sat; + let expected_node_b_balance_upper = + premine_amount_sat - channel_amount_sat - reserve_amount_sat; + assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, expected_node_a_balance); + assert!(node_b.list_balances().spendable_onchain_balance_sats > expected_node_b_balance_lower); + assert!(node_b.list_balances().spendable_onchain_balance_sats < expected_node_b_balance_upper); assert_eq!( Err(NodeError::InsufficientFunds), - node_a.onchain_payment().send_to_address(&addr_b, node_a_balance + 1) + node_a.onchain_payment().send_to_address(&addr_b, expected_node_a_balance + 1) ); - let txid = node_b.onchain_payment().send_to_address(&addr_a, 1000).unwrap(); + let amount_to_send_sats = 1000; + let txid = node_b.onchain_payment().send_to_address(&addr_a, amount_to_send_sats).unwrap(); generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6); wait_for_tx(&electrsd.client, txid); node_a.sync_wallets().unwrap(); node_b.sync_wallets().unwrap(); - let node_a_balance = node_a_balance + 1000; - let node_b_balance_lower = node_b_balance_lower - 1000; - let node_b_balance_upper = node_b_balance_upper - 1000; - assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, node_a_balance); - assert!(node_b.list_balances().spendable_onchain_balance_sats > node_b_balance_lower); - assert!(node_b.list_balances().spendable_onchain_balance_sats < node_b_balance_upper); + let expected_node_a_balance = expected_node_a_balance + amount_to_send_sats; + let expected_node_b_balance_lower = expected_node_b_balance_lower - amount_to_send_sats; + let expected_node_b_balance_upper = expected_node_b_balance_upper - amount_to_send_sats; + assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, expected_node_a_balance); + assert!(node_b.list_balances().spendable_onchain_balance_sats > expected_node_b_balance_lower); + assert!(node_b.list_balances().spendable_onchain_balance_sats < expected_node_b_balance_upper); let addr_b = node_b.onchain_payment().new_address().unwrap(); let txid = node_a.onchain_payment().send_all_to_address(&addr_b, true).unwrap(); @@ -334,13 +338,13 @@ fn onchain_spend_receive() { node_a.sync_wallets().unwrap(); node_b.sync_wallets().unwrap(); - let node_b_balance_lower = node_b_balance_lower + node_a_balance; - let node_b_balance_upper = node_b_balance_upper + node_a_balance; - let node_a_balance = 0; - assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, node_a_balance); + let expected_node_b_balance_lower = expected_node_b_balance_lower + expected_node_a_balance; + let expected_node_b_balance_upper = expected_node_b_balance_upper + expected_node_a_balance; + let expected_node_a_balance = 0; + assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, expected_node_a_balance); assert_eq!(node_a.list_balances().total_onchain_balance_sats, reserve_amount_sat); - assert!(node_b.list_balances().spendable_onchain_balance_sats > node_b_balance_lower); - assert!(node_b.list_balances().spendable_onchain_balance_sats < node_b_balance_upper); + assert!(node_b.list_balances().spendable_onchain_balance_sats > expected_node_b_balance_lower); + assert!(node_b.list_balances().spendable_onchain_balance_sats < expected_node_b_balance_upper); let addr_b = node_b.onchain_payment().new_address().unwrap(); let txid = node_a.onchain_payment().send_all_to_address(&addr_b, false).unwrap(); @@ -350,14 +354,14 @@ fn onchain_spend_receive() { node_a.sync_wallets().unwrap(); node_b.sync_wallets().unwrap(); - let node_b_balance_lower = node_b_balance_lower + reserve_amount_sat; - let node_b_balance_upper = node_b_balance_upper + reserve_amount_sat; - let node_a_balance = 0; + let expected_node_b_balance_lower = expected_node_b_balance_lower + reserve_amount_sat; + let expected_node_b_balance_upper = expected_node_b_balance_upper + reserve_amount_sat; + let expected_node_a_balance = 0; - assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, node_a_balance); - assert_eq!(node_a.list_balances().total_onchain_balance_sats, node_a_balance); - assert!(node_b.list_balances().spendable_onchain_balance_sats > node_b_balance_lower); - assert!(node_b.list_balances().spendable_onchain_balance_sats < node_b_balance_upper); + assert_eq!(node_a.list_balances().spendable_onchain_balance_sats, expected_node_a_balance); + assert_eq!(node_a.list_balances().total_onchain_balance_sats, expected_node_a_balance); + assert!(node_b.list_balances().spendable_onchain_balance_sats > expected_node_b_balance_lower); + assert!(node_b.list_balances().spendable_onchain_balance_sats < expected_node_b_balance_upper); } #[test]