From a4e9f3100f1e7b16b92dffaa0b229995afa2e5d2 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 14 Jun 2018 01:32:11 -0400 Subject: [PATCH] updating wallet tests --- lbrynet/database/storage.py | 6 +-- .../integration/wallet/test_transactions.py | 51 ++++++------------- 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/lbrynet/database/storage.py b/lbrynet/database/storage.py index e46fa5926..b8e92251e 100644 --- a/lbrynet/database/storage.py +++ b/lbrynet/database/storage.py @@ -11,7 +11,7 @@ from lbryschema.decode import smart_decode from lbrynet import conf from lbrynet.cryptstream.CryptBlob import CryptBlobInfo from lbrynet.dht.constants import dataExpireTimeout -from lbrynet.wallet.database import SQLiteWalletStorage +from lbrynet.wallet.database import WalletDatabase from torba.constants import COIN log = logging.getLogger(__name__) @@ -95,7 +95,7 @@ class SqliteConnection(adbapi.ConnectionPool): cls.reactor = reactor -class SQLiteStorage(SQLiteWalletStorage): +class SQLiteStorage(WalletDatabase): CREATE_TABLES_QUERY = """ pragma foreign_keys=on; @@ -166,7 +166,7 @@ class SQLiteStorage(SQLiteWalletStorage): timestamp integer, primary key (sd_hash, reflector_address) ); - """ + SQLiteWalletStorage.CREATE_TABLES_QUERY + """ + WalletDatabase.CREATE_TABLES_QUERY def __init__(self, db_dir, reactor=None): if not reactor: diff --git a/lbrynet/tests/integration/wallet/test_transactions.py b/lbrynet/tests/integration/wallet/test_transactions.py index b7b72aa34..8fee5d01b 100644 --- a/lbrynet/tests/integration/wallet/test_transactions.py +++ b/lbrynet/tests/integration/wallet/test_transactions.py @@ -2,30 +2,8 @@ import asyncio from binascii import hexlify, unhexlify from orchstr8.testcase import IntegrationTestCase from lbryschema.claim import ClaimDict - - -class BasicTransactionTests(IntegrationTestCase): - - VERBOSE = True - - async def test_sending_and_recieving(self): - - self.assertEqual(await self.get_balance(), 0.0) - - address = self.account.get_least_used_receiving_address() - sendtxid = await self.blockchain.send_to_address(address.decode(), 5.5) - await self.blockchain.generate(1) - await self.on_transaction(sendtxid) - - self.assertAlmostEqual(await self.get_balance(), 5.5, places=2) - - lbrycrd_address = await self.blockchain.get_raw_change_address() - tx = self.manager.send_amount_to_address(5, lbrycrd_address) - await self.broadcast(tx) - await self.on_transaction(tx.id.decode()) - await self.blockchain.generate(1) - - self.assertAlmostEqual(await self.get_balance(), 0.5, places=2) +from torba.constants import COIN +from lbrynet.wallet.manager import LbryWalletManager example_claim_dict = { @@ -58,28 +36,29 @@ example_claim_dict = { class ClaimTransactionTests(IntegrationTestCase): VERBOSE = True + WALLET_MANAGER = LbryWalletManager async def test_creating_updating_and_abandoning_claim(self): - address = self.account.get_least_used_receiving_address() - sendtxid = await self.lbrycrd.send_to_address(address.decode(), 9.0) - await self.lbrycrd.generate(1) - await self.on_transaction(sendtxid) + await self.account.ensure_address_gap().asFuture(asyncio.get_event_loop()) - self.assertAlmostEqual(self.manager.get_balance(), 9, places=2) + address = await self.account.receiving.get_or_create_usable_address().asFuture(asyncio.get_event_loop()) + sendtxid = await self.blockchain.send_to_address(address.decode(), 10) + await self.on_transaction(sendtxid) #mempool + await self.blockchain.generate(1) + await self.on_transaction(sendtxid) #confirmed + + self.assertEqual(round(await self.get_balance(self.account)/COIN, 1), 10.0) claim = ClaimDict.load_dict(example_claim_dict) - tx = self.manager.claim_name(b'foo', 5, hexlify(claim.serialized)) + tx = self.manager.claim_name(b'foo', 1*COIN, hexlify(claim.serialized)) await self.broadcast(tx) - await self.on_transaction(tx.id.decode()) - await self.lbrycrd.generate(1) - - await asyncio.sleep(2) + await self.on_transaction(tx.hex_id.decode()) #mempool + await self.blockchain.generate(1) + await self.on_transaction(tx.hex_id.decode()) #confirmed self.assertAlmostEqual(self.manager.get_balance(), 9, places=2) - await asyncio.sleep(2) - response = await self.resolve('lbry://foo') print(response)