mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-08-24 10:05:29 -05:00
Ak.setup nodes (#10619)
* Remove unused test code * Centralize fixture uses of setup_n_nodes * Centralize fixure uses of setup_two_nodes * Break up setup_nodes into setup_services, for individial services, and setup_nodes, for initializing different simulator configurations * Sort imports
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from clvm.casts import int_to_bytes
|
||||
|
||||
from chia.protocols import full_node_protocol, wallet_protocol
|
||||
@@ -13,7 +12,7 @@ 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 setup_two_nodes, test_constants
|
||||
from tests.setup_nodes import test_constants
|
||||
from tests.util.generator_tools_testing import run_and_get_removals_and_additions
|
||||
|
||||
BURN_PUZZLE_HASH = b"0" * 32
|
||||
@@ -24,12 +23,6 @@ WALLET_A_PUZZLE_HASHES = [WALLET_A.get_new_puzzlehash() for _ in range(5)]
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def two_nodes(db_version, self_hostname):
|
||||
async for _ in setup_two_nodes(test_constants, db_version=db_version, self_hostname=self_hostname):
|
||||
yield _
|
||||
|
||||
|
||||
class TestBlockchainTransactions:
|
||||
@pytest.mark.asyncio
|
||||
async def test_basic_blockchain_tx(self, two_nodes, bt):
|
||||
|
||||
@@ -5,6 +5,8 @@ import pytest
|
||||
import pytest_asyncio
|
||||
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
|
||||
multiprocessing.set_start_method("spawn")
|
||||
|
||||
@@ -141,3 +143,33 @@ if os.getenv("_PYTEST_RAISE", "0") != "0":
|
||||
@pytest.hookimpl(tryfirst=True)
|
||||
def pytest_internalerror(excinfo):
|
||||
raise excinfo.value
|
||||
|
||||
|
||||
@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 two_nodes(db_version, self_hostname):
|
||||
async for _ in setup_two_nodes(test_constants, db_version=db_version, self_hostname=self_hostname):
|
||||
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):
|
||||
yield _
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def four_nodes(db_version, self_hostname):
|
||||
async for _ in setup_n_nodes(test_constants, 4, db_version=db_version, self_hostname=self_hostname):
|
||||
yield _
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
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 _
|
||||
|
||||
@@ -5,7 +5,6 @@ import time
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from chia.full_node.weight_proof import _validate_sub_epoch_summaries
|
||||
from chia.protocols import full_node_protocol
|
||||
@@ -15,37 +14,13 @@ from chia.types.peer_info import PeerInfo
|
||||
from chia.util.hash import std_hash
|
||||
from chia.util.ints import uint16
|
||||
from tests.core.node_height import node_height_exactly, node_height_between
|
||||
from tests.setup_nodes import setup_n_nodes, setup_two_nodes, test_constants
|
||||
from tests.setup_nodes import test_constants
|
||||
from tests.time_out_assert import time_out_assert
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def two_nodes(db_version, self_hostname):
|
||||
async for _ in setup_two_nodes(test_constants, db_version=db_version, self_hostname=self_hostname):
|
||||
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):
|
||||
yield _
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def four_nodes(db_version, self_hostname):
|
||||
async for _ in setup_n_nodes(test_constants, 4, db_version=db_version, self_hostname=self_hostname):
|
||||
yield _
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
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 _
|
||||
|
||||
|
||||
class TestFullSync:
|
||||
@pytest.mark.asyncio
|
||||
async def test_long_sync_from_zero(self, five_nodes, default_400_blocks, bt, self_hostname):
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
import time
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from chia.protocols import full_node_protocol
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.ints import uint16
|
||||
from tests.connection_utils import connect_and_get_peer
|
||||
from tests.setup_nodes import setup_two_nodes, test_constants
|
||||
from tests.time_out_assert import time_out_assert
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def two_nodes(db_version, self_hostname):
|
||||
async for _ in setup_two_nodes(test_constants, db_version=db_version, self_hostname=self_hostname):
|
||||
yield _
|
||||
|
||||
|
||||
class TestNodeLoad:
|
||||
@pytest.mark.asyncio
|
||||
async def test_blocks_load(self, bt, two_nodes, self_hostname):
|
||||
|
||||
+11
-258
@@ -1,26 +1,24 @@
|
||||
import logging
|
||||
import asyncio
|
||||
import signal
|
||||
import sqlite3
|
||||
|
||||
from secrets import token_bytes
|
||||
from typing import Dict, List, Optional, AsyncGenerator
|
||||
from typing import Dict, List
|
||||
|
||||
from chia.consensus.constants import ConsensusConstants
|
||||
from chia.daemon.server import WebSocketServer, create_server_for_daemon, daemon_launch_lock_path, singleton
|
||||
from chia.full_node.full_node_api import FullNodeAPI
|
||||
from chia.server.start_farmer import service_kwargs_for_farmer
|
||||
from chia.server.start_full_node import service_kwargs_for_full_node
|
||||
from chia.server.start_harvester import service_kwargs_for_harvester
|
||||
from chia.server.start_introducer import service_kwargs_for_introducer
|
||||
from chia.server.start_service import Service
|
||||
from chia.server.start_timelord import service_kwargs_for_timelord
|
||||
from chia.server.start_wallet import service_kwargs_for_wallet
|
||||
from chia.simulator.start_simulator import service_kwargs_for_full_node_simulator
|
||||
from chia.timelord.timelord_launcher import kill_processes, spawn_process
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.bech32m import encode_puzzle_hash
|
||||
from tests.block_tools import create_block_tools_async, test_constants, BlockTools
|
||||
from tests.setup_services import (
|
||||
setup_full_node,
|
||||
setup_harvester,
|
||||
setup_farmer,
|
||||
setup_introducer,
|
||||
setup_vdf_clients,
|
||||
setup_timelord,
|
||||
setup_vdf_client,
|
||||
setup_daemon,
|
||||
)
|
||||
from tests.util.keyring import TempKeyring
|
||||
from tests.util.socket import find_available_listen_port
|
||||
from chia.util.hash import std_hash
|
||||
@@ -49,93 +47,6 @@ async def _teardown_nodes(node_aiters: List) -> None:
|
||||
pass
|
||||
|
||||
|
||||
async def setup_daemon(btools: BlockTools) -> AsyncGenerator[WebSocketServer, None]:
|
||||
root_path = btools.root_path
|
||||
config = btools.config
|
||||
assert "daemon_port" in config
|
||||
lockfile = singleton(daemon_launch_lock_path(root_path))
|
||||
crt_path = root_path / config["daemon_ssl"]["private_crt"]
|
||||
key_path = root_path / config["daemon_ssl"]["private_key"]
|
||||
ca_crt_path = root_path / config["private_ssl_ca"]["crt"]
|
||||
ca_key_path = root_path / config["private_ssl_ca"]["key"]
|
||||
assert lockfile is not None
|
||||
create_server_for_daemon(btools.root_path)
|
||||
ws_server = WebSocketServer(root_path, ca_crt_path, ca_key_path, crt_path, key_path)
|
||||
await ws_server.start()
|
||||
|
||||
yield ws_server
|
||||
|
||||
await ws_server.stop()
|
||||
|
||||
|
||||
async def setup_full_node(
|
||||
consensus_constants: ConsensusConstants,
|
||||
db_name,
|
||||
self_hostname: str,
|
||||
port,
|
||||
rpc_port,
|
||||
local_bt: BlockTools,
|
||||
introducer_port=None,
|
||||
simulator=False,
|
||||
send_uncompact_interval=0,
|
||||
sanitize_weight_proof_only=False,
|
||||
connect_to_daemon=False,
|
||||
db_version=1,
|
||||
):
|
||||
db_path = local_bt.root_path / f"{db_name}"
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
if db_version > 1:
|
||||
with sqlite3.connect(db_path) as connection:
|
||||
connection.execute("CREATE TABLE database_version(version int)")
|
||||
connection.execute("INSERT INTO database_version VALUES (?)", (db_version,))
|
||||
connection.commit()
|
||||
|
||||
if connect_to_daemon:
|
||||
assert local_bt.config["daemon_port"] is not None
|
||||
config = local_bt.config["full_node"]
|
||||
|
||||
config["database_path"] = db_name
|
||||
config["send_uncompact_interval"] = send_uncompact_interval
|
||||
config["target_uncompact_proofs"] = 30
|
||||
config["peer_connect_interval"] = 50
|
||||
config["sanitize_weight_proof_only"] = sanitize_weight_proof_only
|
||||
if introducer_port is not None:
|
||||
config["introducer_peer"]["host"] = self_hostname
|
||||
config["introducer_peer"]["port"] = introducer_port
|
||||
else:
|
||||
config["introducer_peer"] = None
|
||||
config["dns_servers"] = []
|
||||
config["port"] = port
|
||||
config["rpc_port"] = rpc_port
|
||||
overrides = config["network_overrides"]["constants"][config["selected_network"]]
|
||||
updated_constants = consensus_constants.replace_str_to_bytes(**overrides)
|
||||
if simulator:
|
||||
kwargs = service_kwargs_for_full_node_simulator(local_bt.root_path, config, local_bt)
|
||||
else:
|
||||
kwargs = service_kwargs_for_full_node(local_bt.root_path, config, updated_constants)
|
||||
|
||||
kwargs.update(
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=connect_to_daemon,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._api
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
|
||||
# Note: convert these setup functions to fixtures, or push it one layer up,
|
||||
# keeping these usable independently?
|
||||
async def setup_wallet_node(
|
||||
self_hostname: str,
|
||||
port,
|
||||
@@ -206,164 +117,6 @@ async def setup_wallet_node(
|
||||
keychain.delete_all_keys()
|
||||
|
||||
|
||||
async def setup_harvester(
|
||||
b_tools: BlockTools,
|
||||
self_hostname: str,
|
||||
port,
|
||||
rpc_port,
|
||||
farmer_port,
|
||||
consensus_constants: ConsensusConstants,
|
||||
start_service: bool = True,
|
||||
):
|
||||
|
||||
config = b_tools.config["harvester"]
|
||||
config["port"] = port
|
||||
config["rpc_port"] = rpc_port
|
||||
kwargs = service_kwargs_for_harvester(b_tools.root_path, config, consensus_constants)
|
||||
kwargs.update(
|
||||
server_listen_ports=[port],
|
||||
advertised_port=port,
|
||||
connect_peers=[PeerInfo(self_hostname, farmer_port)],
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
if start_service:
|
||||
await service.start()
|
||||
|
||||
yield service
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
|
||||
|
||||
async def setup_farmer(
|
||||
b_tools: BlockTools,
|
||||
self_hostname: str,
|
||||
port,
|
||||
rpc_port,
|
||||
consensus_constants: ConsensusConstants,
|
||||
full_node_port: Optional[uint16] = None,
|
||||
start_service: bool = True,
|
||||
):
|
||||
config = b_tools.config["farmer"]
|
||||
config_pool = b_tools.config["pool"]
|
||||
|
||||
config["xch_target_address"] = encode_puzzle_hash(b_tools.farmer_ph, "xch")
|
||||
config["pool_public_keys"] = [bytes(pk).hex() for pk in b_tools.pool_pubkeys]
|
||||
config["port"] = port
|
||||
config["rpc_port"] = rpc_port
|
||||
config_pool["xch_target_address"] = encode_puzzle_hash(b_tools.pool_ph, "xch")
|
||||
|
||||
if full_node_port:
|
||||
config["full_node_peer"]["host"] = self_hostname
|
||||
config["full_node_peer"]["port"] = full_node_port
|
||||
else:
|
||||
del config["full_node_peer"]
|
||||
|
||||
kwargs = service_kwargs_for_farmer(
|
||||
b_tools.root_path, config, config_pool, consensus_constants, b_tools.local_keychain
|
||||
)
|
||||
kwargs.update(
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
if start_service:
|
||||
await service.start()
|
||||
|
||||
yield service
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
|
||||
|
||||
async def setup_introducer(bt: BlockTools, port):
|
||||
kwargs = service_kwargs_for_introducer(
|
||||
bt.root_path,
|
||||
bt.config["introducer"],
|
||||
)
|
||||
kwargs.update(
|
||||
advertised_port=port,
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._api, service._node.server
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
|
||||
|
||||
async def setup_vdf_client(bt: BlockTools, self_hostname: str, port):
|
||||
vdf_task_1 = asyncio.create_task(spawn_process(self_hostname, port, 1, bt.config.get("prefer_ipv6")))
|
||||
|
||||
def stop():
|
||||
asyncio.create_task(kill_processes())
|
||||
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, stop)
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGINT, stop)
|
||||
|
||||
yield vdf_task_1
|
||||
await kill_processes()
|
||||
|
||||
|
||||
async def setup_vdf_clients(bt: BlockTools, self_hostname: str, port):
|
||||
vdf_task_1 = asyncio.create_task(spawn_process(self_hostname, port, 1, bt.config.get("prefer_ipv6")))
|
||||
vdf_task_2 = asyncio.create_task(spawn_process(self_hostname, port, 2, bt.config.get("prefer_ipv6")))
|
||||
vdf_task_3 = asyncio.create_task(spawn_process(self_hostname, port, 3, bt.config.get("prefer_ipv6")))
|
||||
|
||||
def stop():
|
||||
asyncio.create_task(kill_processes())
|
||||
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, stop)
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGINT, stop)
|
||||
|
||||
yield vdf_task_1, vdf_task_2, vdf_task_3
|
||||
|
||||
await kill_processes()
|
||||
|
||||
|
||||
async def setup_timelord(
|
||||
port, full_node_port, rpc_port, vdf_port, sanitizer, consensus_constants: ConsensusConstants, b_tools: BlockTools
|
||||
):
|
||||
config = b_tools.config["timelord"]
|
||||
config["port"] = port
|
||||
config["full_node_peer"]["port"] = full_node_port
|
||||
config["bluebox_mode"] = sanitizer
|
||||
config["fast_algorithm"] = False
|
||||
config["vdf_server"]["port"] = vdf_port
|
||||
config["start_rpc_server"] = True
|
||||
config["rpc_port"] = rpc_port
|
||||
|
||||
kwargs = service_kwargs_for_timelord(b_tools.root_path, config, consensus_constants)
|
||||
kwargs.update(
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._api, service._node.server
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
|
||||
|
||||
async def setup_two_nodes(consensus_constants: ConsensusConstants, db_version: int, self_hostname: str):
|
||||
"""
|
||||
Setup and teardown of two full nodes, with blockchains and separate DBs.
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import signal
|
||||
import sqlite3
|
||||
from secrets import token_bytes
|
||||
from typing import AsyncGenerator, Optional
|
||||
|
||||
from chia.consensus.constants import ConsensusConstants
|
||||
from chia.daemon.server import WebSocketServer, create_server_for_daemon, daemon_launch_lock_path, singleton
|
||||
from chia.server.start_farmer import service_kwargs_for_farmer
|
||||
from chia.server.start_full_node import service_kwargs_for_full_node
|
||||
from chia.server.start_harvester import service_kwargs_for_harvester
|
||||
from chia.server.start_introducer import service_kwargs_for_introducer
|
||||
from chia.server.start_service import Service
|
||||
from chia.server.start_timelord import service_kwargs_for_timelord
|
||||
from chia.server.start_wallet import service_kwargs_for_wallet
|
||||
from chia.simulator.start_simulator import service_kwargs_for_full_node_simulator
|
||||
from chia.timelord.timelord_launcher import kill_processes, spawn_process
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.bech32m import encode_puzzle_hash
|
||||
from chia.util.ints import uint16
|
||||
from chia.util.keychain import bytes_to_mnemonic
|
||||
from tests.block_tools import BlockTools
|
||||
from tests.util.keyring import TempKeyring
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def setup_daemon(btools: BlockTools) -> AsyncGenerator[WebSocketServer, None]:
|
||||
root_path = btools.root_path
|
||||
config = btools.config
|
||||
assert "daemon_port" in config
|
||||
lockfile = singleton(daemon_launch_lock_path(root_path))
|
||||
crt_path = root_path / config["daemon_ssl"]["private_crt"]
|
||||
key_path = root_path / config["daemon_ssl"]["private_key"]
|
||||
ca_crt_path = root_path / config["private_ssl_ca"]["crt"]
|
||||
ca_key_path = root_path / config["private_ssl_ca"]["key"]
|
||||
assert lockfile is not None
|
||||
create_server_for_daemon(btools.root_path)
|
||||
ws_server = WebSocketServer(root_path, ca_crt_path, ca_key_path, crt_path, key_path)
|
||||
await ws_server.start()
|
||||
|
||||
yield ws_server
|
||||
|
||||
await ws_server.stop()
|
||||
|
||||
|
||||
async def setup_full_node(
|
||||
consensus_constants: ConsensusConstants,
|
||||
db_name,
|
||||
self_hostname: str,
|
||||
port,
|
||||
rpc_port,
|
||||
local_bt: BlockTools,
|
||||
introducer_port=None,
|
||||
simulator=False,
|
||||
send_uncompact_interval=0,
|
||||
sanitize_weight_proof_only=False,
|
||||
connect_to_daemon=False,
|
||||
db_version=1,
|
||||
):
|
||||
db_path = local_bt.root_path / f"{db_name}"
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
if db_version > 1:
|
||||
with sqlite3.connect(db_path) as connection:
|
||||
connection.execute("CREATE TABLE database_version(version int)")
|
||||
connection.execute("INSERT INTO database_version VALUES (?)", (db_version,))
|
||||
connection.commit()
|
||||
|
||||
if connect_to_daemon:
|
||||
assert local_bt.config["daemon_port"] is not None
|
||||
config = local_bt.config["full_node"]
|
||||
|
||||
config["database_path"] = db_name
|
||||
config["send_uncompact_interval"] = send_uncompact_interval
|
||||
config["target_uncompact_proofs"] = 30
|
||||
config["peer_connect_interval"] = 50
|
||||
config["sanitize_weight_proof_only"] = sanitize_weight_proof_only
|
||||
if introducer_port is not None:
|
||||
config["introducer_peer"]["host"] = self_hostname
|
||||
config["introducer_peer"]["port"] = introducer_port
|
||||
else:
|
||||
config["introducer_peer"] = None
|
||||
config["dns_servers"] = []
|
||||
config["port"] = port
|
||||
config["rpc_port"] = rpc_port
|
||||
overrides = config["network_overrides"]["constants"][config["selected_network"]]
|
||||
updated_constants = consensus_constants.replace_str_to_bytes(**overrides)
|
||||
if simulator:
|
||||
kwargs = service_kwargs_for_full_node_simulator(local_bt.root_path, config, local_bt)
|
||||
else:
|
||||
kwargs = service_kwargs_for_full_node(local_bt.root_path, config, updated_constants)
|
||||
|
||||
kwargs.update(
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=connect_to_daemon,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._api
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
|
||||
|
||||
# Note: convert these setup functions to fixtures, or push it one layer up,
|
||||
# keeping these usable independently?
|
||||
async def setup_wallet_node(
|
||||
self_hostname: str,
|
||||
port,
|
||||
rpc_port,
|
||||
consensus_constants: ConsensusConstants,
|
||||
local_bt: BlockTools,
|
||||
full_node_port=None,
|
||||
introducer_port=None,
|
||||
key_seed=None,
|
||||
starting_height=None,
|
||||
initial_num_public_keys=5,
|
||||
):
|
||||
with TempKeyring(populate=True) as keychain:
|
||||
config = local_bt.config["wallet"]
|
||||
config["port"] = port
|
||||
config["rpc_port"] = rpc_port
|
||||
if starting_height is not None:
|
||||
config["starting_height"] = starting_height
|
||||
config["initial_num_public_keys"] = initial_num_public_keys
|
||||
|
||||
entropy = token_bytes(32)
|
||||
if key_seed is None:
|
||||
key_seed = entropy
|
||||
keychain.add_private_key(bytes_to_mnemonic(key_seed), "")
|
||||
first_pk = keychain.get_first_public_key()
|
||||
assert first_pk is not None
|
||||
db_path_key_suffix = str(first_pk.get_fingerprint())
|
||||
db_name = f"test-wallet-db-{port}-KEY.sqlite"
|
||||
db_path_replaced: str = db_name.replace("KEY", db_path_key_suffix)
|
||||
db_path = local_bt.root_path / db_path_replaced
|
||||
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
config["database_path"] = str(db_name)
|
||||
config["testing"] = True
|
||||
|
||||
config["introducer_peer"]["host"] = self_hostname
|
||||
if introducer_port is not None:
|
||||
config["introducer_peer"]["port"] = introducer_port
|
||||
config["peer_connect_interval"] = 10
|
||||
else:
|
||||
config["introducer_peer"] = None
|
||||
|
||||
if full_node_port is not None:
|
||||
config["full_node_peer"] = {}
|
||||
config["full_node_peer"]["host"] = self_hostname
|
||||
config["full_node_peer"]["port"] = full_node_port
|
||||
else:
|
||||
del config["full_node_peer"]
|
||||
|
||||
kwargs = service_kwargs_for_wallet(local_bt.root_path, config, consensus_constants, keychain)
|
||||
kwargs.update(
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._node, service._node.server
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
if db_path.exists():
|
||||
db_path.unlink()
|
||||
keychain.delete_all_keys()
|
||||
|
||||
|
||||
async def setup_harvester(
|
||||
b_tools: BlockTools,
|
||||
self_hostname: str,
|
||||
port,
|
||||
rpc_port,
|
||||
farmer_port,
|
||||
consensus_constants: ConsensusConstants,
|
||||
start_service: bool = True,
|
||||
):
|
||||
|
||||
config = b_tools.config["harvester"]
|
||||
config["port"] = port
|
||||
config["rpc_port"] = rpc_port
|
||||
kwargs = service_kwargs_for_harvester(b_tools.root_path, config, consensus_constants)
|
||||
kwargs.update(
|
||||
server_listen_ports=[port],
|
||||
advertised_port=port,
|
||||
connect_peers=[PeerInfo(self_hostname, farmer_port)],
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
if start_service:
|
||||
await service.start()
|
||||
|
||||
yield service
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
|
||||
|
||||
async def setup_farmer(
|
||||
b_tools: BlockTools,
|
||||
self_hostname: str,
|
||||
port,
|
||||
rpc_port,
|
||||
consensus_constants: ConsensusConstants,
|
||||
full_node_port: Optional[uint16] = None,
|
||||
start_service: bool = True,
|
||||
):
|
||||
config = b_tools.config["farmer"]
|
||||
config_pool = b_tools.config["pool"]
|
||||
|
||||
config["xch_target_address"] = encode_puzzle_hash(b_tools.farmer_ph, "xch")
|
||||
config["pool_public_keys"] = [bytes(pk).hex() for pk in b_tools.pool_pubkeys]
|
||||
config["port"] = port
|
||||
config["rpc_port"] = rpc_port
|
||||
config_pool["xch_target_address"] = encode_puzzle_hash(b_tools.pool_ph, "xch")
|
||||
|
||||
if full_node_port:
|
||||
config["full_node_peer"]["host"] = self_hostname
|
||||
config["full_node_peer"]["port"] = full_node_port
|
||||
else:
|
||||
del config["full_node_peer"]
|
||||
|
||||
kwargs = service_kwargs_for_farmer(
|
||||
b_tools.root_path, config, config_pool, consensus_constants, b_tools.local_keychain
|
||||
)
|
||||
kwargs.update(
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
if start_service:
|
||||
await service.start()
|
||||
|
||||
yield service
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
|
||||
|
||||
async def setup_introducer(bt: BlockTools, port):
|
||||
kwargs = service_kwargs_for_introducer(
|
||||
bt.root_path,
|
||||
bt.config["introducer"],
|
||||
)
|
||||
kwargs.update(
|
||||
advertised_port=port,
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._api, service._node.server
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
|
||||
|
||||
async def setup_vdf_client(bt: BlockTools, self_hostname: str, port):
|
||||
vdf_task_1 = asyncio.create_task(spawn_process(self_hostname, port, 1, bt.config.get("prefer_ipv6")))
|
||||
|
||||
def stop():
|
||||
asyncio.create_task(kill_processes())
|
||||
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, stop)
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGINT, stop)
|
||||
|
||||
yield vdf_task_1
|
||||
await kill_processes()
|
||||
|
||||
|
||||
async def setup_vdf_clients(bt: BlockTools, self_hostname: str, port):
|
||||
vdf_task_1 = asyncio.create_task(spawn_process(self_hostname, port, 1, bt.config.get("prefer_ipv6")))
|
||||
vdf_task_2 = asyncio.create_task(spawn_process(self_hostname, port, 2, bt.config.get("prefer_ipv6")))
|
||||
vdf_task_3 = asyncio.create_task(spawn_process(self_hostname, port, 3, bt.config.get("prefer_ipv6")))
|
||||
|
||||
def stop():
|
||||
asyncio.create_task(kill_processes())
|
||||
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGTERM, stop)
|
||||
asyncio.get_running_loop().add_signal_handler(signal.SIGINT, stop)
|
||||
|
||||
yield vdf_task_1, vdf_task_2, vdf_task_3
|
||||
|
||||
await kill_processes()
|
||||
|
||||
|
||||
async def setup_timelord(
|
||||
port, full_node_port, rpc_port, vdf_port, sanitizer, consensus_constants: ConsensusConstants, b_tools: BlockTools
|
||||
):
|
||||
config = b_tools.config["timelord"]
|
||||
config["port"] = port
|
||||
config["full_node_peer"]["port"] = full_node_port
|
||||
config["bluebox_mode"] = sanitizer
|
||||
config["fast_algorithm"] = False
|
||||
config["vdf_server"]["port"] = vdf_port
|
||||
config["start_rpc_server"] = True
|
||||
config["rpc_port"] = rpc_port
|
||||
|
||||
kwargs = service_kwargs_for_timelord(b_tools.root_path, config, consensus_constants)
|
||||
kwargs.update(
|
||||
parse_cli_args=False,
|
||||
connect_to_daemon=False,
|
||||
service_name_prefix="test_",
|
||||
)
|
||||
|
||||
service = Service(**kwargs, handle_signals=False)
|
||||
|
||||
await service.start()
|
||||
|
||||
yield service._api, service._node.server
|
||||
|
||||
service.stop()
|
||||
await service.wait_closed()
|
||||
Reference in New Issue
Block a user