fixing wallet unit tests test_ledger.py and test_transactions.py

This commit is contained in:
Lex Berezhny 2018-08-16 12:40:54 -04:00 committed by Jack Robison
parent 2b5e3204c0
commit 5afd446bb3
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 28 additions and 34 deletions

View file

@ -1,45 +1,25 @@
from twisted.internet import defer
from twisted.trial import unittest
from lbrynet import conf
from lbrynet.wallet.account import Account
from lbrynet.wallet.database import WalletDatabase
from lbrynet.wallet.transaction import Transaction, Output, Input
from lbrynet.wallet.ledger import MainNetLedger
from torba.wallet import Wallet
class MockHeaders:
def __init__(self, ledger):
self.ledger = ledger
self.height = 1
def __len__(self):
return self.height
def __getitem__(self, height):
return {'merkle_root': 'abcd04'}
class MainNetTestLedger(MainNetLedger):
headers_class = MockHeaders
network_name = 'unittest'
def __init__(self):
super(MainNetLedger, self).__init__({
'db': WalletDatabase(':memory:')
})
class LedgerTestCase(unittest.TestCase):
def setUp(self):
conf.initialize_settings(False)
self.ledger = MainNetTestLedger()
super().setUp()
self.ledger = MainNetLedger({
'db': MainNetLedger.database_class(':memory:'),
'headers': MainNetLedger.headers_class(':memory:')
})
self.account = Account.generate(self.ledger, Wallet(), "lbryum")
return self.ledger.db.start()
return self.ledger.db.open()
def tearDown(self):
return self.ledger.db.stop()
super().tearDown()
return self.ledger.db.close()
class BasicAccountingTests(LedgerTestCase):

View file

@ -5,11 +5,8 @@ from twisted.internet import defer
from torba.constants import CENT, COIN, NULL_HASH32
from torba.wallet import Wallet
from lbrynet.wallet.account import Account
from lbrynet.wallet.ledger import MainNetLedger
from lbrynet.wallet.database import WalletDatabase
from lbrynet.wallet.transaction import Transaction, Output, Input
from lbrynet.wallet.manager import LbryWalletManager
FEE_PER_BYTE = 50
@ -41,7 +38,16 @@ def get_claim_transaction(claim_name, claim=b''):
class TestSizeAndFeeEstimation(unittest.TestCase):
def setUp(self):
self.ledger = MainNetLedger({'db': WalletDatabase(':memory:')})
super().setUp()
self.ledger = MainNetLedger({
'db': MainNetLedger.database_class(':memory:'),
'headers': MainNetLedger.headers_class(':memory:')
})
return self.ledger.db.open()
def tearDown(self):
super().tearDown()
return self.ledger.db.close()
def test_output_size_and_fee(self):
txo = get_output()
@ -216,8 +222,16 @@ class TestTransactionSerialization(unittest.TestCase):
class TestTransactionSigning(unittest.TestCase):
def setUp(self):
self.ledger = MainNetLedger({'db': WalletDatabase(':memory:')})
return self.ledger.db.start()
super().setUp()
self.ledger = MainNetLedger({
'db': MainNetLedger.database_class(':memory:'),
'headers': MainNetLedger.headers_class(':memory:')
})
return self.ledger.db.open()
def tearDown(self):
super().tearDown()
return self.ledger.db.close()
@defer.inlineCallbacks
def test_sign(self):