fixing tests

This commit is contained in:
Lex Berezhny 2018-10-15 00:45:21 -04:00
parent e10f1df321
commit 2cd1947ef5
7 changed files with 29 additions and 23 deletions

View file

@ -1,5 +1,4 @@
import asyncio from orchstr8.testcase import IntegrationTestCase
from orchstr8.testcase import IntegrationTestCase, d2f
from torba.constants import COIN from torba.constants import COIN
@ -8,7 +7,7 @@ class ReconnectTests(IntegrationTestCase):
VERBOSE = False VERBOSE = False
async def test_connection_drop_still_receives_events_after_reconnected(self): 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() self.ledger.network.client.connectionLost()
sendtxid = await self.blockchain.send_to_address(address1, 1.1337) sendtxid = await self.blockchain.send_to_address(address1, 1.1337)
await self.on_transaction_id(sendtxid) # mempool await self.on_transaction_id(sendtxid) # mempool
@ -21,13 +20,13 @@ class ReconnectTests(IntegrationTestCase):
# what's that smoke on my ethernet cable? oh no! # what's that smoke on my ethernet cable? oh no!
self.ledger.network.client.connectionLost() self.ledger.network.client.connectionLost()
with self.assertRaisesRegex(TimeoutError, 'Connection dropped'): with self.assertRaisesRegex(TimeoutError, 'Connection dropped'):
await d2f(d) await d
# rich but offline? no way, no water, let's retry # rich but offline? no way, no water, let's retry
with self.assertRaisesRegex(ConnectionError, 'connection is not available'): 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 # * goes to pick some water outside... * time passes by and another donation comes in
sendtxid = await self.blockchain.send_to_address(address1, 42) sendtxid = await self.blockchain.send_to_address(address1, 42)
await self.blockchain.generate(1) await self.blockchain.generate(1)
# omg, the burned cable still works! torba is fire proof! # 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)

View file

@ -1,12 +1,13 @@
import unittest
from binascii import unhexlify, hexlify from binascii import unhexlify, hexlify
from orchstr8.testcase import AsyncioTestCase
from .key_fixtures import expected_ids, expected_privkeys, expected_hardened_privkeys from .key_fixtures import expected_ids, expected_privkeys, expected_hardened_privkeys
from torba.bip32 import PubKey, PrivateKey, from_extended_key_string from torba.bip32 import PubKey, PrivateKey, from_extended_key_string
from torba.coin.bitcoinsegwit import MainNetLedger as ledger_class from torba.coin.bitcoinsegwit import MainNetLedger as ledger_class
class BIP32Tests(unittest.TestCase): class BIP32Tests(AsyncioTestCase):
def test_pubkey_validation(self): def test_pubkey_validation(self):
with self.assertRaisesRegex(TypeError, 'chain code must be raw bytes'): with self.assertRaisesRegex(TypeError, 'chain code must be raw bytes'):
@ -39,7 +40,7 @@ class BIP32Tests(unittest.TestCase):
self.assertIsInstance(new_key, PubKey) self.assertIsInstance(new_key, PubKey)
self.assertEqual(hexlify(new_key.identifier()), expected_ids[i]) 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'): with self.assertRaisesRegex(TypeError, 'private key must be raw bytes'):
PrivateKey(None, None, b'abcd'*8, 0, 255) PrivateKey(None, None, b'abcd'*8, 0, 255)
with self.assertRaisesRegex(ValueError, 'private key must be 32 bytes'): with self.assertRaisesRegex(ValueError, 'private key must be 32 bytes'):
@ -64,7 +65,7 @@ class BIP32Tests(unittest.TestCase):
private_key.child(-1) private_key.child(-1)
self.assertIsInstance(private_key.child(PrivateKey.HARDENED), PrivateKey) self.assertIsInstance(private_key.child(PrivateKey.HARDENED), PrivateKey)
def test_private_key_derivation(self): async def test_private_key_derivation(self):
private_key = PrivateKey( private_key = PrivateKey(
ledger_class({ ledger_class({
'db': ledger_class.database_class(':memory:'), 'db': ledger_class.database_class(':memory:'),
@ -82,7 +83,7 @@ class BIP32Tests(unittest.TestCase):
self.assertIsInstance(new_privkey, PrivateKey) self.assertIsInstance(new_privkey, PrivateKey)
self.assertEqual(hexlify(new_privkey.private_key_bytes), expected_hardened_privkeys[i - 1 - PrivateKey.HARDENED]) 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({ ledger = ledger_class({
'db': ledger_class.database_class(':memory:'), 'db': ledger_class.database_class(':memory:'),
'headers': ledger_class.headers_class(':memory:'), 'headers': ledger_class.headers_class(':memory:'),

View file

@ -1,6 +1,7 @@
import unittest
from types import GeneratorType from types import GeneratorType
from orchstr8.testcase import AsyncioTestCase
from torba.coin.bitcoinsegwit import MainNetLedger as ledger_class from torba.coin.bitcoinsegwit import MainNetLedger as ledger_class
from torba.coinselection import CoinSelector, MAXIMUM_TRIES from torba.coinselection import CoinSelector, MAXIMUM_TRIES
from torba.constants import CENT 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 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({ self.ledger = ledger_class({
'db': ledger_class.database_class(':memory:'), 'db': ledger_class.database_class(':memory:'),
'headers': ledger_class.headers_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): def estimates(self, *args):
txos = args[0] if isinstance(args[0], (GeneratorType, list)) else args txos = args[0] if isinstance(args[0], (GeneratorType, list)) else args

View file

@ -93,7 +93,7 @@ class TestScriptTemplates(unittest.TestCase):
) )
def test_push_data_many_not_separated(self): 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')) parse((PUSH_MANY('Chiefs'), PUSH_MANY('Devs')), (b'jeremy', b'grin', b'lex', b'jack'))

View file

@ -1,15 +1,16 @@
import unittest
import tempfile import tempfile
from orchstr8.testcase import AsyncioTestCase
from torba.coin.bitcoinsegwit import MainNetLedger as BTCLedger from torba.coin.bitcoinsegwit import MainNetLedger as BTCLedger
from torba.coin.bitcoincash import MainNetLedger as BCHLedger from torba.coin.bitcoincash import MainNetLedger as BCHLedger
from torba.basemanager import BaseWalletManager from torba.basemanager import BaseWalletManager
from torba.wallet import Wallet, WalletStorage from torba.wallet import Wallet, WalletStorage
class TestWalletCreation(unittest.TestCase): class TestWalletCreation(AsyncioTestCase):
def setUp(self): async def asyncSetUp(self):
self.manager = BaseWalletManager() self.manager = BaseWalletManager()
config = {'data_path': '/tmp/wallet'} config = {'data_path': '/tmp/wallet'}
self.btc_ledger = self.manager.get_or_create_ledger(BTCLedger.get_id(), config) self.btc_ledger = self.manager.get_or_create_ledger(BTCLedger.get_id(), config)

View file

@ -66,8 +66,9 @@ class BaseNetwork:
async def stop(self): async def stop(self):
self.running = False self.running = False
if self.is_connected: if self.is_connected:
disconnected = self.client.on_disconnected.first
await self.client.close() await self.client.close()
await self.client.on_disconnected.first await disconnected
@property @property
def is_connected(self): def is_connected(self):

View file

@ -17,9 +17,9 @@ changedir = {toxinidir}/tests
setenv = setenv =
integration: LEDGER={envname} integration: LEDGER={envname}
commands = 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: 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 unittest 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_reconnect
# Too slow on Travis # Too slow on Travis
# integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_blockchain_reorganization # integration: coverage run -p --source={envsitepackagesdir}/torba -m twisted.trial --reactor=asyncio integration.test_blockchain_reorganization