async def setup_simulators_and_wallets( simulator_count: int, wallet_count: int, dic: Dict, starting_height=None, key_seed=None, starting_port=50000 ): simulators: List[FullNodeAPI] = [] wallets = [] node_iters = [] consensus_constants = constants_for_dic(dic) for index in range(0, simulator_count): port = starting_port + index db_name = f"blockchain_test_{port}.db" sim = setup_full_node(consensus_constants, db_name, port, BlockTools(consensus_constants), simulator=True) simulators.append(await sim.__anext__()) node_iters.append(sim) for index in range(0, wallet_count): if key_seed is None: seed = std_hash(uint32(index)) else: seed = key_seed port = starting_port + 5000 + index wlt = setup_wallet_node( port, consensus_constants, BlockTools(consensus_constants), None, key_seed=seed, starting_height=starting_height, ) wallets.append(await wlt.__anext__()) node_iters.append(wlt) yield simulators, wallets await _teardown_nodes(node_iters)
def service_kwargs_for_full_node_simulator( root_path: Path, config: Dict, bt: BlockTools, ) -> Dict: mkdir(path_from_root(root_path, config["database_path"]).parent) overrides = config["network_overrides"][config["selected_network"]] consensus_constants = bt.constants updated_constants = consensus_constants.replace_str_to_bytes(**overrides) bt.constants = updated_constants node = FullNode( config, root_path=root_path, consensus_constants=updated_constants, name=SERVICE_NAME, ) peer_api = FullNodeSimulator(node, bt) kwargs = dict( root_path=root_path, node=node, peer_api=peer_api, node_type=NodeType.FULL_NODE, advertised_port=config["port"], service_name=SERVICE_NAME, server_listen_ports=[config["port"]], on_connect_callback=node.on_connect, rpc_info=(FullNodeRpcApi, config["rpc_port"]), network_id=updated_constants.GENESIS_CHALLENGE, ) return kwargs
async def setup_two_nodes(consensus_constants: ConsensusConstants): """ Setup and teardown of two full nodes, with blockchains and separate DBs. """ node_iters = [ setup_full_node( consensus_constants, "blockchain_test.db", 21234, BlockTools(constants=test_constants), simulator=False ), setup_full_node( consensus_constants, "blockchain_test_2.db", 21235, BlockTools(constants=test_constants), simulator=False ), ] fn1 = await node_iters[0].__anext__() fn2 = await node_iters[1].__anext__() yield fn1, fn2, fn1.full_node.server, fn2.full_node.server await _teardown_nodes(node_iters)
async def setup_node_and_wallet(consensus_constants: ConsensusConstants, starting_height=None, key_seed=None): btools = BlockTools(constants=test_constants) node_iters = [ setup_full_node(consensus_constants, "blockchain_test.db", 21234, btools, simulator=False), setup_wallet_node(21235, consensus_constants, btools, None, starting_height=starting_height, key_seed=key_seed), ] full_node_api = await node_iters[0].__anext__() wallet, s2 = await node_iters[1].__anext__() yield full_node_api, wallet, full_node_api.full_node.server, s2 await _teardown_nodes(node_iters)
import json import aiohttp import pytest from src.server.outbound_message import NodeType from src.server.server import ssl_context_for_server from src.types.peer_info import PeerInfo from src.util.block_tools import BlockTools from src.util.ints import uint16 from src.util.ws_message import create_payload from tests.core.node_height import node_height_at_least from tests.setup_nodes import setup_daemon, self_hostname, setup_full_system from tests.simulation.test_simulation import test_constants_modified from tests.time_out_assert import time_out_assert, time_out_assert_custom_interval b_tools = BlockTools(constants=test_constants_modified) b_tools_1 = BlockTools(constants=test_constants_modified) new_config = b_tools._config new_config["daemon_port"] = 55401 b_tools.change_config(new_config) class TestDaemon: @pytest.fixture(scope="function") async def get_daemon(self): async for _ in setup_daemon(btools=b_tools): yield _ @pytest.fixture(scope="function") async def simulation(self): async for _ in setup_full_system(b_tools_1.constants,
async def extra_node(self): b_tools = BlockTools(constants=test_constants_modified) async for _ in setup_full_node(test_constants_modified, "blockchain_test_3.db", 21240, b_tools): yield _