From c5426068aaed59efeb9fc3c763935d96e4f8df42 Mon Sep 17 00:00:00 2001 From: Adam Kelly <338792+aqk@users.noreply.github.com> Date: Tue, 29 Mar 2022 13:25:30 -0700 Subject: [PATCH] Consolidate test fixtures (#10778) * Rename confusing fixtures, especially ones with the same name but different implementation * revert premature fixture rename: two_wallet_nodes_start_height_1 * Consolidate test fixtures --- .../test_blockchain_transactions.py | 2 +- tests/conftest.py | 314 +++++++++++++++++- tests/core/daemon/test_daemon.py | 48 +-- .../full_node/full_sync/test_full_sync.py | 1 - .../full_node/stores/test_full_node_store.py | 8 +- tests/core/full_node/test_full_node.py | 65 +--- .../full_node/test_mempool_performance.py | 12 +- tests/core/full_node/test_performance.py | 23 +- tests/core/full_node/test_transactions.py | 20 -- tests/core/server/test_dos.py | 10 +- tests/core/ssl/test_ssl.py | 33 +- tests/core/test_daemon_rpc.py | 10 +- tests/core/test_filter.py | 9 - tests/core/test_full_node_rpc.py | 16 +- tests/pools/test_pool_rpc.py | 6 - tests/wallet/cat_wallet/test_cat_lifecycle.py | 22 +- tests/wallet/cat_wallet/test_cat_wallet.py | 24 +- .../wallet/cat_wallet/test_offer_lifecycle.py | 23 +- tests/wallet/cat_wallet/test_trades.py | 55 +-- tests/wallet/did_wallet/test_did.py | 39 +-- tests/wallet/did_wallet/test_did_rpc.py | 14 +- tests/wallet/rl_wallet/test_rl_rpc.py | 8 - tests/wallet/rl_wallet/test_rl_wallet.py | 8 - tests/wallet/rpc/test_wallet_rpc.py | 28 +- .../simple_sync/test_simple_sync_protocol.py | 18 +- tests/wallet/sync/test_wallet_sync.py | 21 +- tests/wallet/test_wallet.py | 46 +-- tests/wallet/test_wallet_blockchain.py | 9 +- 28 files changed, 377 insertions(+), 515 deletions(-) diff --git a/tests/blockchain/test_blockchain_transactions.py b/tests/blockchain/test_blockchain_transactions.py index 1d0c830ac0..4f39638ce9 100644 --- a/tests/blockchain/test_blockchain_transactions.py +++ b/tests/blockchain/test_blockchain_transactions.py @@ -11,9 +11,9 @@ from chia.types.spend_bundle import SpendBundle from chia.util.errors import ConsensusError, Err from chia.util.ints import uint64 from tests.blockchain.blockchain_test_utils import _validate_and_add_block -from tests.wallet_tools import WalletTool from tests.setup_nodes import test_constants from tests.util.generator_tools_testing import run_and_get_removals_and_additions +from tests.wallet_tools import WalletTool BURN_PUZZLE_HASH = b"0" * 32 diff --git a/tests/conftest.py b/tests/conftest.py index c59b5f4589..f2d3933a5f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,8 @@ # flake8: noqa E402 # See imports after multiprocessing.set_start_method import multiprocessing import os +from secrets import token_bytes + import pytest import pytest_asyncio import tempfile @@ -8,11 +10,34 @@ import tempfile from tests.setup_nodes import setup_node_and_wallet, setup_n_nodes, setup_two_nodes # Set spawn after stdlib imports, but before other imports +from chia.clvm.spend_sim import SimClient, SpendSim +from chia.protocols import full_node_protocol +from chia.simulator.simulator_protocol import FarmNewBlockProtocol +from chia.types.blockchain_format.sized_bytes import bytes32 +from chia.types.peer_info import PeerInfo +from chia.util.ints import uint16 +from tests.core.node_height import node_height_at_least +from tests.pools.test_pool_rpc import wallet_is_synced +from tests.setup_nodes import ( + setup_simulators_and_wallets, + setup_node_and_wallet, + setup_full_system, + setup_daemon, + setup_n_nodes, + setup_introducer, + setup_timelord, + setup_two_nodes, +) +from tests.simulation.test_simulation import test_constants_modified +from tests.time_out_assert import time_out_assert +from tests.util.socket import find_available_listen_port +from tests.wallet_tools import WalletTool + multiprocessing.set_start_method("spawn") from pathlib import Path from chia.util.keyring_wrapper import KeyringWrapper -from tests.block_tools import BlockTools, test_constants, create_block_tools +from tests.block_tools import BlockTools, test_constants, create_block_tools, create_block_tools_async from tests.util.keyring import TempKeyring @@ -157,6 +182,12 @@ async def two_nodes(db_version, self_hostname): yield _ +@pytest_asyncio.fixture(scope="function") +async def setup_two_nodes_fixture(db_version): + async for _ in setup_simulators_and_wallets(2, 0, {}, db_version=db_version): + yield _ + + @pytest_asyncio.fixture(scope="function") async def three_nodes(db_version, self_hostname): async for _ in setup_n_nodes(test_constants, 3, db_version=db_version, self_hostname=self_hostname): @@ -173,3 +204,284 @@ async def four_nodes(db_version, self_hostname): async def five_nodes(db_version, self_hostname): async for _ in setup_n_nodes(test_constants, 5, db_version=db_version, self_hostname=self_hostname): yield _ + + +@pytest_asyncio.fixture(scope="module") +async def wallet_nodes(bt): + async_gen = setup_simulators_and_wallets(2, 1, {"MEMPOOL_BLOCK_BUFFER": 2, "MAX_BLOCK_COST_CLVM": 400000000}) + nodes, wallets = await async_gen.__anext__() + full_node_1 = nodes[0] + full_node_2 = nodes[1] + server_1 = full_node_1.full_node.server + server_2 = full_node_2.full_node.server + wallet_a = bt.get_pool_wallet_tool() + wallet_receiver = WalletTool(full_node_1.full_node.constants) + yield full_node_1, full_node_2, server_1, server_2, wallet_a, wallet_receiver + + async for _ in async_gen: + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def setup_four_nodes(db_version): + async for _ in setup_simulators_and_wallets(5, 0, {}, db_version=db_version): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def two_nodes_sim_and_wallets(): + async for _ in setup_simulators_and_wallets(2, 0, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def wallet_node_sim_and_wallet(): + async for _ in setup_simulators_and_wallets(1, 1, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def wallet_node_100_pk(): + async for _ in setup_simulators_and_wallets(1, 1, {}, initial_num_public_keys=100): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def two_wallet_nodes(): + async for _ in setup_simulators_and_wallets(1, 2, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def three_sim_two_wallets(): + async for _ in setup_simulators_and_wallets(3, 2, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def setup_two_nodes_and_wallet(): + async for _ in setup_simulators_and_wallets(2, 1, {}, db_version=2): # xxx + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def three_wallet_nodes(): + async for _ in setup_simulators_and_wallets(1, 3, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def two_wallet_nodes_five_freeze(): + async for _ in setup_simulators_and_wallets(1, 2, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def wallet_node_simulator(): + async for _ in setup_simulators_and_wallets(1, 1, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def wallet_two_node_simulator(): + async for _ in setup_simulators_and_wallets(2, 1, {}): + yield _ + + +@pytest_asyncio.fixture(scope="module") +async def wallet_nodes_mempool_perf(bt): + key_seed = bt.farmer_master_sk_entropy + async for _ in setup_simulators_and_wallets(2, 1, {}, key_seed=key_seed): + yield _ + + +@pytest_asyncio.fixture(scope="module") +async def wallet_nodes_perf(bt): + async_gen = setup_simulators_and_wallets(1, 1, {"MEMPOOL_BLOCK_BUFFER": 1, "MAX_BLOCK_COST_CLVM": 11000000000}) + nodes, wallets = await async_gen.__anext__() + full_node_1 = nodes[0] + server_1 = full_node_1.full_node.server + wallet_a = bt.get_pool_wallet_tool() + wallet_receiver = WalletTool(full_node_1.full_node.constants) + yield full_node_1, server_1, wallet_a, wallet_receiver + + async for _ in async_gen: + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def wallet_node_starting_height(self_hostname): + async for _ in setup_node_and_wallet(test_constants, self_hostname, starting_height=100): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def wallet_nodes_mainnet(bt, db_version): + async_gen = setup_simulators_and_wallets(2, 1, {"NETWORK_TYPE": 0}, db_version=db_version) + nodes, wallets = await async_gen.__anext__() + full_node_1 = nodes[0] + full_node_2 = nodes[1] + server_1 = full_node_1.full_node.server + server_2 = full_node_2.full_node.server + wallet_a = bt.get_pool_wallet_tool() + wallet_receiver = WalletTool(full_node_1.full_node.constants) + yield full_node_1, full_node_2, server_1, server_2, wallet_a, wallet_receiver + + async for _ in async_gen: + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def three_nodes_two_wallets(): + async for _ in setup_simulators_and_wallets(3, 2, {}): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def wallet_and_node(): + async for _ in setup_simulators_and_wallets(1, 1, {}): + yield _ + + +# TODO: Ideally, the db_version should be the (parameterized) db_version +# fixture, to test all versions of the database schema. This doesn't work +# because of a hack in shutting down the full node, which means you cannot run +# more than one simulations per process. +@pytest_asyncio.fixture(scope="function") +async def daemon_simulation(bt, get_b_tools, get_b_tools_1): + async for _ in setup_full_system( + test_constants_modified, + bt, + b_tools=get_b_tools, + b_tools_1=get_b_tools_1, + connect_to_daemon=True, + db_version=1, + ): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def get_daemon(bt): + async for _ in setup_daemon(btools=bt): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def get_temp_keyring(): + with TempKeyring() as keychain: + yield keychain + + +@pytest_asyncio.fixture(scope="function") +async def get_b_tools_1(get_temp_keyring): + return await create_block_tools_async(constants=test_constants_modified, keychain=get_temp_keyring) + + +@pytest_asyncio.fixture(scope="function") +async def get_b_tools(get_temp_keyring): + local_b_tools = await create_block_tools_async(constants=test_constants_modified, keychain=get_temp_keyring) + new_config = local_b_tools._config + local_b_tools.change_config(new_config) + return local_b_tools + + +@pytest_asyncio.fixture(scope="function") +async def get_daemon_with_temp_keyring(get_b_tools): + async for daemon in setup_daemon(btools=get_b_tools): + yield get_b_tools, daemon + + +@pytest_asyncio.fixture(scope="function") +async def wallets_prefarm(two_wallet_nodes, self_hostname, trusted): + """ + Sets up the node with 10 blocks, and returns a payer and payee wallet. + """ + farm_blocks = 10 + buffer = 4 + full_nodes, wallets = two_wallet_nodes + full_node_api = full_nodes[0] + full_node_server = full_node_api.server + wallet_node_0, wallet_server_0 = wallets[0] + wallet_node_1, wallet_server_1 = wallets[1] + wallet_0 = wallet_node_0.wallet_state_manager.main_wallet + wallet_1 = wallet_node_1.wallet_state_manager.main_wallet + + ph0 = await wallet_0.get_new_puzzlehash() + ph1 = await wallet_1.get_new_puzzlehash() + + if trusted: + wallet_node_0.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()} + wallet_node_1.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()} + else: + wallet_node_0.config["trusted_peers"] = {} + wallet_node_1.config["trusted_peers"] = {} + + await wallet_server_0.start_client(PeerInfo(self_hostname, uint16(full_node_server._port)), None) + await wallet_server_1.start_client(PeerInfo(self_hostname, uint16(full_node_server._port)), None) + + for i in range(0, farm_blocks): + await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph0)) + + for i in range(0, farm_blocks): + await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph1)) + + for i in range(0, buffer): + await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(bytes32(token_bytes(nbytes=32)))) + + await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api) + await time_out_assert(10, wallet_is_synced, True, wallet_node_1, full_node_api) + + return wallet_node_0, wallet_node_1, full_node_api + + +@pytest_asyncio.fixture(scope="function") +async def introducer(bt): + introducer_port = find_available_listen_port("introducer") + async for _ in setup_introducer(bt, introducer_port): + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def timelord(bt): + timelord_port = find_available_listen_port("timelord") + node_port = find_available_listen_port("node") + rpc_port = find_available_listen_port("rpc") + vdf_port = find_available_listen_port("vdf") + async for _ in setup_timelord(timelord_port, node_port, rpc_port, vdf_port, False, test_constants, bt): + yield _ + + +@pytest_asyncio.fixture(scope="module") +async def two_nodes_mempool(bt, wallet_a): + async_gen = setup_simulators_and_wallets(2, 1, {}) + nodes, _ = await async_gen.__anext__() + full_node_1 = nodes[0] + full_node_2 = nodes[1] + server_1 = full_node_1.full_node.server + server_2 = full_node_2.full_node.server + + reward_ph = wallet_a.get_new_puzzlehash() + blocks = bt.get_consecutive_blocks( + 3, + guarantee_transaction_block=True, + farmer_reward_puzzle_hash=reward_ph, + pool_reward_puzzle_hash=reward_ph, + ) + + for block in blocks: + await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block)) + + await time_out_assert(60, node_height_at_least, True, full_node_1, blocks[-1].height) + + yield full_node_1, full_node_2, server_1, server_2 + + async for _ in async_gen: + yield _ + + +@pytest_asyncio.fixture(scope="function") +async def setup_sim(): + sim = await SpendSim.create() + sim_client = SimClient(sim) + await sim.farm_block() + return sim, sim_client diff --git a/tests/core/daemon/test_daemon.py b/tests/core/daemon/test_daemon.py index fb6fe11465..28d4226d5c 100644 --- a/tests/core/daemon/test_daemon.py +++ b/tests/core/daemon/test_daemon.py @@ -3,62 +3,16 @@ import asyncio import json import logging import pytest -import pytest_asyncio from chia.daemon.server import WebSocketServer from chia.server.outbound_message import NodeType from chia.types.peer_info import PeerInfo -from tests.block_tools import BlockTools, create_block_tools_async +from tests.block_tools import BlockTools from chia.util.ints import uint16 from chia.util.keyring_wrapper import DEFAULT_PASSPHRASE_IF_NO_MASTER_PASSPHRASE from chia.util.ws_message import create_payload from tests.core.node_height import node_height_at_least -from tests.setup_nodes import setup_daemon, setup_full_system -from tests.simulation.test_simulation import test_constants_modified from tests.time_out_assert import time_out_assert_custom_interval, time_out_assert -from tests.util.keyring import TempKeyring - - -@pytest_asyncio.fixture(scope="function") -async def get_temp_keyring(): - with TempKeyring() as keychain: - yield keychain - - -@pytest_asyncio.fixture(scope="function") -async def get_b_tools_1(get_temp_keyring): - return await create_block_tools_async(constants=test_constants_modified, keychain=get_temp_keyring) - - -@pytest_asyncio.fixture(scope="function") -async def get_b_tools(get_temp_keyring): - local_b_tools = await create_block_tools_async(constants=test_constants_modified, keychain=get_temp_keyring) - new_config = local_b_tools._config - local_b_tools.change_config(new_config) - return local_b_tools - - -@pytest_asyncio.fixture(scope="function") -async def get_daemon_with_temp_keyring(get_b_tools): - async for daemon in setup_daemon(btools=get_b_tools): - yield get_b_tools, daemon - - -# TODO: Ideally, the db_version should be the (parameterized) db_version -# fixture, to test all versions of the database schema. This doesn't work -# because of a hack in shutting down the full node, which means you cannot run -# more than one simulations per process. -@pytest_asyncio.fixture(scope="function") -async def daemon_simulation(bt, get_b_tools, get_b_tools_1): - async for _ in setup_full_system( - test_constants_modified, - bt, - b_tools=get_b_tools, - b_tools_1=get_b_tools_1, - connect_to_daemon=True, - db_version=1, - ): - yield _ class TestDaemon: diff --git a/tests/core/full_node/full_sync/test_full_sync.py b/tests/core/full_node/full_sync/test_full_sync.py index 0444f827a1..df244e7bbe 100644 --- a/tests/core/full_node/full_sync/test_full_sync.py +++ b/tests/core/full_node/full_sync/test_full_sync.py @@ -17,7 +17,6 @@ from tests.core.node_height import node_height_exactly, node_height_between from tests.setup_nodes import test_constants from tests.time_out_assert import time_out_assert - log = logging.getLogger(__name__) diff --git a/tests/core/full_node/stores/test_full_node_store.py b/tests/core/full_node/stores/test_full_node_store.py index c96307e283..ca6c14cb14 100644 --- a/tests/core/full_node/stores/test_full_node_store.py +++ b/tests/core/full_node/stores/test_full_node_store.py @@ -1,5 +1,3 @@ -# flake8: noqa: F811, F401 -import asyncio import atexit import logging from secrets import token_bytes @@ -8,7 +6,6 @@ from typing import List, Optional import pytest import pytest_asyncio -from chia.consensus.block_record import BlockRecord from chia.consensus.blockchain import ReceiveBlockResult from chia.consensus.find_fork_point import find_fork_point_in_chain from chia.consensus.multiprocess_validation import PreValidationResult @@ -20,12 +17,11 @@ from chia.protocols.timelord_protocol import NewInfusionPointVDF from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.unfinished_block import UnfinishedBlock from chia.util.block_cache import BlockCache -from tests.block_tools import get_signage_point, create_block_tools from chia.util.hash import std_hash from chia.util.ints import uint8, uint32, uint64, uint128 +from tests.block_tools import get_signage_point, create_block_tools from tests.blockchain.blockchain_test_utils import ( _validate_and_add_block, - _validate_and_add_block_multi_result, _validate_and_add_block_no_error, ) from tests.setup_nodes import test_constants as test_constants_original @@ -627,7 +623,7 @@ class TestFullNodeStore: for block in blocks: await _validate_and_add_block_no_error(blockchain, block) - log.warning(f"Starting loop") + log.warning("Starting loop") while True: log.warning("Looping") blocks = bt.get_consecutive_blocks(1, block_list_input=blocks, skip_slots=1) diff --git a/tests/core/full_node/test_full_node.py b/tests/core/full_node/test_full_node.py index 4d02d7a375..5c324c3540 100644 --- a/tests/core/full_node/test_full_node.py +++ b/tests/core/full_node/test_full_node.py @@ -5,11 +5,10 @@ import random import time from secrets import token_bytes from typing import Dict, Optional, List -from blspy import G2Element -from clvm.casts import int_to_bytes import pytest -import pytest_asyncio +from blspy import G2Element +from clvm.casts import int_to_bytes from chia.consensus.pot_iterations import is_overflow_block from chia.full_node.bundle_tools import detect_potential_template_generator @@ -33,26 +32,24 @@ from chia.types.mempool_inclusion_status import MempoolInclusionStatus from chia.types.peer_info import PeerInfo, TimestampedPeerInfo from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_block import UnfinishedBlock -from tests.block_tools import get_signage_point from chia.util.errors import Err from chia.util.hash import std_hash from chia.util.ints import uint8, uint16, uint32, uint64 from chia.util.recursive_replace import recursive_replace from chia.util.vdf_prover import get_vdf_info_and_proof +from chia.wallet.transaction_record import TransactionRecord +from tests.block_tools import get_signage_point from tests.blockchain.blockchain_test_utils import ( _validate_and_add_block, _validate_and_add_block_no_error, ) -from tests.pools.test_pool_rpc import wallet_is_synced -from tests.wallet_tools import WalletTool -from chia.wallet.transaction_record import TransactionRecord - from tests.connection_utils import add_dummy_connection, connect_and_get_peer from tests.core.full_node.stores.test_coin_store import get_future_reward_coins from tests.core.full_node.test_mempool_performance import wallet_height_at_least from tests.core.make_block_generator import make_spend_bundle from tests.core.node_height import node_height_at_least -from tests.setup_nodes import setup_simulators_and_wallets, test_constants +from tests.pools.test_pool_rpc import wallet_is_synced +from tests.setup_nodes import test_constants from tests.time_out_assert import time_out_assert, time_out_assert_custom_interval, time_out_messages log = logging.getLogger(__name__) @@ -98,56 +95,6 @@ async def get_block_path(full_node: FullNodeAPI): return blocks_list -@pytest_asyncio.fixture(scope="module") -async def wallet_nodes(bt): - async_gen = setup_simulators_and_wallets(2, 1, {"MEMPOOL_BLOCK_BUFFER": 2, "MAX_BLOCK_COST_CLVM": 400000000}) - nodes, wallets = await async_gen.__anext__() - full_node_1 = nodes[0] - full_node_2 = nodes[1] - server_1 = full_node_1.full_node.server - server_2 = full_node_2.full_node.server - wallet_a = bt.get_pool_wallet_tool() - wallet_receiver = WalletTool(full_node_1.full_node.constants) - yield full_node_1, full_node_2, server_1, server_2, wallet_a, wallet_receiver - - async for _ in async_gen: - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def setup_four_nodes(db_version): - async for _ in setup_simulators_and_wallets(5, 0, {}, db_version=db_version): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def setup_two_nodes_fixture(db_version): - async for _ in setup_simulators_and_wallets(2, 0, {}, db_version=db_version): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def setup_two_nodes_and_wallet(): - async for _ in setup_simulators_and_wallets(2, 1, {}, db_version=2): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def wallet_nodes_mainnet(bt, db_version): - async_gen = setup_simulators_and_wallets(2, 1, {"NETWORK_TYPE": 0}, db_version=db_version) - nodes, wallets = await async_gen.__anext__() - full_node_1 = nodes[0] - full_node_2 = nodes[1] - server_1 = full_node_1.full_node.server - server_2 = full_node_2.full_node.server - wallet_a = bt.get_pool_wallet_tool() - wallet_receiver = WalletTool(full_node_1.full_node.constants) - yield full_node_1, full_node_2, server_1, server_2, wallet_a, wallet_receiver - - async for _ in async_gen: - yield _ - - class TestFullNodeBlockCompression: @pytest.mark.asyncio @pytest.mark.parametrize("tx_size", [10000, 3000000000000]) diff --git a/tests/core/full_node/test_mempool_performance.py b/tests/core/full_node/test_mempool_performance.py index a8a7766aff..96b44d6a8c 100644 --- a/tests/core/full_node/test_mempool_performance.py +++ b/tests/core/full_node/test_mempool_performance.py @@ -1,11 +1,9 @@ # flake8: noqa: F811, F401 -import asyncio +import logging import time import pytest -import pytest_asyncio -import logging from chia.protocols import full_node_protocol from chia.types.peer_info import PeerInfo @@ -13,7 +11,6 @@ from chia.util.ints import uint16 from chia.wallet.transaction_record import TransactionRecord from chia.wallet.wallet_node import WalletNode from tests.connection_utils import connect_and_get_peer -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert @@ -35,13 +32,6 @@ async def wallet_balance_at_least(wallet_node: WalletNode, balance): log = logging.getLogger(__name__) -@pytest_asyncio.fixture(scope="module") -async def wallet_nodes_mempool_perf(bt): - key_seed = bt.farmer_master_sk_entropy - async for _ in setup_simulators_and_wallets(2, 1, {}, key_seed=key_seed): - yield _ - - class TestMempoolPerformance: @pytest.mark.asyncio @pytest.mark.benchmark diff --git a/tests/core/full_node/test_performance.py b/tests/core/full_node/test_performance.py index 4a1ce2260c..58e1edeac3 100644 --- a/tests/core/full_node/test_performance.py +++ b/tests/core/full_node/test_performance.py @@ -1,15 +1,13 @@ # flake8: noqa: F811, F401 -import asyncio +import cProfile import dataclasses import logging import random import time from typing import Dict -from clvm.casts import int_to_bytes import pytest -import pytest_asyncio -import cProfile +from clvm.casts import int_to_bytes from chia.consensus.block_record import BlockRecord from chia.full_node.full_node_api import FullNodeAPI @@ -18,12 +16,9 @@ from chia.types.condition_opcodes import ConditionOpcode from chia.types.condition_with_args import ConditionWithArgs from chia.types.unfinished_block import UnfinishedBlock from chia.util.ints import uint64 -from tests.wallet_tools import WalletTool - from tests.connection_utils import add_dummy_connection from tests.core.full_node.stores.test_coin_store import get_future_reward_coins from tests.core.node_height import node_height_at_least -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert log = logging.getLogger(__name__) @@ -39,20 +34,6 @@ async def get_block_path(full_node: FullNodeAPI): return blocks_list -@pytest_asyncio.fixture(scope="module") -async def wallet_nodes_perf(bt): - async_gen = setup_simulators_and_wallets(1, 1, {"MEMPOOL_BLOCK_BUFFER": 1, "MAX_BLOCK_COST_CLVM": 11000000000}) - nodes, wallets = await async_gen.__anext__() - full_node_1 = nodes[0] - server_1 = full_node_1.full_node.server - wallet_a = bt.get_pool_wallet_tool() - wallet_receiver = WalletTool(full_node_1.full_node.constants) - yield full_node_1, server_1, wallet_a, wallet_receiver - - async for _ in async_gen: - yield _ - - class TestPerformance: @pytest.mark.asyncio @pytest.mark.benchmark diff --git a/tests/core/full_node/test_transactions.py b/tests/core/full_node/test_transactions.py index e00dacd22a..b2c88a2a78 100644 --- a/tests/core/full_node/test_transactions.py +++ b/tests/core/full_node/test_transactions.py @@ -3,7 +3,6 @@ from secrets import token_bytes from typing import Optional import pytest -import pytest_asyncio from chia.consensus.block_record import BlockRecord from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward @@ -12,28 +11,9 @@ from chia.protocols import full_node_protocol from chia.simulator.simulator_protocol import FarmNewBlockProtocol from chia.types.peer_info import PeerInfo from chia.util.ints import uint16, uint32 -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert -@pytest_asyncio.fixture(scope="function") -async def wallet_node_sim_and_wallet(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def three_nodes_two_wallets(): - async for _ in setup_simulators_and_wallets(3, 2, {}): - yield _ - - class TestTransactions: @pytest.mark.asyncio async def test_wallet_coinbase(self, wallet_node_sim_and_wallet, self_hostname): diff --git a/tests/core/server/test_dos.py b/tests/core/server/test_dos.py index 9985e29993..de87635e35 100644 --- a/tests/core/server/test_dos.py +++ b/tests/core/server/test_dos.py @@ -3,7 +3,6 @@ import asyncio import logging import pytest -import pytest_asyncio from aiohttp import ClientSession, ClientTimeout, ServerDisconnectedError, WSCloseCode, WSMessage, WSMsgType from chia.full_node.full_node_api import FullNodeAPI @@ -15,9 +14,8 @@ from chia.server.rate_limits import RateLimiter from chia.server.server import ssl_context_for_client from chia.server.ws_connection import WSChiaConnection from chia.types.peer_info import PeerInfo -from chia.util.ints import uint16, uint64 from chia.util.errors import Err -from tests.setup_nodes import setup_simulators_and_wallets +from chia.util.ints import uint16, uint64 from tests.time_out_assert import time_out_assert log = logging.getLogger(__name__) @@ -33,12 +31,6 @@ async def get_block_path(full_node: FullNodeAPI): return blocks_list -@pytest_asyncio.fixture(scope="function") -async def setup_two_nodes_fixture(db_version): - async for _ in setup_simulators_and_wallets(2, 0, {}, db_version=db_version): - yield _ - - class FakeRateLimiter: def process_msg_and_check(self, msg): return True diff --git a/tests/core/ssl/test_ssl.py b/tests/core/ssl/test_ssl.py index 798df4c64c..24a20efcfc 100644 --- a/tests/core/ssl/test_ssl.py +++ b/tests/core/ssl/test_ssl.py @@ -10,15 +10,9 @@ from chia.server.server import ChiaServer, ssl_context_for_client from chia.server.ws_connection import WSChiaConnection from chia.ssl.create_ssl import generate_ca_signed_cert from chia.types.peer_info import PeerInfo -from tests.block_tools import test_constants from chia.util.ints import uint16 -from tests.setup_nodes import ( - setup_harvester_farmer, - setup_introducer, - setup_simulators_and_wallets, - setup_timelord, -) -from tests.util.socket import find_available_listen_port +from tests.block_tools import test_constants +from tests.setup_nodes import setup_harvester_farmer async def establish_connection(server: ChiaServer, self_hostname: str, ssl_context) -> bool: @@ -57,29 +51,6 @@ async def harvester_farmer(bt): yield _ -@pytest_asyncio.fixture(scope="function") -async def wallet_node_sim_and_wallet(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def introducer(bt): - introducer_port = find_available_listen_port("introducer") - async for _ in setup_introducer(bt, introducer_port): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def timelord(bt): - timelord_port = find_available_listen_port("timelord") - node_port = find_available_listen_port("node") - rpc_port = find_available_listen_port("rpc") - vdf_port = find_available_listen_port("vdf") - async for _ in setup_timelord(timelord_port, node_port, rpc_port, vdf_port, False, test_constants, bt): - yield _ - - class TestSSL: @pytest.mark.asyncio async def test_public_connections(self, wallet_node_sim_and_wallet, self_hostname): diff --git a/tests/core/test_daemon_rpc.py b/tests/core/test_daemon_rpc.py index f5100eed89..5cf5780eae 100644 --- a/tests/core/test_daemon_rpc.py +++ b/tests/core/test_daemon_rpc.py @@ -1,15 +1,7 @@ import pytest -import pytest_asyncio -from tests.setup_nodes import setup_daemon -from chia.daemon.client import connect_to_daemon from chia import __version__ - - -@pytest_asyncio.fixture(scope="function") -async def get_daemon(bt): - async for _ in setup_daemon(btools=bt): - yield _ +from chia.daemon.client import connect_to_daemon class TestDaemonRpc: diff --git a/tests/core/test_filter.py b/tests/core/test_filter.py index 3448b4b42e..db953e4bef 100644 --- a/tests/core/test_filter.py +++ b/tests/core/test_filter.py @@ -1,17 +1,8 @@ from typing import List import pytest -import pytest_asyncio from chiabip158 import PyBIP158 -from tests.setup_nodes import setup_simulators_and_wallets - - -@pytest_asyncio.fixture(scope="function") -async def wallet_and_node(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - class TestFilter: @pytest.mark.asyncio diff --git a/tests/core/test_full_node_rpc.py b/tests/core/test_full_node_rpc.py index ee6a58c30e..e2bff665c9 100644 --- a/tests/core/test_full_node_rpc.py +++ b/tests/core/test_full_node_rpc.py @@ -1,9 +1,7 @@ # flake8: noqa: F811, F401 -import logging from typing import List import pytest -import pytest_asyncio from blspy import AugSchemeMPL from chia.consensus.pot_iterations import is_overflow_block @@ -16,22 +14,16 @@ from chia.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtoco from chia.types.full_block import FullBlock from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_block import UnfinishedBlock -from tests.block_tools import get_signage_point from chia.util.hash import std_hash -from chia.util.ints import uint16, uint8 +from chia.util.ints import uint8 +from tests.block_tools import get_signage_point from tests.blockchain.blockchain_test_utils import _validate_and_add_block -from tests.wallet_tools import WalletTool from tests.connection_utils import connect_and_get_peer -from tests.setup_nodes import setup_simulators_and_wallets, test_constants +from tests.setup_nodes import test_constants from tests.time_out_assert import time_out_assert from tests.util.rpc import validate_get_routes from tests.util.socket import find_available_listen_port - - -@pytest_asyncio.fixture(scope="function") -async def two_nodes_sim_and_wallets(): - async for _ in setup_simulators_and_wallets(2, 0, {}): - yield _ +from tests.wallet_tools import WalletTool class TestRpc: diff --git a/tests/pools/test_pool_rpc.py b/tests/pools/test_pool_rpc.py index 20f627bc31..0a4d996859 100644 --- a/tests/pools/test_pool_rpc.py +++ b/tests/pools/test_pool_rpc.py @@ -91,12 +91,6 @@ async def wallet_is_synced(wallet_node: WalletNode, full_node_api): PREFARMED_BLOCKS = 4 -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - @pytest_asyncio.fixture(scope="function") async def one_wallet_node_and_rpc(bt, self_hostname): rmtree(get_pool_plot_dir(), ignore_errors=True) diff --git a/tests/wallet/cat_wallet/test_cat_lifecycle.py b/tests/wallet/cat_wallet/test_cat_lifecycle.py index b4bdf889b1..c56a6d95ab 100644 --- a/tests/wallet/cat_wallet/test_cat_lifecycle.py +++ b/tests/wallet/cat_wallet/test_cat_lifecycle.py @@ -1,49 +1,39 @@ -import pytest -import pytest_asyncio - from typing import List, Tuple, Optional, Dict + +import pytest from blspy import PrivateKey, AugSchemeMPL, G2Element from clvm.casts import int_to_bytes from chia.clvm.spend_sim import SpendSim, SimClient -from chia.types.blockchain_format.program import Program from chia.types.blockchain_format.coin import Coin +from chia.types.blockchain_format.program import Program from chia.types.blockchain_format.sized_bytes import bytes32 -from chia.types.spend_bundle import SpendBundle from chia.types.coin_spend import CoinSpend from chia.types.mempool_inclusion_status import MempoolInclusionStatus +from chia.types.spend_bundle import SpendBundle from chia.util.errors import Err from chia.util.ints import uint64 -from chia.wallet.lineage_proof import LineageProof from chia.wallet.cat_wallet.cat_utils import ( CAT_MOD, SpendableCAT, construct_cat_puzzle, unsigned_spend_bundle_for_spendable_cats, ) +from chia.wallet.lineage_proof import LineageProof from chia.wallet.puzzles.tails import ( GenesisById, GenesisByPuzhash, EverythingWithSig, DelegatedLimitations, ) - -from tests.clvm.test_puzzles import secret_exponent_for_index from tests.clvm.benchmark_costs import cost_of_spend_bundle +from tests.clvm.test_puzzles import secret_exponent_for_index acs = Program.to(1) acs_ph = acs.get_tree_hash() NO_LINEAGE_PROOF = LineageProof() -@pytest_asyncio.fixture(scope="function") -async def setup_sim(): - sim = await SpendSim.create() - sim_client = SimClient(sim) - await sim.farm_block() - return sim, sim_client - - async def do_spend( sim: SpendSim, sim_client: SimClient, diff --git a/tests/wallet/cat_wallet/test_cat_wallet.py b/tests/wallet/cat_wallet/test_cat_wallet.py index 808a76c529..a8c57100a8 100644 --- a/tests/wallet/cat_wallet/test_cat_wallet.py +++ b/tests/wallet/cat_wallet/test_cat_wallet.py @@ -2,7 +2,6 @@ import asyncio from typing import List import pytest -import pytest_asyncio from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward from chia.full_node.mempool_manager import MempoolManager @@ -11,15 +10,14 @@ from chia.types.blockchain_format.coin import Coin from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.peer_info import PeerInfo from chia.util.ints import uint16, uint32, uint64 -from chia.wallet.cat_wallet.cat_utils import construct_cat_puzzle -from chia.wallet.cat_wallet.cat_wallet import CATWallet from chia.wallet.cat_wallet.cat_constants import DEFAULT_CATS from chia.wallet.cat_wallet.cat_info import LegacyCATInfo +from chia.wallet.cat_wallet.cat_utils import construct_cat_puzzle +from chia.wallet.cat_wallet.cat_wallet import CATWallet from chia.wallet.puzzles.cat_loader import CAT_MOD from chia.wallet.transaction_record import TransactionRecord from chia.wallet.wallet_info import WalletInfo from tests.pools.test_pool_rpc import wallet_is_synced -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert @@ -30,24 +28,6 @@ async def tx_in_pool(mempool: MempoolManager, tx_id: bytes32): return True -@pytest_asyncio.fixture(scope="function") -async def wallet_node_sim_and_wallet(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def three_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 3, {}): - yield _ - - class TestCATWallet: @pytest.mark.parametrize( "trusted", diff --git a/tests/wallet/cat_wallet/test_offer_lifecycle.py b/tests/wallet/cat_wallet/test_offer_lifecycle.py index 7f1e9272e3..a2777376e8 100644 --- a/tests/wallet/cat_wallet/test_offer_lifecycle.py +++ b/tests/wallet/cat_wallet/test_offer_lifecycle.py @@ -1,17 +1,15 @@ -import pytest -import pytest_asyncio - from typing import Dict, Optional, List + +import pytest from blspy import G2Element -from chia.clvm.spend_sim import SpendSim, SimClient -from chia.types.blockchain_format.coin import Coin -from chia.types.blockchain_format.sized_bytes import bytes32 -from chia.types.blockchain_format.program import Program from chia.types.announcement import Announcement -from chia.types.spend_bundle import SpendBundle +from chia.types.blockchain_format.coin import Coin +from chia.types.blockchain_format.program import Program +from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.coin_spend import CoinSpend from chia.types.mempool_inclusion_status import MempoolInclusionStatus +from chia.types.spend_bundle import SpendBundle from chia.util.ints import uint64 from chia.wallet.cat_wallet.cat_utils import ( CAT_MOD, @@ -21,7 +19,6 @@ from chia.wallet.cat_wallet.cat_utils import ( ) from chia.wallet.payment import Payment from chia.wallet.trading.offer import Offer, NotarizedPayment - from tests.clvm.benchmark_costs import cost_of_spend_bundle acs = Program.to(1) @@ -41,14 +38,6 @@ def str_to_cat_hash(tail_str: str) -> bytes32: return construct_cat_puzzle(CAT_MOD, str_to_tail_hash(tail_str), acs).get_tree_hash() -@pytest_asyncio.fixture(scope="function") -async def setup_sim(): - sim = await SpendSim.create() - sim_client = SimClient(sim) - await sim.farm_block() - return sim, sim_client - - # This method takes a dictionary of strings mapping to amounts and generates the appropriate CAT/XCH coins async def generate_coins( sim, diff --git a/tests/wallet/cat_wallet/test_trades.py b/tests/wallet/cat_wallet/test_trades.py index 826cd786ed..2ac4701bb2 100644 --- a/tests/wallet/cat_wallet/test_trades.py +++ b/tests/wallet/cat_wallet/test_trades.py @@ -3,19 +3,15 @@ from secrets import token_bytes from typing import List import pytest -import pytest_asyncio from chia.full_node.mempool_manager import MempoolManager from chia.simulator.simulator_protocol import FarmNewBlockProtocol -from chia.types.peer_info import PeerInfo -from chia.util.ints import uint16, uint64 +from chia.util.ints import uint64 from chia.wallet.cat_wallet.cat_wallet import CATWallet from chia.wallet.trading.offer import Offer from chia.wallet.trading.trade_status import TradeStatus from chia.wallet.transaction_record import TransactionRecord from chia.wallet.util.transaction_type import TransactionType -from tests.pools.test_pool_rpc import wallet_is_synced -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert @@ -26,58 +22,9 @@ async def tx_in_pool(mempool: MempoolManager, tx_id): return True -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - buffer_blocks = 4 -@pytest_asyncio.fixture(scope="function") -async def wallets_prefarm(two_wallet_nodes, self_hostname, trusted): - """ - Sets up the node with 10 blocks, and returns a payer and payee wallet. - """ - farm_blocks = 10 - buffer = 4 - full_nodes, wallets = two_wallet_nodes - full_node_api = full_nodes[0] - full_node_server = full_node_api.server - wallet_node_0, wallet_server_0 = wallets[0] - wallet_node_1, wallet_server_1 = wallets[1] - wallet_0 = wallet_node_0.wallet_state_manager.main_wallet - wallet_1 = wallet_node_1.wallet_state_manager.main_wallet - - ph0 = await wallet_0.get_new_puzzlehash() - ph1 = await wallet_1.get_new_puzzlehash() - - if trusted: - wallet_node_0.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()} - wallet_node_1.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()} - else: - wallet_node_0.config["trusted_peers"] = {} - wallet_node_1.config["trusted_peers"] = {} - - await wallet_server_0.start_client(PeerInfo(self_hostname, uint16(full_node_server._port)), None) - await wallet_server_1.start_client(PeerInfo(self_hostname, uint16(full_node_server._port)), None) - - for i in range(0, farm_blocks): - await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph0)) - - for i in range(0, farm_blocks): - await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph1)) - - for i in range(0, buffer): - await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(token_bytes())) - - await time_out_assert(10, wallet_is_synced, True, wallet_node_0, full_node_api) - await time_out_assert(10, wallet_is_synced, True, wallet_node_1, full_node_api) - - return wallet_node_0, wallet_node_1, full_node_api - - @pytest.mark.parametrize( "trusted", [True, False], diff --git a/tests/wallet/did_wallet/test_did.py b/tests/wallet/did_wallet/test_did.py index 11b9bdd800..221a194583 100644 --- a/tests/wallet/did_wallet/test_did.py +++ b/tests/wallet/did_wallet/test_did.py @@ -1,43 +1,18 @@ import pytest -import pytest_asyncio -from chia.simulator.simulator_protocol import FarmNewBlockProtocol -from chia.types.peer_info import PeerInfo -from chia.util.ints import uint16, uint32, uint64 -from tests.setup_nodes import setup_simulators_and_wallets -from chia.wallet.did_wallet.did_wallet import DIDWallet -from chia.types.blockchain_format.program import Program from blspy import AugSchemeMPL -from chia.types.spend_bundle import SpendBundle + from chia.consensus.block_rewards import calculate_pool_reward, calculate_base_farmer_reward +from chia.simulator.simulator_protocol import FarmNewBlockProtocol +from chia.types.blockchain_format.program import Program +from chia.types.peer_info import PeerInfo +from chia.types.spend_bundle import SpendBundle +from chia.util.ints import uint16, uint32, uint64 +from chia.wallet.did_wallet.did_wallet import DIDWallet from tests.time_out_assert import time_out_assert, time_out_assert_not_none pytestmark = pytest.mark.skip("TODO: Fix tests") -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def three_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 3, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes_five_freeze(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def three_sim_two_wallets(): - async for _ in setup_simulators_and_wallets(3, 2, {}): - yield _ - - class TestDIDWallet: @pytest.mark.asyncio async def test_creation_from_backup_file(self, self_hostname, three_wallet_nodes): diff --git a/tests/wallet/did_wallet/test_did_rpc.py b/tests/wallet/did_wallet/test_did_rpc.py index f393c3164a..75f8cc1b4a 100644 --- a/tests/wallet/did_wallet/test_did_rpc.py +++ b/tests/wallet/did_wallet/test_did_rpc.py @@ -1,6 +1,6 @@ import logging + import pytest -import pytest_asyncio from chia.rpc.rpc_server import start_rpc_server from chia.rpc.wallet_rpc_api import WalletRpcApi @@ -8,24 +8,16 @@ from chia.rpc.wallet_rpc_client import WalletRpcClient from chia.simulator.simulator_protocol import FarmNewBlockProtocol from chia.types.peer_info import PeerInfo from chia.util.ints import uint16, uint64 -from chia.wallet.util.wallet_types import WalletType -from tests.setup_nodes import setup_simulators_and_wallets -from tests.time_out_assert import time_out_assert from chia.wallet.did_wallet.did_wallet import DIDWallet +from chia.wallet.util.wallet_types import WalletType +from tests.time_out_assert import time_out_assert from tests.util.socket import find_available_listen_port - log = logging.getLogger(__name__) pytestmark = pytest.mark.skip("TODO: Fix tests") -@pytest_asyncio.fixture(scope="function") -async def three_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 3, {}): - yield _ - - class TestDIDWallet: @pytest.mark.asyncio async def test_create_did(self, bt, three_wallet_nodes, self_hostname): diff --git a/tests/wallet/rl_wallet/test_rl_rpc.py b/tests/wallet/rl_wallet/test_rl_rpc.py index e387646e79..78a6f58da7 100644 --- a/tests/wallet/rl_wallet/test_rl_rpc.py +++ b/tests/wallet/rl_wallet/test_rl_rpc.py @@ -1,7 +1,6 @@ import asyncio import pytest -import pytest_asyncio from chia.rpc.wallet_rpc_api import WalletRpcApi from chia.simulator.simulator_protocol import FarmNewBlockProtocol @@ -13,7 +12,6 @@ from chia.util.bech32m import encode_puzzle_hash from chia.util.ints import uint16 from chia.wallet.transaction_record import TransactionRecord from chia.wallet.util.wallet_types import WalletType -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert from tests.wallet.sync.test_wallet_sync import wallet_height_at_least @@ -46,12 +44,6 @@ async def check_balance(api, wallet_id): return balance -@pytest_asyncio.fixture(scope="function") -async def three_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 3, {}): - yield _ - - class TestRLWallet: @pytest.mark.asyncio @pytest.mark.skip diff --git a/tests/wallet/rl_wallet/test_rl_wallet.py b/tests/wallet/rl_wallet/test_rl_wallet.py index cee43b28fc..ebf0ddd595 100644 --- a/tests/wallet/rl_wallet/test_rl_wallet.py +++ b/tests/wallet/rl_wallet/test_rl_wallet.py @@ -1,20 +1,12 @@ import pytest -import pytest_asyncio from chia.simulator.simulator_protocol import FarmNewBlockProtocol from chia.types.peer_info import PeerInfo from chia.util.ints import uint16, uint64 from chia.wallet.rl_wallet.rl_wallet import RLWallet -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - class TestCATWallet: @pytest.mark.asyncio @pytest.mark.skip diff --git a/tests/wallet/rpc/test_wallet_rpc.py b/tests/wallet/rpc/test_wallet_rpc.py index ee8ec4c855..f92570b31a 100644 --- a/tests/wallet/rpc/test_wallet_rpc.py +++ b/tests/wallet/rpc/test_wallet_rpc.py @@ -1,19 +1,13 @@ import asyncio +import logging +from operator import attrgetter from typing import Dict, Optional +import pytest from blspy import G2Element -from chia.types.coin_record import CoinRecord -from chia.types.coin_spend import CoinSpend -from chia.types.spend_bundle import SpendBundle -from chia.util.config import lock_and_load_config, save_config -from operator import attrgetter -import logging - -import pytest -import pytest_asyncio - from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward +from chia.consensus.coinbase import create_puzzlehash_for_pk from chia.rpc.full_node_rpc_api import FullNodeRpcApi from chia.rpc.full_node_rpc_client import FullNodeRpcClient from chia.rpc.rpc_server import start_rpc_server @@ -22,33 +16,29 @@ from chia.rpc.wallet_rpc_client import WalletRpcClient from chia.simulator.simulator_protocol import FarmNewBlockProtocol from chia.types.announcement import Announcement from chia.types.blockchain_format.program import Program +from chia.types.coin_record import CoinRecord +from chia.types.coin_spend import CoinSpend from chia.types.peer_info import PeerInfo +from chia.types.spend_bundle import SpendBundle from chia.util.bech32m import decode_puzzle_hash, encode_puzzle_hash -from chia.consensus.coinbase import create_puzzlehash_for_pk +from chia.util.config import lock_and_load_config, save_config from chia.util.hash import std_hash -from chia.wallet.derive_keys import master_sk_to_wallet_sk from chia.util.ints import uint16, uint32, uint64 from chia.wallet.cat_wallet.cat_constants import DEFAULT_CATS from chia.wallet.cat_wallet.cat_wallet import CATWallet +from chia.wallet.derive_keys import master_sk_to_wallet_sk from chia.wallet.trading.trade_status import TradeStatus from chia.wallet.transaction_record import TransactionRecord from chia.wallet.transaction_sorting import SortKey from chia.wallet.util.compute_memos import compute_memos from chia.wallet.util.wallet_types import WalletType from tests.pools.test_pool_rpc import wallet_is_synced -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert from tests.util.socket import find_available_listen_port log = logging.getLogger(__name__) -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - async def assert_wallet_types(client: WalletRpcClient, expected: Dict[WalletType, int]) -> None: for wallet_type in WalletType: wallets = await client.get_wallets(wallet_type) diff --git a/tests/wallet/simple_sync/test_simple_sync_protocol.py b/tests/wallet/simple_sync/test_simple_sync_protocol.py index 2e45359f57..bcbd59c5b7 100644 --- a/tests/wallet/simple_sync/test_simple_sync_protocol.py +++ b/tests/wallet/simple_sync/test_simple_sync_protocol.py @@ -3,15 +3,14 @@ import asyncio from typing import List, Optional import pytest -import pytest_asyncio from clvm.casts import int_to_bytes from colorlog import getLogger from chia.consensus.block_rewards import calculate_pool_reward, calculate_base_farmer_reward -from chia.protocols import wallet_protocol, full_node_protocol +from chia.protocols import wallet_protocol from chia.protocols.full_node_protocol import RespondTransaction from chia.protocols.protocol_message_types import ProtocolMessageTypes -from chia.protocols.wallet_protocol import RespondToCoinUpdates, CoinStateUpdate, RespondToPhUpdates, CoinState +from chia.protocols.wallet_protocol import RespondToCoinUpdates, CoinStateUpdate, RespondToPhUpdates from chia.server.outbound_message import NodeType from chia.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol from chia.types.blockchain_format.coin import Coin @@ -25,7 +24,6 @@ from chia.wallet.wallet import Wallet from chia.wallet.wallet_state_manager import WalletStateManager from tests.connection_utils import add_dummy_connection from tests.pools.test_pool_rpc import wallet_is_synced -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert from tests.wallet.cat_wallet.test_cat_wallet import tx_in_pool from tests.wallet_tools import WalletTool @@ -41,18 +39,6 @@ def wallet_height_at_least(wallet_node, h): log = getLogger(__name__) -@pytest_asyncio.fixture(scope="function") -async def wallet_node_simulator(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def wallet_two_node_simulator(): - async for _ in setup_simulators_and_wallets(2, 1, {}): - yield _ - - async def get_all_messages_in_queue(queue): all_messages = [] await asyncio.sleep(2) diff --git a/tests/wallet/sync/test_wallet_sync.py b/tests/wallet/sync/test_wallet_sync.py index e904a1a8d1..c98f78354c 100644 --- a/tests/wallet/sync/test_wallet_sync.py +++ b/tests/wallet/sync/test_wallet_sync.py @@ -2,7 +2,6 @@ import asyncio import pytest -import pytest_asyncio from colorlog import getLogger from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward @@ -13,7 +12,7 @@ from chia.util.ints import uint16, uint32 from chia.wallet.wallet_state_manager import WalletStateManager from tests.connection_utils import disconnect_all_and_reconnect from tests.pools.test_pool_rpc import wallet_is_synced -from tests.setup_nodes import setup_node_and_wallet, setup_simulators_and_wallets, test_constants +from tests.setup_nodes import test_constants from tests.time_out_assert import time_out_assert @@ -27,24 +26,6 @@ def wallet_height_at_least(wallet_node, h): log = getLogger(__name__) -@pytest_asyncio.fixture(scope="function") -async def wallet_node(self_hostname): - async for _ in setup_node_and_wallet(test_constants, self_hostname): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def wallet_node_simulator(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def wallet_node_starting_height(self_hostname): - async for _ in setup_node_and_wallet(test_constants, self_hostname, starting_height=100): - yield _ - - class TestWalletSync: @pytest.mark.parametrize( "trusted", diff --git a/tests/wallet/test_wallet.py b/tests/wallet/test_wallet.py index bd75233fcb..02467334ac 100644 --- a/tests/wallet/test_wallet.py +++ b/tests/wallet/test_wallet.py @@ -1,7 +1,8 @@ import asyncio -import pytest -import pytest_asyncio import time + +import pytest + from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward from chia.protocols.full_node_protocol import RespondBlock from chia.server.server import ChiaServer @@ -11,52 +12,15 @@ from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.peer_info import PeerInfo from chia.util.ints import uint16, uint32, uint64 from chia.wallet.derive_keys import master_sk_to_wallet_sk -from chia.wallet.util.transaction_type import TransactionType -from chia.wallet.util.compute_memos import compute_memos from chia.wallet.transaction_record import TransactionRecord +from chia.wallet.util.compute_memos import compute_memos +from chia.wallet.util.transaction_type import TransactionType from chia.wallet.wallet_node import WalletNode from chia.wallet.wallet_state_manager import WalletStateManager -from tests.setup_nodes import setup_simulators_and_wallets from tests.time_out_assert import time_out_assert, time_out_assert_not_none from tests.wallet.cat_wallet.test_cat_wallet import tx_in_pool -@pytest_asyncio.fixture(scope="function") -async def wallet_node(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def wallet_node_sim_and_wallet(): - async for _ in setup_simulators_and_wallets(1, 1, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def wallet_node_100_pk(): - async for _ in setup_simulators_and_wallets(1, 1, {}, initial_num_public_keys=100): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def two_wallet_nodes_five_freeze(): - async for _ in setup_simulators_and_wallets(1, 2, {}): - yield _ - - -@pytest_asyncio.fixture(scope="function") -async def three_sim_two_wallets(): - async for _ in setup_simulators_and_wallets(3, 2, {}): - yield _ - - class TestWalletSimulator: @pytest.mark.parametrize( "trusted", diff --git a/tests/wallet/test_wallet_blockchain.py b/tests/wallet/test_wallet_blockchain.py index 7b5c1e3b36..e5a84f5984 100644 --- a/tests/wallet/test_wallet_blockchain.py +++ b/tests/wallet/test_wallet_blockchain.py @@ -3,7 +3,6 @@ from pathlib import Path import aiosqlite import pytest -import pytest_asyncio from chia.consensus.blockchain import ReceiveBlockResult from chia.protocols import full_node_protocol @@ -13,13 +12,7 @@ from chia.util.db_wrapper import DBWrapper from chia.util.generator_tools import get_block_header from chia.wallet.key_val_store import KeyValStore from chia.wallet.wallet_blockchain import WalletBlockchain -from tests.setup_nodes import test_constants, setup_node_and_wallet - - -@pytest_asyncio.fixture(scope="function") -async def wallet_node(self_hostname): - async for _ in setup_node_and_wallet(test_constants, self_hostname): - yield _ +from tests.setup_nodes import test_constants class TestWalletBlockchain: