diff --git a/tests/full_node/test_transactions.py b/tests/full_node/test_transactions.py index 6a37226c..736d2ab7 100644 --- a/tests/full_node/test_transactions.py +++ b/tests/full_node/test_transactions.py @@ -8,9 +8,7 @@ from src.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol from src.types.peer_info import PeerInfo from src.util.ints import uint16, uint32 from tests.setup_nodes import ( - setup_node_simulator_and_two_wallets, - setup_node_simulator_and_wallet, - setup_three_simulators_and_two_wallets, + setup_simulators_and_wallets ) from src.consensus.block_rewards import calculate_base_fee, calculate_block_reward @@ -24,19 +22,19 @@ def event_loop(): class TestTransactions: @pytest.fixture(scope="function") async def wallet_node(self): - async for _ in setup_node_simulator_and_wallet(): + async for _ in setup_simulators_and_wallets(1, 1, {}): yield _ @pytest.fixture(scope="function") async def two_wallet_nodes(self): - async for _ in setup_node_simulator_and_two_wallets( + async for _ in setup_simulators_and_wallets(1, 2, {"COINBASE_FREEZE_PERIOD": 0} ): yield _ @pytest.fixture(scope="function") async def three_nodes_two_wallets(self): - async for _ in setup_three_simulators_and_two_wallets( + async for _ in setup_simulators_and_wallets(3, 2, {"COINBASE_FREEZE_PERIOD": 0} ): yield _ @@ -44,7 +42,9 @@ class TestTransactions: @pytest.mark.asyncio async def test_wallet_coinbase(self, wallet_node): num_blocks = 10 - full_node_1, wallet_node, server_1, server_2 = wallet_node + full_nodes, wallets = wallet_node + full_node_1, server_1 = full_nodes[0] + wallet_node, server_2 = wallets[0] wallet = wallet_node.main_wallet ph = await wallet.get_new_puzzlehash() diff --git a/tests/setup_nodes.py b/tests/setup_nodes.py index 7363564e..3abd70bd 100644 --- a/tests/setup_nodes.py +++ b/tests/setup_nodes.py @@ -1,5 +1,5 @@ import signal -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Tuple, List from pathlib import Path import asyncio @@ -28,8 +28,7 @@ from src.farmer import Farmer from src.introducer import Introducer from src.timelord import Timelord from src.server.connection import PeerInfo -from src.util.ints import uint16 - +from src.util.ints import uint16, uint32 bt = BlockTools() @@ -316,24 +315,6 @@ async def setup_node_and_wallet(dic={}): pass -async def setup_node_simulator_and_wallet(dic={}): - node_iters = [ - setup_full_node_simulator("blockchain_test.db", 21234, dic=dic), - setup_wallet_node(21235, dic=dic), - ] - - full_node, s1 = await node_iters[0].__anext__() - wallet, s2 = await node_iters[1].__anext__() - - yield (full_node, wallet, s1, s2) - - for node_iter in node_iters: - try: - await node_iter.__anext__() - except StopAsyncIteration: - pass - - async def setup_node_and_two_wallets(dic={}): node_iters = [ setup_full_node("blockchain_test.db", 21234, dic=dic), @@ -354,45 +335,26 @@ async def setup_node_and_two_wallets(dic={}): pass -async def setup_node_simulator_and_two_wallets(dic={}): - node_iters = [ - setup_full_node_simulator("blockchain_test.db", 21234, dic=dic), - setup_wallet_node(21235, key_seed=b"Test node 1", dic=dic), - setup_wallet_node(21236, key_seed=b"Test node 2", dic=dic), - ] +async def setup_simulators_and_wallets(simulator_count: int, wallet_count: int, dic: Dict): + simulators: List[Tuple[FullNode, ChiaServer]] = [] + wallets = [] + node_iters = [] - full_node, s1 = await node_iters[0].__anext__() - wallet, s2 = await node_iters[1].__anext__() - wallet_2, s3 = await node_iters[2].__anext__() + for index in range(0, simulator_count): + db_name = f"blockchain_test{index}.db" + port = 50000 + index + sim = setup_full_node_simulator(db_name, port, dic=dic) + simulators.append(await sim.__anext__()) + node_iters.append(sim) - yield (full_node, wallet, wallet_2, s1, s2, s3) + for index in range(0, wallet_count): + seed = bytes(uint32(index)) + port = 55000 + index + wlt = setup_wallet_node(port, key_seed=seed, dic=dic) + wallets.append(await wlt.__anext__()) + node_iters.append(wlt) - for node_iter in node_iters: - try: - await node_iter.__anext__() - except StopAsyncIteration: - pass - - -async def setup_three_simulators_and_two_wallets(dic={}): - node_iters = [ - setup_full_node_simulator("blockchain_test0.db", 21234, dic=dic), - setup_full_node_simulator("blockchain_test1.db", 21235, dic=dic), - setup_full_node_simulator("blockchain_test2.db", 21236, dic=dic), - setup_wallet_node(21237, key_seed=b"Test node 1", dic=dic), - setup_wallet_node(21238, key_seed=b"Test node 2", dic=dic), - ] - - full_node0, s0 = await node_iters[0].__anext__() - full_node1, s1 = await node_iters[1].__anext__() - full_node2, s2 = await node_iters[2].__anext__() - - wallet_0, s3 = await node_iters[3].__anext__() - wallet_1, s4 = await node_iters[4].__anext__() - - full_nodes = [(full_node0, s0), (full_node1, s1), (full_node2, s2)] - wallets = [(wallet_0, s3), (wallet_1, s4)] - yield (full_nodes, wallets) + yield (simulators, wallets) for node_iter in node_iters: try: diff --git a/tests/test_filter.py b/tests/test_filter.py index eae54381..bd6768c5 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -5,13 +5,10 @@ import pytest from blspy import ExtendedPrivateKey from chiabip158 import PyBIP158 -from src.wallet.wallet_node import WalletNode from tests.setup_nodes import ( - setup_two_nodes, test_constants, bt, - setup_node_simulator_and_wallet, -) + setup_simulators_and_wallets) from src.util.config import load_config @@ -24,15 +21,14 @@ def event_loop(): class TestFilter: @pytest.fixture(scope="function") async def wallet_and_node(self): - async for _ in setup_node_simulator_and_wallet(): + async for _ in setup_simulators_and_wallets(1, 1, {}): yield _ @pytest.mark.asyncio async def test_basic_filter_test(self, wallet_and_node): - sk = bytes(ExtendedPrivateKey.from_seed(b"")).hex() - config = load_config("config.yaml", "wallet") - key_config = {"wallet_sk": sk} - full_node_1, wallet_node, server_1, server_2 = wallet_and_node + full_nodes, wallets = wallet_and_node + full_node_1, server_1 = full_nodes[0] + wallet_node, server_2 = wallets[0] wallet = wallet_node.main_wallet num_blocks = 2 diff --git a/tests/wallet/test_wallet.py b/tests/wallet/test_wallet.py index fbece970..aa6f4114 100644 --- a/tests/wallet/test_wallet.py +++ b/tests/wallet/test_wallet.py @@ -8,10 +8,7 @@ from src.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol from src.types.peer_info import PeerInfo from src.util.ints import uint16, uint32 from tests.setup_nodes import ( - setup_node_simulator_and_two_wallets, - setup_node_simulator_and_wallet, - setup_three_simulators_and_two_wallets, -) + setup_simulators_and_wallets) from src.consensus.block_rewards import calculate_base_fee, calculate_block_reward @@ -24,26 +21,26 @@ def event_loop(): class TestWalletSimulator: @pytest.fixture(scope="function") async def wallet_node(self): - async for _ in setup_node_simulator_and_wallet(): + async for _ in setup_simulators_and_wallets(1, 1, {}): yield _ @pytest.fixture(scope="function") async def two_wallet_nodes(self): - async for _ in setup_node_simulator_and_two_wallets( + async for _ in setup_simulators_and_wallets(1, 2, {"COINBASE_FREEZE_PERIOD": 0} ): yield _ @pytest.fixture(scope="function") async def two_wallet_nodes_five_freeze(self): - async for _ in setup_node_simulator_and_two_wallets( + async for _ in setup_simulators_and_wallets(1, 2, {"COINBASE_FREEZE_PERIOD": 5} ): yield _ @pytest.fixture(scope="function") async def three_sim_two_wallets(self): - async for _ in setup_three_simulators_and_two_wallets( + async for _ in setup_simulators_and_wallets(3, 2, {"COINBASE_FREEZE_PERIOD": 0} ): yield _ @@ -51,7 +48,9 @@ class TestWalletSimulator: @pytest.mark.asyncio async def test_wallet_coinbase(self, wallet_node): num_blocks = 10 - full_node_1, wallet_node, server_1, server_2 = wallet_node + full_nodes, wallets = wallet_node + full_node_1, server_1 = full_nodes[0] + wallet_node, server_2 = wallets[0] wallet = wallet_node.main_wallet ph = await wallet.get_new_puzzlehash() @@ -73,14 +72,10 @@ class TestWalletSimulator: @pytest.mark.asyncio async def test_wallet_make_transaction(self, two_wallet_nodes): num_blocks = 10 - ( - full_node_1, - wallet_node, - wallet_node_2, - server_1, - server_2, - server_3, - ) = two_wallet_nodes + full_nodes, wallets = two_wallet_nodes + full_node_1, server_1 = full_nodes[0] + wallet_node, server_2 = wallets[0] + wallet_node_2, server_3 = wallets[1] wallet = wallet_node.main_wallet ph = await wallet.get_new_puzzlehash() @@ -136,7 +131,9 @@ class TestWalletSimulator: @pytest.mark.asyncio async def test_wallet_coinbase_reorg(self, wallet_node): num_blocks = 10 - full_node_1, wallet_node, server_1, server_2 = wallet_node + full_nodes, wallets = wallet_node + full_node_1, server_1 = full_nodes[0] + wallet_node, server_2 = wallets[0] wallet = wallet_node.main_wallet ph = await wallet.get_new_puzzlehash() @@ -241,14 +238,10 @@ class TestWalletSimulator: @pytest.mark.asyncio async def test_wallet_make_transaction_hop(self, two_wallet_nodes_five_freeze): num_blocks = 10 - ( - full_node_0, - wallet_node_0, - wallet_node_1, - full_node_server, - wallet_0_server, - wallet_1_server, - ) = two_wallet_nodes_five_freeze + full_nodes, wallets = two_wallet_nodes_five_freeze + full_node_0, full_node_server = full_nodes[0] + wallet_node_0, wallet_0_server = wallets[0] + wallet_node_1, wallet_1_server = wallets[1] wallet_0 = wallet_node_0.main_wallet wallet_1 = wallet_node_1.main_wallet ph = await wallet_0.get_new_puzzlehash()