Skip to content

Commit

Permalink
CoinChooser: avoid NotEnoughFunds if zero buckets are sufficient
Browse files Browse the repository at this point in the history
closes #5752

Adapted from @JeremyRand's fix
  • Loading branch information
SomberNight committed Nov 11, 2019
1 parent 5773097 commit 5549f3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion electrum/coinchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ class CoinChooserRandom(CoinChooserBase):
def bucket_candidates_any(self, buckets: List[Bucket], sufficient_funds) -> List[List[Bucket]]:
'''Returns a list of bucket sets.'''
if not buckets:
raise NotEnoughFunds()
if sufficient_funds([], bucket_value_sum=0):
return [[]]
else:
raise NotEnoughFunds()

candidates = set()

Expand Down
20 changes: 20 additions & 0 deletions electrum/tests/test_coinchooser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from electrum.coinchooser import CoinChooserPrivacy
from electrum.util import NotEnoughFunds

from . import ElectrumTestCase


class TestCoinChooser(ElectrumTestCase):

def test_bucket_candidates_with_empty_buckets(self):
def sufficient_funds(buckets, *, bucket_value_sum):
return True
coin_chooser = CoinChooserPrivacy()
self.assertEqual([[]], coin_chooser.bucket_candidates_any([], sufficient_funds))
self.assertEqual([[]], coin_chooser.bucket_candidates_prefer_confirmed([], sufficient_funds))
def sufficient_funds(buckets, *, bucket_value_sum):
return False
with self.assertRaises(NotEnoughFunds):
coin_chooser.bucket_candidates_any([], sufficient_funds)
with self.assertRaises(NotEnoughFunds):
coin_chooser.bucket_candidates_prefer_confirmed([], sufficient_funds)

0 comments on commit 5549f3a

Please sign in to comment.