Browse Source

tests: make setup fixtures optional.

This allows running tests that do not require, e.g., bitcoind, without having to run these setup fixtures at all.

Signed-off-by: PulpCattel <PulpCattel@users.noreply.github.com>
master
PulpCattel 3 years ago
parent
commit
c4d9b9264a
No known key found for this signature in database
GPG Key ID: BDFD82BA08D9F218
  1. 25
      conftest.py
  2. 2
      jmclient/test/test_blockchaininterface.py
  3. 2
      jmclient/test/test_bond_calc.py
  4. 5
      jmclient/test/test_client_protocol.py
  5. 2
      jmclient/test/test_coinjoin.py
  6. 3
      jmclient/test/test_commitment_utils.py
  7. 2
      jmclient/test/test_configure.py
  8. 2
      jmclient/test/test_core_nohistory_sync.py
  9. 4
      jmclient/test/test_payjoin.py
  10. 3
      jmclient/test/test_podle.py
  11. 3
      jmclient/test/test_privkeys.py
  12. 3
      jmclient/test/test_psbt_wallet.py
  13. 2
      jmclient/test/test_schedule.py
  14. 2
      jmclient/test/test_snicker.py
  15. 3
      jmclient/test/test_taker.py
  16. 2
      jmclient/test/test_tx_creation.py
  17. 3
      jmclient/test/test_valid_addresses.py
  18. 1
      jmclient/test/test_wallet.py
  19. 4
      jmclient/test/test_wallet_rpc.py
  20. 3
      jmclient/test/test_wallets.py
  21. 3
      jmclient/test/test_walletservice.py
  22. 3
      jmclient/test/test_walletutils.py
  23. 4
      jmclient/test/test_yieldgenerator.py
  24. 5
      jmdaemon/test/test_daemon_protocol.py
  25. 4
      jmdaemon/test/test_irc_messaging.py
  26. 2
      jmdaemon/test/test_orderbookwatch.py
  27. 2
      test/test_e2e_coinjoin.py

25
conftest.py

@ -82,6 +82,29 @@ def pytest_addoption(parser: Any) -> None:
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def setup_early_if_needed(request) -> None:
"""
Make sure fixtures requested by test *modules* are executed first.
I.e., like a dynamically set `autouse=True`.
(By default, without `autouse=True`, they would run later at request time)
Useful so that fixtures like `setup_regtest_bitcoind` can run *only* if
we are planning to invoke a test that requires it, but still at startup time.
"""
modules = set()
# Loop through the collected tests
for item in request.node.items:
module = item.getparent(pytest.Module)
if module in modules:
continue
modules.add(module)
# Loop through each test module marker
for marker in module.iter_markers('usefixtures'):
# We know we are gonna need these fixtures, so we invoke them early
for fixture in marker.args:
request.getfixturevalue(fixture)
@pytest.fixture(scope="session")
def setup_miniircd(pytestconfig): def setup_miniircd(pytestconfig):
""" """
Setup miniircd and handle its clean up. Setup miniircd and handle its clean up.
@ -102,7 +125,7 @@ def setup_miniircd(pytestconfig):
m.kill() m.kill()
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session")
def setup_regtest_bitcoind(pytestconfig): def setup_regtest_bitcoind(pytestconfig):
""" """
Setup regtest bitcoind and handle its clean up. Setup regtest bitcoind and handle its clean up.

2
jmclient/test/test_blockchaininterface.py

@ -10,6 +10,8 @@ from jmclient import load_test_config, jm_single, BaseWallet
log = get_log() log = get_log()
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
def sync_test_wallet(fast, wallet_service): def sync_test_wallet(fast, wallet_service):
sync_count = 0 sync_count = 0

2
jmclient/test/test_bond_calc.py

@ -4,6 +4,8 @@ import pytest
from jmclient import jm_single, load_test_config, FidelityBondMixin from jmclient import jm_single, load_test_config, FidelityBondMixin
from jmclient.bond_calc import get_next_locktime, get_bond_values, get_percentiles from jmclient.bond_calc import get_next_locktime, get_bond_values, get_percentiles
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
@pytest.mark.parametrize(('date', 'next_locktime'), @pytest.mark.parametrize(('date', 'next_locktime'),
((datetime(2022, 1, 1, 1, 1), datetime(2022, 2, 1)), ((datetime(2022, 1, 1, 1, 1), datetime(2022, 2, 1)),

5
jmclient/test/test_client_protocol.py

@ -21,6 +21,11 @@ import json
import jmbitcoin as bitcoin import jmbitcoin as bitcoin
import twisted import twisted
import base64 import base64
import pytest
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
twisted.internet.base.DelayedCall.debug = True twisted.internet.base.DelayedCall.debug = True
test_completed = False test_completed = False

2
jmclient/test/test_coinjoin.py

@ -18,6 +18,8 @@ from commontest import make_wallets, default_max_cj_fee
from test_taker import dummy_filter_orderbook from test_taker import dummy_filter_orderbook
import jmbitcoin as btc import jmbitcoin as btc
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))
log = get_log() log = get_log()

3
jmclient/test/test_commitment_utils.py

@ -6,6 +6,9 @@ from jmclient import (load_test_config, jm_single, BTC_P2WPKH)
from jmclient.commitment_utils import get_utxo_info, validate_utxo_data from jmclient.commitment_utils import get_utxo_info, validate_utxo_data
from jmbitcoin import select_chain_params from jmbitcoin import select_chain_params
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
def test_get_utxo_info(): def test_get_utxo_info():
load_test_config() load_test_config()
# this test tests mainnet keys, so temporarily switch network # this test tests mainnet keys, so temporarily switch network

2
jmclient/test/test_configure.py

@ -4,6 +4,8 @@ import pytest
from jmclient import load_test_config, jm_single from jmclient import load_test_config, jm_single
from jmclient.configure import get_blockchain_interface_instance from jmclient.configure import get_blockchain_interface_instance
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
def test_attribute_dict(): def test_attribute_dict():
from jmclient.configure import AttributeDict from jmclient.configure import AttributeDict

2
jmclient/test/test_core_nohistory_sync.py

@ -11,6 +11,8 @@ from jmclient import (load_test_config, SegwitLegacyWallet,
SegwitWallet, jm_single, BaseWallet) SegwitWallet, jm_single, BaseWallet)
from jmbitcoin import select_chain_params from jmbitcoin import select_chain_params
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
log = get_log() log = get_log()
def test_fast_sync_unavailable(setup_sync): def test_fast_sync_unavailable(setup_sync):

4
jmclient/test/test_payjoin.py

@ -4,6 +4,8 @@ Test doing payjoins over tcp client/server
""" """
import os import os
import pytest
from twisted.internet import reactor from twisted.internet import reactor
from twisted.web.server import Site from twisted.web.server import Site
from twisted.web.client import readBody from twisted.web.client import readBody
@ -26,6 +28,8 @@ from jmclient.payjoin import process_payjoin_proposal_from_server
from commontest import make_wallets from commontest import make_wallets
from test_coinjoin import make_wallets_to_list, sync_wallets from test_coinjoin import make_wallets_to_list, sync_wallets
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))
log = get_log() log = get_log()

3
jmclient/test/test_podle.py

@ -12,6 +12,9 @@ from jmclient import load_test_config, jm_single, generate_podle,\
get_podle_commitments, add_external_commitments, update_commitments get_podle_commitments, add_external_commitments, update_commitments
from jmclient.podle import verify_all_NUMS, verify_podle, PoDLEError from jmclient.podle import verify_all_NUMS, verify_podle, PoDLEError
from commontest import make_wallets from commontest import make_wallets
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
log = get_log() log = get_log()
def test_commitments_empty(setup_podle): def test_commitments_empty(setup_podle):

3
jmclient/test/test_privkeys.py

@ -7,6 +7,9 @@ from jmclient import BTCEngine, jm_single, load_test_config
import json import json
import pytest import pytest
import os import os
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))
def test_read_raw_privkeys(setup_keys): def test_read_raw_privkeys(setup_keys):

3
jmclient/test/test_psbt_wallet.py

@ -17,6 +17,9 @@ from jmclient import (load_test_config, jm_single, direct_send,
SegwitLegacyWallet, SegwitWallet, LegacyWallet, SegwitLegacyWallet, SegwitWallet, LegacyWallet,
VolatileStorage, get_network) VolatileStorage, get_network)
from jmclient.wallet import PSBTWalletMixin from jmclient.wallet import PSBTWalletMixin
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
log = get_log() log = get_log()
def create_volatile_wallet(seedphrase, wallet_cls=SegwitWallet): def create_volatile_wallet(seedphrase, wallet_cls=SegwitWallet):

2
jmclient/test/test_schedule.py

@ -6,6 +6,8 @@ from jmclient import (get_schedule, get_tumble_schedule,
tweak_tumble_schedule, load_test_config) tweak_tumble_schedule, load_test_config)
import os import os
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
valids = """#sample for testing valids = """#sample for testing
1, 110000000, 3, INTERNAL, 0, 16, 1 1, 110000000, 3, INTERNAL, 0, 16, 1
0, 20000000, 2, mnsquzxrHXpFsZeL42qwbKdCP2y1esN3qw, 9.88, 16, 0 0, 20000000, 2, mnsquzxrHXpFsZeL42qwbKdCP2y1esN3qw, 9.88, 16, 0

2
jmclient/test/test_snicker.py

@ -10,6 +10,8 @@ from jmbase import get_log, bintohex
from jmclient import (load_test_config, estimate_tx_fee, SNICKERReceiver, from jmclient import (load_test_config, estimate_tx_fee, SNICKERReceiver,
direct_send, BaseWallet) direct_send, BaseWallet)
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
log = get_log() log = get_log()
@pytest.mark.parametrize( @pytest.mark.parametrize(

3
jmclient/test/test_taker.py

@ -19,6 +19,9 @@ from taker_test_data import t_utxos_by_mixdepth, t_orderbook,\
t_maker_response, t_chosen_orders, t_dummy_ext t_maker_response, t_chosen_orders, t_dummy_ext
from commontest import default_max_cj_fee from commontest import default_max_cj_fee
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
def convert_utxos(utxodict): def convert_utxos(utxodict):
return_dict = {} return_dict = {}
for uk, val in utxodict.items(): for uk, val in utxodict.items():

2
jmclient/test/test_tx_creation.py

@ -13,6 +13,8 @@ import pytest
from jmbase import get_log from jmbase import get_log
from jmclient import load_test_config, jm_single, direct_send, estimate_tx_fee, compute_tx_locktime from jmclient import load_test_config, jm_single, direct_send, estimate_tx_fee, compute_tx_locktime
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
log = get_log() log = get_log()
#just a random selection of pubkeys for receiving multisigs; #just a random selection of pubkeys for receiving multisigs;
#if we ever need the privkeys, they are in a json file somewhere #if we ever need the privkeys, they are in a json file somewhere

3
jmclient/test/test_valid_addresses.py

@ -7,6 +7,9 @@ from bitcointx import ChainParams
import json import json
import pytest import pytest
import os import os
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))
def address_valid_somewhere(addr): def address_valid_somewhere(addr):

1
jmclient/test/test_wallet.py

@ -19,6 +19,7 @@ from test_blockchaininterface import sync_test_wallet
from freezegun import freeze_time from freezegun import freeze_time
from bitcointx.wallet import CCoinAddressError from bitcointx.wallet import CCoinAddressError
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))

4
jmclient/test/test_wallet_rpc.py

@ -1,4 +1,6 @@
import os, json import os, json
import pytest
from twisted.internet import reactor, defer, task from twisted.internet import reactor, defer, task
from twisted.web.client import readBody, Headers from twisted.web.client import readBody, Headers
@ -19,6 +21,8 @@ from test_coinjoin import make_wallets_to_list, sync_wallets
from test_websocket import (ClientTProtocol, test_tx_hex_1, from test_websocket import (ClientTProtocol, test_tx_hex_1,
test_tx_hex_txid, encoded_token) test_tx_hex_txid, encoded_token)
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))
testfilename = "testwrpc" testfilename = "testwrpc"

3
jmclient/test/test_wallets.py

@ -13,6 +13,9 @@ from jmclient import (
load_test_config, jm_single, load_test_config, jm_single,
estimate_tx_fee, BitcoinCoreInterface, Mnemonic) estimate_tx_fee, BitcoinCoreInterface, Mnemonic)
from taker_test_data import t_raw_signed_tx from taker_test_data import t_raw_signed_tx
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))
log = get_log() log = get_log()

3
jmclient/test/test_walletservice.py

@ -7,6 +7,9 @@ from jmclient import load_test_config, jm_single, \
WalletService WalletService
from test_blockchaininterface import sync_test_wallet from test_blockchaininterface import sync_test_wallet
from test_wallet import fund_wallet_addr, get_populated_wallet from test_wallet import fund_wallet_addr, get_populated_wallet
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
testdir = os.path.dirname(os.path.realpath(__file__)) testdir = os.path.dirname(os.path.realpath(__file__))
log = get_log() log = get_log()

3
jmclient/test/test_walletutils.py

@ -6,6 +6,9 @@ from jmclient.wallet_utils import (bip32pathparse, WalletView,
WalletViewAccount, WalletViewBranch, WalletViewAccount, WalletViewBranch,
WalletViewEntry, wallet_signmessage) WalletViewEntry, wallet_signmessage)
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
# The below signatures have all been verified against Electrum 4.0.9: # The below signatures have all been verified against Electrum 4.0.9:
@pytest.mark.parametrize('seed, hdpath, walletcls, message, sig, addr', [ @pytest.mark.parametrize('seed, hdpath, walletcls, message, sig, addr', [
[b"\x01"*16, "m/84'/0'/0'/0/0", SegwitWallet, "hello", [b"\x01"*16, "m/84'/0'/0'/0/0", SegwitWallet, "hello",

4
jmclient/test/test_yieldgenerator.py

@ -1,10 +1,14 @@
import unittest import unittest
import pytest
from jmbitcoin import CMutableTxOut, CMutableTransaction 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
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
class CustomUtxoWallet(SegwitLegacyWallet): class CustomUtxoWallet(SegwitLegacyWallet):
"""A wallet instance that makes it easy to do the tasks we need for """A wallet instance that makes it easy to do the tasks we need for

5
jmdaemon/test/test_daemon_protocol.py

@ -22,6 +22,11 @@ from msgdata import *
import base64 import base64
import sys import sys
from dummy_mc import DummyMessageChannel from dummy_mc import DummyMessageChannel
import pytest
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
test_completed = False test_completed = False
end_early = False end_early = False
jlog = get_log() jlog = get_log()

4
jmdaemon/test/test_irc_messaging.py

@ -8,6 +8,10 @@ from jmdaemon import IRCMessageChannel, MessageChannelCollection
#needed for test framework #needed for test framework
from jmclient import (load_test_config, get_mchannels, jm_single) from jmclient import (load_test_config, get_mchannels, jm_single)
import pytest
pytestmark = pytest.mark.usefixtures("setup_miniircd", "setup_regtest_bitcoind")
si = 1 si = 1
class DummyDaemon(object): class DummyDaemon(object):
def request_signature_verify(self, a, b, c, d, e, def request_signature_verify(self, a, b, c, d, e,

2
jmdaemon/test/test_orderbookwatch.py

@ -7,6 +7,8 @@ from jmdaemon.protocol import JM_VERSION, ORDER_KEYS
from jmbase.support import hextobin from jmbase.support import hextobin
from jmclient.fidelity_bond import FidelityBondProof from jmclient.fidelity_bond import FidelityBondProof
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
class DummyDaemon(object): class DummyDaemon(object):
def request_signature_verify(self, a, b, c, d, e, def request_signature_verify(self, a, b, c, d, e,
f, g, h): f, g, h):

2
test/test_e2e_coinjoin.py

@ -27,6 +27,8 @@ from jmclient import (YieldGeneratorBasic, load_test_config, jm_single,
import jmclient import jmclient
from jmclient.wallet_rpc import api_version_string from jmclient.wallet_rpc import api_version_string
pytestmark = pytest.mark.usefixtures("setup_regtest_bitcoind")
log = get_log() log = get_log()
wallet_name = "test-onion-yg-runner.jmdat" wallet_name = "test-onion-yg-runner.jmdat"

Loading…
Cancel
Save