From 97532fb30066fe23194ecce9fd396ea694702f73 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sun, 15 Jul 2018 16:04:11 -0400 Subject: [PATCH] don't delete lock if it's not in locks dict and other fun things --- tests/unit/test_ledger.py | 8 +++++++- torba/baseaccount.py | 1 - torba/baseledger.py | 12 +++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/unit/test_ledger.py b/tests/unit/test_ledger.py index 708d2fc4d..afedf6042 100644 --- a/tests/unit/test_ledger.py +++ b/tests/unit/test_ledger.py @@ -55,12 +55,18 @@ class MainNetTestLedger(MainNetLedger): }) -class TestSynchronization(unittest.TestCase): +class LedgerTestCase(unittest.TestCase): def setUp(self): self.ledger = MainNetTestLedger() return self.ledger.db.start() + def tearDown(self): + return self.ledger.db.stop() + + +class TestSynchronization(LedgerTestCase): + @defer.inlineCallbacks def test_update_history(self): account = self.ledger.account_class.generate(self.ledger, u"torba") diff --git a/torba/baseaccount.py b/torba/baseaccount.py index c3ca0df37..a10ae7257 100644 --- a/torba/baseaccount.py +++ b/torba/baseaccount.py @@ -1,7 +1,6 @@ from typing import Dict from twisted.internet import defer -import torba.baseledger from torba.mnemonic import Mnemonic from torba.bip32 import PrivateKey, PubKey, from_extended_key_string from torba.hash import double_sha256, aes_encrypt, aes_decrypt diff --git a/torba/baseledger.py b/torba/baseledger.py index f07b5c3b6..e2b22d8aa 100644 --- a/torba/baseledger.py +++ b/torba/baseledger.py @@ -90,8 +90,9 @@ class BaseLedger(six.with_metaclass(LedgerRegistry)): def get_id(cls): return '{}_{}'.format(cls.symbol.lower(), cls.network_name.lower()) - def hash160_to_address(self, h160): - raw_address = self.pubkey_address_prefix + h160 + @classmethod + def hash160_to_address(cls, h160): + raw_address = cls.pubkey_address_prefix + h160 return Base58.encode(bytearray(raw_address + double_sha256(raw_address)[0:4])) @staticmethod @@ -100,8 +101,9 @@ class BaseLedger(six.with_metaclass(LedgerRegistry)): prefix, pubkey_bytes, addr_checksum = bytes[0], bytes[1:21], bytes[21:] return pubkey_bytes - def public_key_to_address(self, public_key): - return self.hash160_to_address(hash160(public_key)) + @classmethod + def public_key_to_address(cls, public_key): + return cls.hash160_to_address(hash160(public_key)) @staticmethod def private_key_to_wif(private_key): @@ -303,7 +305,7 @@ class BaseLedger(six.with_metaclass(LedgerRegistry)): finally: lock.release() - if not lock.locked: + if not lock.locked and hex_id in self._transaction_processing_locks: del self._transaction_processing_locks[hex_id] @defer.inlineCallbacks