Skip to content

Commit

Permalink
extend tests being parametrised by soft-fork (#15977)
Browse files Browse the repository at this point in the history
* Make more tests parameterized by conftest.Mode (used for testing forks)

* limit test cases to save CI time

* bump timeouts

* run cat_wallet tests in parallel

* mypy type annotation fix in test_daemon.py

* Bump some wait_for_wallets_synced timeouts.

* remove unused test fixture

* address review comments

* bump datalayer timeout

* disable test_dusted_wallet() test

---------

Co-authored-by: Amine Khaldi <[email protected]>
  • Loading branch information
arvidn and AmineKhaldi authored Sep 8, 2023
1 parent 2c3f54a commit 952c2d3
Show file tree
Hide file tree
Showing 25 changed files with 258 additions and 251 deletions.
17 changes: 7 additions & 10 deletions chia/simulator/setup_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def setup_n_nodes(
async def setup_simulators_and_wallets(
simulator_count: int,
wallet_count: int,
dic: Dict[str, int],
consensus_constants: ConsensusConstants,
spam_filter_after_n_txs: int = 200,
xch_spam_amount: int = 1000000,
*,
Expand All @@ -156,7 +156,7 @@ async def setup_simulators_and_wallets(
with TempKeyring(populate=True) as keychain1, TempKeyring(populate=True) as keychain2:
res = await setup_simulators_and_wallets_inner(
db_version,
dic,
consensus_constants,
initial_num_public_keys,
key_seed,
keychain1,
Expand Down Expand Up @@ -186,7 +186,7 @@ async def setup_simulators_and_wallets(
async def setup_simulators_and_wallets_service(
simulator_count: int,
wallet_count: int,
dic: Dict[str, int],
consensus_constants: ConsensusConstants,
spam_filter_after_n_txs: int = 200,
xch_spam_amount: int = 1000000,
*,
Expand All @@ -201,7 +201,7 @@ async def setup_simulators_and_wallets_service(
with TempKeyring(populate=True) as keychain1, TempKeyring(populate=True) as keychain2:
res = await setup_simulators_and_wallets_inner(
db_version,
dic,
consensus_constants,
initial_num_public_keys,
key_seed,
keychain1,
Expand All @@ -222,7 +222,7 @@ async def setup_simulators_and_wallets_service(

async def setup_simulators_and_wallets_inner(
db_version: int,
dic: Dict[str, int],
consensus_constants: ConsensusConstants,
initial_num_public_keys: int,
key_seed: Optional[bytes32],
keychain1: Keychain,
Expand All @@ -245,13 +245,10 @@ async def setup_simulators_and_wallets_inner(
AsyncGenerator[Union[Service[FullNode, FullNodeSimulator], Service[WalletNode, WalletNodeAPI]], None]
] = []
bt_tools: List[BlockTools] = []
consensus_constants: ConsensusConstants = constants_for_dic(dic)
for index in range(0, simulator_count):
db_name = f"blockchain_test_{index}_sim_and_wallets.db"
bt_tools.append(
await create_block_tools_async(
consensus_constants, const_dict=dic, keychain=keychain1, config_overrides=config_overrides
)
await create_block_tools_async(consensus_constants, keychain=keychain1, config_overrides=config_overrides)
) # block tools modifies constants
sim = cast(
AsyncGenerator[Service[FullNode, FullNodeSimulator], None],
Expand All @@ -275,7 +272,7 @@ async def setup_simulators_and_wallets_inner(
seed = key_seed
if index > (len(bt_tools) - 1):
wallet_bt_tools = await create_block_tools_async(
consensus_constants, const_dict=dic, keychain=keychain2, config_overrides=config_overrides
consensus_constants, keychain=keychain2, config_overrides=config_overrides
) # block tools modifies constants
else:
wallet_bt_tools = bt_tools[index]
Expand Down
2 changes: 1 addition & 1 deletion tests/blockchain/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ async def test_pool_target_signature(self, empty_blockchain, bt):
reason="Skipped ConsensusMode.SOFT_FORK4 temporarily until adding more pool plots.",
)
@pytest.mark.asyncio
async def test_pool_target_contract(self, empty_blockchain, bt, consensus_mode: ConsensusMode):
async def test_pool_target_contract(self, empty_blockchain, bt):
# 20c invalid pool target with contract
blocks_initial = bt.get_consecutive_blocks(2)
await _validate_and_add_block(empty_blockchain, blocks_initial[0])
Expand Down
127 changes: 60 additions & 67 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,23 +356,23 @@ def pytest_collection_modifyitems(session, config: pytest.Config, items: List[py


@pytest_asyncio.fixture(scope="function")
async def node_with_params(request):
async def node_with_params(request, blockchain_constants: ConsensusConstants):
params = {}
if request:
params = request.param
async for (sims, wallets, bt) in setup_simulators_and_wallets(1, 0, {}, **params):
async for (sims, wallets, bt) in setup_simulators_and_wallets(1, 0, blockchain_constants, **params):
yield sims[0]


@pytest_asyncio.fixture(scope="function")
async def two_nodes(db_version: int, self_hostname, blockchain_constants):
async def two_nodes(db_version: int, self_hostname, blockchain_constants: ConsensusConstants):
async for _ in setup_two_nodes(blockchain_constants, db_version=db_version, self_hostname=self_hostname):
yield _


@pytest_asyncio.fixture(scope="function")
async def setup_two_nodes_fixture(db_version: int):
async for _ in setup_simulators_and_wallets(2, 0, {}, db_version=db_version):
async def setup_two_nodes_fixture(db_version: int, blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(2, 0, blockchain_constants, db_version=db_version):
yield _


Expand Down Expand Up @@ -413,7 +413,7 @@ async def wallet_nodes(blockchain_constants, consensus_mode):
async_gen = setup_simulators_and_wallets(
2,
1,
{"MEMPOOL_BLOCK_BUFFER": 1, "MAX_BLOCK_COST_CLVM": 400000000, "SOFT_FORK4_HEIGHT": constants.SOFT_FORK4_HEIGHT},
blockchain_constants.replace(MEMPOOL_BLOCK_BUFFER=1, MAX_BLOCK_COST_CLVM=400000000),
)
nodes, wallets, bt = await async_gen.__anext__()
full_node_1 = nodes[0]
Expand All @@ -429,14 +429,14 @@ async def wallet_nodes(blockchain_constants, consensus_mode):


@pytest_asyncio.fixture(scope="function")
async def setup_four_nodes(db_version):
async for _ in setup_simulators_and_wallets(4, 0, {}, db_version=db_version):
async def setup_four_nodes(db_version, blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(4, 0, blockchain_constants, 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, {}):
async def two_nodes_sim_and_wallets(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(2, 0, blockchain_constants):
yield _


Expand All @@ -455,104 +455,108 @@ async def two_nodes_sim_and_wallets():
],
)
async def two_nodes_sim_and_wallets_services(blockchain_constants, consensus_mode):
async for _ in setup_simulators_and_wallets_service(
2, 0, {"SOFT_FORK4_HEIGHT": blockchain_constants.SOFT_FORK4_HEIGHT}
):
async for _ in setup_simulators_and_wallets_service(2, 0, blockchain_constants):
yield _


@pytest_asyncio.fixture(scope="function")
async def one_wallet_and_one_simulator_services():
async for _ in setup_simulators_and_wallets_service(1, 1, {}):
async def one_wallet_and_one_simulator_services(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets_service(1, 1, blockchain_constants):
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):
async def wallet_node_100_pk(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(1, 1, blockchain_constants, initial_num_public_keys=100):
yield _


@pytest_asyncio.fixture(scope="function")
async def simulator_and_wallet() -> AsyncIterator[
Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]], BlockTools]
]:
async for _ in setup_simulators_and_wallets(simulator_count=1, wallet_count=1, dic={}):
async def simulator_and_wallet(
blockchain_constants: ConsensusConstants,
) -> AsyncIterator[Tuple[List[FullNodeSimulator], List[Tuple[WalletNode, ChiaServer]], BlockTools]]:
async for _ in setup_simulators_and_wallets(1, 1, blockchain_constants):
yield _


@pytest_asyncio.fixture(scope="function")
async def two_wallet_nodes(request):
async def two_wallet_nodes(request, blockchain_constants: ConsensusConstants):
params = {}
if request and request.param_index > 0:
params = request.param
async for _ in setup_simulators_and_wallets(1, 2, {}, **params):
async for _ in setup_simulators_and_wallets(1, 2, blockchain_constants, **params):
yield _


@pytest_asyncio.fixture(scope="function")
async def two_wallet_nodes_services() -> AsyncIterator[
async def two_wallet_nodes_services(
blockchain_constants: ConsensusConstants,
) -> AsyncIterator[
Tuple[List[Service[FullNode, FullNodeSimulator]], List[Service[WalletNode, WalletNodeAPI]], BlockTools]
]:
async for _ in setup_simulators_and_wallets_service(1, 2, {}):
async for _ in setup_simulators_and_wallets_service(1, 2, blockchain_constants):
yield _


@pytest_asyncio.fixture(scope="function")
async def two_wallet_nodes_custom_spam_filtering(spam_filter_after_n_txs, xch_spam_amount):
async for _ in setup_simulators_and_wallets(1, 2, {}, spam_filter_after_n_txs, xch_spam_amount):
async def two_wallet_nodes_custom_spam_filtering(
spam_filter_after_n_txs, xch_spam_amount, blockchain_constants: ConsensusConstants
):
async for _ in setup_simulators_and_wallets(1, 2, blockchain_constants, spam_filter_after_n_txs, xch_spam_amount):
yield _


@pytest_asyncio.fixture(scope="function")
async def three_sim_two_wallets():
async for _ in setup_simulators_and_wallets(3, 2, {}):
async def three_sim_two_wallets(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(3, 2, blockchain_constants):
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):
async def setup_two_nodes_and_wallet(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(2, 1, blockchain_constants, db_version=2):
yield _


@pytest_asyncio.fixture(scope="function")
async def setup_two_nodes_and_wallet_fast_retry():
async def setup_two_nodes_and_wallet_fast_retry(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(
1, 1, {}, config_overrides={"wallet.tx_resend_timeout_secs": 1}, db_version=2
1, 1, blockchain_constants, config_overrides={"wallet.tx_resend_timeout_secs": 1}, db_version=2
):
yield _


@pytest_asyncio.fixture(scope="function")
async def three_wallet_nodes():
async for _ in setup_simulators_and_wallets(1, 3, {}):
async def three_wallet_nodes(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(1, 3, blockchain_constants):
yield _


@pytest_asyncio.fixture(scope="function")
async def wallet_two_node_simulator():
async for _ in setup_simulators_and_wallets(2, 1, {}):
async def wallet_two_node_simulator(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(2, 1, blockchain_constants):
yield _


@pytest_asyncio.fixture(scope="function")
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):
async for _ in setup_simulators_and_wallets(2, 1, bt.constants, key_seed=key_seed):
yield _


@pytest_asyncio.fixture(scope="function")
async def two_nodes_two_wallets_with_same_keys(bt) -> AsyncIterator[SimulatorsAndWallets]:
key_seed = bt.farmer_master_sk_entropy
async for _ in setup_simulators_and_wallets(2, 2, {}, key_seed=key_seed):
async for _ in setup_simulators_and_wallets(2, 2, bt.constants, key_seed=key_seed):
yield _


@pytest_asyncio.fixture(scope="module")
async def wallet_nodes_perf():
async_gen = setup_simulators_and_wallets(1, 1, {"MEMPOOL_BLOCK_BUFFER": 1, "MAX_BLOCK_COST_CLVM": 11000000000})
async def wallet_nodes_perf(blockchain_constants: ConsensusConstants):
async_gen = setup_simulators_and_wallets(
1, 1, blockchain_constants, config_overrides={"MEMPOOL_BLOCK_BUFFER": 1, "MAX_BLOCK_COST_CLVM": 11000000000}
)
nodes, wallets, bt = await async_gen.__anext__()
full_node_1 = nodes[0]
server_1 = full_node_1.full_node.server
Expand All @@ -565,36 +569,24 @@ async def wallet_nodes_perf():


@pytest_asyncio.fixture(scope="function")
async def wallet_nodes_mainnet(db_version):
async_gen = setup_simulators_and_wallets(2, 1, {}, db_version=db_version)
nodes, wallets, bt = 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, bt

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, {}):
async def three_nodes_two_wallets(blockchain_constants: ConsensusConstants):
async for _ in setup_simulators_and_wallets(3, 2, blockchain_constants):
yield _


@pytest_asyncio.fixture(scope="function")
async def one_node() -> AsyncIterator[Tuple[List[Service], List[FullNodeSimulator], BlockTools]]:
async for _ in setup_simulators_and_wallets_service(1, 0, {}):
async def one_node(
blockchain_constants: ConsensusConstants,
) -> AsyncIterator[Tuple[List[Service], List[FullNodeSimulator], BlockTools]]:
async for _ in setup_simulators_and_wallets_service(1, 0, blockchain_constants):
yield _


@pytest_asyncio.fixture(scope="function")
async def one_node_one_block() -> AsyncIterator[Tuple[Union[FullNodeAPI, FullNodeSimulator], ChiaServer, BlockTools]]:
async_gen = setup_simulators_and_wallets(1, 0, {})
async def one_node_one_block(
blockchain_constants: ConsensusConstants,
) -> AsyncIterator[Tuple[Union[FullNodeAPI, FullNodeSimulator], ChiaServer, BlockTools]]:
async_gen = setup_simulators_and_wallets(1, 0, blockchain_constants)
nodes, _, bt = await async_gen.__anext__()
full_node_1 = nodes[0]
server_1 = full_node_1.full_node.server
Expand Down Expand Up @@ -623,8 +615,8 @@ async def one_node_one_block() -> AsyncIterator[Tuple[Union[FullNodeAPI, FullNod


@pytest_asyncio.fixture(scope="function")
async def two_nodes_one_block():
async_gen = setup_simulators_and_wallets(2, 0, {})
async def two_nodes_one_block(blockchain_constants: ConsensusConstants):
async_gen = setup_simulators_and_wallets(2, 0, blockchain_constants)
nodes, _, bt = await async_gen.__anext__()
full_node_1 = nodes[0]
full_node_2 = nodes[1]
Expand All @@ -638,7 +630,7 @@ async def two_nodes_one_block():
guarantee_transaction_block=True,
farmer_reward_puzzle_hash=reward_ph,
pool_reward_puzzle_hash=reward_ph,
genesis_timestamp=10000,
genesis_timestamp=uint64(10000),
time_per_block=10,
)
assert blocks[0].height == 0
Expand All @@ -657,6 +649,7 @@ async def two_nodes_one_block():
@pytest_asyncio.fixture(scope="function")
async def farmer_one_harvester_simulator_wallet(
tmp_path: Path,
blockchain_constants: ConsensusConstants,
) -> AsyncIterator[
Tuple[
Service[Harvester, HarvesterAPI],
Expand All @@ -666,7 +659,7 @@ async def farmer_one_harvester_simulator_wallet(
BlockTools,
]
]:
async for sim_and_wallet in setup_simulators_and_wallets_service(1, 1, {}):
async for sim_and_wallet in setup_simulators_and_wallets_service(1, 1, blockchain_constants):
nodes, wallets, bt = sim_and_wallet
async for farmer_harvester in setup_farmer_multi_harvester(bt, 1, tmp_path, bt.constants, start_services=True):
harvester_services, farmer_service, _ = farmer_harvester
Expand Down
1 change: 1 addition & 0 deletions tests/core/daemon/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

job_timeout = 50
install_timelord = True
checkout_blocks_and_plots = True
2 changes: 1 addition & 1 deletion tests/core/daemon/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ async def num_connections():
data = {"service": service_name}
payload = create_payload("register_service", data, service_name, "daemon")
await ws.send_str(payload)
message_queue = asyncio.Queue()
message_queue: asyncio.Queue = asyncio.Queue()

async def reader(ws, queue):
while True:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/data_layer/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

parallel = 4
job_timeout = 60
job_timeout = 80
checkout_blocks_and_plots = True
Loading

0 comments on commit 952c2d3

Please sign in to comment.