Skip to content

Commit

Permalink
f Improve variable naming to clarify fee buffer etc
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Nov 11, 2024
1 parent f0ce6d9 commit 91207fb
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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]
Expand Down

0 comments on commit 91207fb

Please sign in to comment.