diff --git a/cashu/core/helpers.py b/cashu/core/helpers.py index 7c20faa..15b77cd 100644 --- a/cashu/core/helpers.py +++ b/cashu/core/helpers.py @@ -53,5 +53,5 @@ def calculate_number_of_blank_outputs(fee_reserve_sat: int): """ assert fee_reserve_sat >= 0, "Fee reserve can't be negative." if fee_reserve_sat == 0: - return 1 - return math.ceil(math.log2(fee_reserve_sat)) + return 0 + return max(math.ceil(math.log2(fee_reserve_sat)), 1) diff --git a/tests/test_core.py b/tests/test_core.py index 3782aa9..470b140 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -43,8 +43,15 @@ def test_calculate_number_of_blank_outputs_for_small_fee_reserve(): assert n_blank_outputs == expected_n_blank_outputs -def test_calculate_number_of_blank_outputs_fails_for_negative_fee_reserve(): +def test_calculate_number_of_blank_outputs_for_zero_fee_reserve(): # Negative fee reserve is not supported. fee_reserve_sat = 0 + n_blank_outputs = calculate_number_of_blank_outputs(fee_reserve_sat) + assert n_blank_outputs == 0 + + +def test_calculate_number_of_blank_outputs_fails_for_negative_fee_reserve(): + # Negative fee reserve is not supported. + fee_reserve_sat = -1 with pytest.raises(AssertionError): _ = calculate_number_of_blank_outputs(fee_reserve_sat)