Merge pull request #749 from chrisglass/clean-tests-wallet
authorThomasV <thomasv1@gmx.de>
Thu, 10 Jul 2014 00:58:51 +0000 (02:58 +0200)
committerThomasV <thomasv1@gmx.de>
Thu, 10 Jul 2014 00:58:51 +0000 (02:58 +0200)
Add tests to the wallet.py module.

1  2 
lib/wallet.py

diff --combined lib/wallet.py
@@@ -43,11 -43,10 +43,10 @@@ DUST_THRESHOLD = 543
  IMPORTED_ACCOUNT = '/x'
  
  
- class WalletStorage:
+ class WalletStorage(object):
  
      def __init__(self, config):
-         self.lock = threading.Lock()
+         self.lock = threading.RLock()
          self.config = config
          self.data = {}
          self.file_exists = False
@@@ -56,7 -55,6 +55,6 @@@
          if self.path:
              self.read(self.path)
  
      def init_path(self, config):
          """Set the path of the wallet."""
  
@@@ -84,7 -82,6 +82,6 @@@
  
          return new_path
  
      def read(self, path):
          """Read the contents of the wallet file."""
          try:
          self.data = d
          self.file_exists = True
  
      def get(self, key, default=None):
-         v = self.data.get(key)
-         if v is None:
-             v = default
-         return v
+         with self.lock:
+             v = self.data.get(key)
+             if v is None:
+                 v = default
+             return v
  
      def put(self, key, value, save = True):
  
              os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE)
  
  
- class Abstract_Wallet:
+ class Abstract_Wallet(object):
      """
      Wallet classes are created to handle various address generation methods.
      Completion states (watching-only, single account, no seed, etc) are handled inside classes.
      """
      def __init__(self, storage):
          self.storage = storage
          self.electrum_version = ELECTRUM_VERSION
          self.history               = storage.get('addr_history',{})        # address -> list(txid, height)
  
          self.fee                   = int(storage.get('fee_per_kb', 10000))
          self.master_public_keys = storage.get('master_public_keys',{})
          self.master_private_keys = storage.get('master_private_keys', {})
  
          self.next_addresses = storage.get('next_addresses',{})
  
          # This attribute is set when wallet.start_threads is called.
          self.synchronizer = None
  
                  print_error("removing unreferenced tx", h)
                  self.transactions.pop(h)
  
          # not saved
          self.prevout_values = {}     # my own transaction outputs
          self.spent_outputs = []
          return s[0] == 1
  
      def get_address_index(self, address):
          for account in self.accounts.keys():
              for for_change in [0,1]:
                  addresses = self.accounts[account].get_addresses(for_change)
@@@ -1059,6 -1051,7 +1051,7 @@@ class Imported_Wallet(Abstract_Wallet)
      def is_beyond_limit(self, address, account, is_change):
          return False
  
  class Deterministic_Wallet(Abstract_Wallet):
  
      def __init__(self, storage):
              return False
          prev_addresses = prev_addresses[max(0, i - limit):]
          for addr in prev_addresses:
 -            if self.address_is_old(addr):
 +            if self.history.get(addr):
                  return False
          return True