forked from LBRYCommunity/lbry-sdk
fixing tests
This commit is contained in:
parent
e10f1df321
commit
2cd1947ef5
7 changed files with 29 additions and 23 deletions
|
@ -1,5 +1,4 @@
|
|||
import asyncio
|
||||
from orchstr8.testcase import IntegrationTestCase, d2f
|
||||
from orchstr8.testcase import IntegrationTestCase
|
||||
from torba.constants import COIN
|
||||
|
||||
|
||||
|
@ -8,7 +7,7 @@ class ReconnectTests(IntegrationTestCase):
|
|||
VERBOSE = False
|
||||
|
||||
async def test_connection_drop_still_receives_events_after_reconnected(self):
|
||||
address1 = await d2f(self.account.receiving.get_or_create_usable_address())
|
||||
address1 = await self.account.receiving.get_or_create_usable_address()
|
||||
self.ledger.network.client.connectionLost()
|
||||
sendtxid = await self.blockchain.send_to_address(address1, 1.1337)
|
||||
await self.on_transaction_id(sendtxid) # mempool
|
||||
|
@ -21,13 +20,13 @@ class ReconnectTests(IntegrationTestCase):
|
|||
# what's that smoke on my ethernet cable? oh no!
|
||||
self.ledger.network.client.connectionLost()
|
||||
with self.assertRaisesRegex(TimeoutError, 'Connection dropped'):
|
||||
await d2f(d)
|
||||
await d
|
||||
# rich but offline? no way, no water, let's retry
|
||||
with self.assertRaisesRegex(ConnectionError, 'connection is not available'):
|
||||
await d2f(self.ledger.network.get_transaction(sendtxid))
|
||||
await self.ledger.network.get_transaction(sendtxid)
|
||||
# * goes to pick some water outside... * time passes by and another donation comes in
|
||||
sendtxid = await self.blockchain.send_to_address(address1, 42)
|
||||
await self.blockchain.generate(1)
|
||||
# omg, the burned cable still works! torba is fire proof!
|
||||
await d2f(self.ledger.network.get_transaction(sendtxid))
|
||||
await self.ledger.network.get_transaction(sendtxid)
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import unittest
|
||||
from binascii import unhexlify, hexlify
|
||||
|
||||
from orchstr8.testcase import AsyncioTestCase
|
||||
|
||||
from .key_fixtures import expected_ids, expected_privkeys, expected_hardened_privkeys
|
||||
from torba.bip32 import PubKey, PrivateKey, from_extended_key_string
|
||||
from torba.coin.bitcoinsegwit import MainNetLedger as ledger_class
|
||||
|
||||
|
||||
class BIP32Tests(unittest.TestCase):
|
||||
class BIP32Tests(AsyncioTestCase):
|
||||
|
||||
def test_pubkey_validation(self):
|
||||
with self.assertRaisesRegex(TypeError, 'chain code must be raw bytes'):
|
||||
|
@ -39,7 +40,7 @@ class BIP32Tests(unittest.TestCase):
|
|||
self.assertIsInstance(new_key, PubKey)
|
||||
self.assertEqual(hexlify(new_key.identifier()), expected_ids[i])
|
||||
|
||||
def test_private_key_validation(self):
|
||||
async def test_private_key_validation(self):
|
||||
with self.assertRaisesRegex(TypeError, 'private key must be raw bytes'):
|
||||
PrivateKey(None, None, b'abcd'*8, 0, 255)
|
||||
with self.assertRaisesRegex(ValueError, 'private key must be 32 bytes'):
|
||||
|
@ -64,7 +65,7 @@ class BIP32Tests(unittest.TestCase):
|
|||
private_key.child(-1)
|
||||
self.assertIsInstance(private_key.child(PrivateKey.HARDENED), PrivateKey)
|
||||
|
||||
def test_private_key_derivation(self):
|
||||
async def test_private_key_derivation(self):
|
||||
private_key = PrivateKey(
|
||||
ledger_class({
|
||||
'db': ledger_class.database_class(':memory:'),
|
||||
|
@ -82,7 +83,7 @@ class BIP32Tests(unittest.TestCase):
|
|||
self.assertIsInstance(new_privkey, PrivateKey)
|
||||
self.assertEqual(hexlify(new_privkey.private_key_bytes), expected_hardened_privkeys[i - 1 - PrivateKey.HARDENED])
|
||||
|
||||
def test_from_extended_keys(self):
|
||||
async def test_from_extended_keys(self):
|
||||
ledger = ledger_class({
|
||||
'db': ledger_class.database_class(':memory:'),
|
||||
'headers': ledger_class.headers_class(':memory:'),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import unittest
|
||||
from types import GeneratorType
|
||||
|
||||
from orchstr8.testcase import AsyncioTestCase
|
||||
|
||||
from torba.coin.bitcoinsegwit import MainNetLedger as ledger_class
|
||||
from torba.coinselection import CoinSelector, MAXIMUM_TRIES
|
||||
from torba.constants import CENT
|
||||
|
@ -16,14 +17,17 @@ def search(*args, **kwargs):
|
|||
return [o.txo.amount for o in selection] if selection else selection
|
||||
|
||||
|
||||
class BaseSelectionTestCase(unittest.TestCase):
|
||||
class BaseSelectionTestCase(AsyncioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
async def asyncSetUp(self):
|
||||
self.ledger = ledger_class({
|
||||
'db': ledger_class.database_class(':memory:'),
|
||||
'headers': ledger_class.headers_class(':memory:'),
|
||||
})
|
||||
return self.ledger.db.open()
|
||||
await self.ledger.db.open()
|
||||
|
||||
async def asyncTearDown(self):
|
||||
await self.ledger.db.close()
|
||||
|
||||
def estimates(self, *args):
|
||||
txos = args[0] if isinstance(args[0], (GeneratorType, list)) else args
|
||||
|
|
|
@ -93,7 +93,7 @@ class TestScriptTemplates(unittest.TestCase):
|
|||
)
|
||||
|
||||
def test_push_data_many_not_separated(self):
|
||||
with self.assertRaisesRegexp(ParseError, 'consecutive PUSH_MANY'):
|
||||
with self.assertRaisesRegex(ParseError, 'consecutive PUSH_MANY'):
|
||||
parse((PUSH_MANY('Chiefs'), PUSH_MANY('Devs')), (b'jeremy', b'grin', b'lex', b'jack'))
|
||||
|
||||
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import unittest
|
||||
import tempfile
|
||||
|
||||
from orchstr8.testcase import AsyncioTestCase
|
||||
|
||||
from torba.coin.bitcoinsegwit import MainNetLedger as BTCLedger
|
||||
from torba.coin.bitcoincash import MainNetLedger as BCHLedger
|
||||
from torba.basemanager import BaseWalletManager
|
||||
from torba.wallet import Wallet, WalletStorage
|
||||
|
||||
|
||||
class TestWalletCreation(unittest.TestCase):
|
||||
class TestWalletCreation(AsyncioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
async def asyncSetUp(self):
|
||||
self.manager = BaseWalletManager()
|
||||
config = {'data_path': '/tmp/wallet'}
|
||||
self.btc_ledger = self.manager.get_or_create_ledger(BTCLedger.get_id(), config)
|
||||
|
|
|
@ -66,8 +66,9 @@ class BaseNetwork:
|
|||
async def stop(self):
|
||||
self.running = False
|
||||
if self.is_connected:
|
||||
disconnected = self.client.on_disconnected.first
|
||||
await self.client.close()
|
||||
await self.client.on_disconnected.first
|
||||
await disconnected
|
||||
|
||||
@property
|
||||
def is_connected(self):
|
||||
|
|
6
tox.ini
6
tox.ini
|
@ -17,9 +17,9 @@ changedir = {toxinidir}/tests
|
|||
setenv =
|
||||
integration: LEDGER={envname}
|
||||
commands =
|
||||
unit: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial unit
|
||||
unit: coverage run -p --source={envsitepackagesdir}/torba -m unittest discover -t . unit
|
||||
integration: orchstr8 download
|
||||
integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_transactions
|
||||
integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_reconnect
|
||||
integration: coverage run -p --source={envsitepackagesdir}/torba -m unittest integration.test_transactions
|
||||
# integration: coverage run -p --source={envsitepackagesdir}/torba -m unittest integration.test_reconnect
|
||||
# Too slow on Travis
|
||||
# integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_blockchain_reorganization
|
||||
|
|
Loading…
Reference in a new issue