URI: 
       tCoinChooser: avoid NotEnoughFunds if zero buckets are sufficient - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 5549f3adbea06f2401a2281abaca58baa5f1f573
   DIR parent 5773097b085e5fa1993505aec63318138dc409bd
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Mon, 11 Nov 2019 15:15:04 +0100
       
       CoinChooser: avoid NotEnoughFunds if zero buckets are sufficient
       
       closes #5752
       
       Adapted from @JeremyRand's fix
       
       Diffstat:
         M electrum/coinchooser.py             |       5 ++++-
         A electrum/tests/test_coinchooser.py  |      20 ++++++++++++++++++++
       
       2 files changed, 24 insertions(+), 1 deletion(-)
       ---
   DIR diff --git a/electrum/coinchooser.py b/electrum/coinchooser.py
       t@@ -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()
        
   DIR diff --git a/electrum/tests/test_coinchooser.py b/electrum/tests/test_coinchooser.py
       t@@ -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)