mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-22 00:52:32 +03:00
051829d855
* use a conftest.py for shared blockchain fixtures
* try delaying import
* Revert "try delaying import"
This reverts commit f86cc305b1
.
* debug
* debug
* debug
* create the .chia dir for tests before creating a broken symlink
* go back
* delay more imports
* black
* provide an explanatory TODO
* Apply suggestions from code review
Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>
Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>
83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
import pytest
|
|
|
|
|
|
# TODO: tests.setup_nodes (which is also imported by tests.util.blockchain) creates a
|
|
# global BlockTools at tests.setup_nodes.bt. This results in an attempt to create
|
|
# the chia root directory which the build scripts symlink to a sometimes-not-there
|
|
# directory. When not there Python complains since, well, the symlink is a file
|
|
# not a directory and also not pointing to a directory. In those same cases,
|
|
# these fixtures are not used. It would be good to refactor that global state
|
|
# creation, including the filesystem modification, away from the import but
|
|
# that seems like a separate step and until then locating the imports in the
|
|
# fixtures avoids the issue.
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
async def empty_blockchain():
|
|
"""
|
|
Provides a list of 10 valid blocks, as well as a blockchain with 9 blocks added to it.
|
|
"""
|
|
from tests.util.blockchain import create_blockchain
|
|
from tests.setup_nodes import test_constants
|
|
|
|
bc1, connection, db_path = await create_blockchain(test_constants)
|
|
yield bc1
|
|
|
|
await connection.close()
|
|
bc1.shut_down()
|
|
db_path.unlink()
|
|
|
|
|
|
block_format_version = "rc4"
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
async def default_400_blocks():
|
|
from tests.util.blockchain import persistent_blocks
|
|
|
|
return persistent_blocks(400, f"test_blocks_400_{block_format_version}.db", seed=b"alternate2")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
async def default_1000_blocks():
|
|
from tests.util.blockchain import persistent_blocks
|
|
|
|
return persistent_blocks(1000, f"test_blocks_1000_{block_format_version}.db")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
async def pre_genesis_empty_slots_1000_blocks():
|
|
from tests.util.blockchain import persistent_blocks
|
|
|
|
return persistent_blocks(
|
|
1000, f"pre_genesis_empty_slots_1000_blocks{block_format_version}.db", seed=b"alternate2", empty_sub_slots=1
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
async def default_10000_blocks():
|
|
from tests.util.blockchain import persistent_blocks
|
|
|
|
return persistent_blocks(10000, f"test_blocks_10000_{block_format_version}.db")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
async def default_20000_blocks():
|
|
from tests.util.blockchain import persistent_blocks
|
|
|
|
return persistent_blocks(20000, f"test_blocks_20000_{block_format_version}.db")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
async def default_10000_blocks_compact():
|
|
from tests.util.blockchain import persistent_blocks
|
|
|
|
return persistent_blocks(
|
|
10000,
|
|
f"test_blocks_10000_compact_{block_format_version}.db",
|
|
normalized_to_identity_cc_eos=True,
|
|
normalized_to_identity_icc_eos=True,
|
|
normalized_to_identity_cc_ip=True,
|
|
normalized_to_identity_cc_sp=True,
|
|
)
|