Browse Source

fix usage of asyncio TestCase

add_frost_channel_encryption
zebra-lucky 2 months ago
parent
commit
80a256539f
  1. 12
      test/jmclient/commontest.py
  2. 6
      test/jmclient/test_client_protocol.py
  3. 4
      test/jmclient/test_wallet_rpc.py
  4. 8
      test/jmclient/test_yieldgenerator.py
  5. 15
      test/unified/common.py
  6. 4
      test/unified/test_bumpfee.py
  7. 4
      test/unified/test_segwit.py

12
test/jmclient/commontest.py

@ -5,7 +5,7 @@ import os
import random import random
from decimal import Decimal from decimal import Decimal
from typing import Callable, List, Optional, Set, Tuple, Union from typing import Callable, List, Optional, Set, Tuple, Union
from unittest import IsolatedAsyncioTestCase from unittest import IsolatedAsyncioTestCase as AsyncioTestCase
from twisted.trial.unittest import TestCase as TrialTestCase from twisted.trial.unittest import TestCase as TrialTestCase
@ -37,16 +37,6 @@ def dummy_info_callback(msg):
pass pass
class TrialAsyncioTestCase(TrialTestCase, IsolatedAsyncioTestCase):
def __init__(self, methodName='runTest'):
IsolatedAsyncioTestCase.__init__(self, methodName)
TrialTestCase.__init__(self, methodName)
def __call__(self, *args, **kwds):
return IsolatedAsyncioTestCase.run(self, *args, **kwds)
class DummyBlockchainInterface(BlockchainInterface): class DummyBlockchainInterface(BlockchainInterface):
def __init__(self) -> None: def __init__(self) -> None:

6
test/jmclient/test_client_protocol.py

@ -25,7 +25,7 @@ from twisted.protocols.amp import UnknownRemoteError
from twisted.protocols import amp from twisted.protocols import amp
from twisted.test import proto_helpers from twisted.test import proto_helpers
from taker_test_data import t_raw_signed_tx from taker_test_data import t_raw_signed_tx
from commontest import default_max_cj_fee, TrialAsyncioTestCase from commontest import default_max_cj_fee, AsyncioTestCase
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind") pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
@ -277,7 +277,7 @@ class DummyClientProtocolFactory(JMClientProtocolFactory):
return JMTakerClientProtocol(self, self.client, nick_priv=b"\xaa"*32 + b"\x01") return JMTakerClientProtocol(self, self.client, nick_priv=b"\xaa"*32 + b"\x01")
class TrialTestJMClientProto(TrialAsyncioTestCase): class TrialTestJMClientProto(AsyncioTestCase):
def setUp(self): def setUp(self):
global clientfactory global clientfactory
@ -322,7 +322,7 @@ class TrialTestJMClientProto(TrialAsyncioTestCase):
pass pass
class TestMakerClientProtocol(TrialAsyncioTestCase): class TestMakerClientProtocol(AsyncioTestCase):
""" """
very basic test case for JMMakerClientProtocol very basic test case for JMMakerClientProtocol

4
test/jmclient/test_wallet_rpc.py

@ -28,7 +28,7 @@ from jmclient import (
storage, storage,
) )
from jmclient.wallet_rpc import api_version_string, CJ_MAKER_RUNNING, CJ_NOT_RUNNING from jmclient.wallet_rpc import api_version_string, CJ_MAKER_RUNNING, CJ_NOT_RUNNING
from commontest import make_wallets, TrialAsyncioTestCase from commontest import make_wallets, AsyncioTestCase
from test_coinjoin import make_wallets_to_list, sync_wallets from test_coinjoin import make_wallets_to_list, sync_wallets
from test_websocket import ClientTProtocol, test_tx_hex_1, test_tx_hex_txid from test_websocket import ClientTProtocol, test_tx_hex_1, test_tx_hex_txid
@ -48,7 +48,7 @@ class JMWalletDaemonT(JMWalletDaemon):
return super().check_cookie(request, *args, **kwargs) return super().check_cookie(request, *args, **kwargs)
class WalletRPCTestBase(TrialAsyncioTestCase): class WalletRPCTestBase(AsyncioTestCase):
""" Base class for set up of tests of the """ Base class for set up of tests of the
Wallet RPC calls using the wallet_rpc.JMWalletDaemon service. Wallet RPC calls using the wallet_rpc.JMWalletDaemon service.
""" """

8
test/jmclient/test_yieldgenerator.py

@ -6,7 +6,7 @@ from jmbitcoin import CMutableTxOut, CMutableTransaction
from jmclient import load_test_config, jm_single,\ from jmclient import load_test_config, jm_single,\
SegwitLegacyWallet, VolatileStorage, YieldGeneratorBasic, \ SegwitLegacyWallet, VolatileStorage, YieldGeneratorBasic, \
get_network, WalletService get_network, WalletService
from commontest import TrialAsyncioTestCase from commontest import AsyncioTestCase
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind") pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
@ -73,7 +73,7 @@ async def create_yg_basic(balances, txfee_contribution=0, cjfee_a=0, cjfee_r=0,
return yg return yg
class CreateMyOrdersTests(TrialAsyncioTestCase): class CreateMyOrdersTests(AsyncioTestCase):
"""Unit tests for YieldGeneratorBasic.create_my_orders.""" """Unit tests for YieldGeneratorBasic.create_my_orders."""
async def test_no_coins(self): async def test_no_coins(self):
@ -130,7 +130,7 @@ class CreateMyOrdersTests(TrialAsyncioTestCase):
self.assertEqual(yg.create_my_orders(), []) self.assertEqual(yg.create_my_orders(), [])
class OidToOrderTests(TrialAsyncioTestCase): class OidToOrderTests(AsyncioTestCase):
"""Tests YieldGeneratorBasic.oid_to_order.""" """Tests YieldGeneratorBasic.oid_to_order."""
async def call_oid_to_order(self, yg, amount): async def call_oid_to_order(self, yg, amount):
@ -180,7 +180,7 @@ class OidToOrderTests(TrialAsyncioTestCase):
self.assertEqual(yg.wallet_service.wallet.get_addr_mixdepth(change_addr), 1) self.assertEqual(yg.wallet_service.wallet.get_addr_mixdepth(change_addr), 1)
class OfferReannouncementTests(TrialAsyncioTestCase): class OfferReannouncementTests(AsyncioTestCase):
"""Tests offer reannouncement logic from on_tx_unconfirmed.""" """Tests offer reannouncement logic from on_tx_unconfirmed."""
def call_on_tx_unconfirmed(self, yg): def call_on_tx_unconfirmed(self, yg):

15
test/unified/common.py

@ -10,7 +10,7 @@ from decimal import Decimal
data_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) data_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, os.path.join(data_dir)) sys.path.insert(0, os.path.join(data_dir))
from unittest import IsolatedAsyncioTestCase from unittest import IsolatedAsyncioTestCase as AsyncioTestCase
from twisted.trial.unittest import TestCase as TrialTestCase from twisted.trial.unittest import TestCase as TrialTestCase
from jmbase import get_log from jmbase import get_log
@ -23,16 +23,6 @@ from jmbase import chunks
log = get_log() log = get_log()
class TrialAsyncioTestCase(TrialTestCase, IsolatedAsyncioTestCase):
def __init__(self, methodName='runTest'):
IsolatedAsyncioTestCase.__init__(self, methodName)
TrialTestCase.__init__(self, methodName)
def __call__(self, *args, **kwds):
return IsolatedAsyncioTestCase.run(self, *args, **kwds)
async def make_sign_and_push(ins_full, async def make_sign_and_push(ins_full,
wallet_service, wallet_service,
amount, amount,
@ -138,6 +128,9 @@ async def make_wallets(n,
dest_addr = await wallet_service.get_new_addr( dest_addr = await wallet_service.get_new_addr(
j, BaseWallet.ADDRESS_TYPE_INTERNAL) j, BaseWallet.ADDRESS_TYPE_INTERNAL)
jm_single().bc_interface.grab_coins(dest_addr , amt) jm_single().bc_interface.grab_coins(dest_addr , amt)
# forward chain and update wallet_service current_blockheight
jm_single().bc_interface.tick_forward_chain(6)
wallet_service.update_blockheight()
return wallets return wallets

4
test/unified/test_bumpfee.py

@ -7,7 +7,7 @@ from scripts.bumpfee import (
check_valid_candidate, compute_bump_fee, check_valid_candidate, compute_bump_fee,
create_bumped_tx, sign_transaction, sign_psbt) create_bumped_tx, sign_transaction, sign_psbt)
from common import TrialAsyncioTestCase from common import AsyncioTestCase
def fund_wallet_addr(wallet, addr, value_btc=1): def fund_wallet_addr(wallet, addr, value_btc=1):
# special case, grab_coins returns hex from rpc: # special case, grab_coins returns hex from rpc:
@ -19,7 +19,7 @@ def fund_wallet_addr(wallet, addr, value_btc=1):
return list(utxo_in.keys())[0] return list(utxo_in.keys())[0]
class BumpFeeTests(TrialAsyncioTestCase): class BumpFeeTests(AsyncioTestCase):
async def asyncSetUp(self): async def asyncSetUp(self):
load_test_config() load_test_config()

4
test/unified/test_segwit.py

@ -11,14 +11,14 @@ from jmbase import get_log, hextobin
from jmclient import load_test_config, jm_single, LegacyWallet, BaseWallet from jmclient import load_test_config, jm_single, LegacyWallet, BaseWallet
from common import TrialAsyncioTestCase from common import AsyncioTestCase
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind") pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
log = get_log() log = get_log()
class SegWitTests(TrialAsyncioTestCase, ParametrizedTestCase): class SegWitTests(AsyncioTestCase, ParametrizedTestCase):
async def asyncSetUp(self): async def asyncSetUp(self):
load_test_config() load_test_config()

Loading…
Cancel
Save