Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cardano_node_tests/testnet_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def main() -> int:
"Both address and skey file must be provided, or neither of them should be provided."
)
return 1
if not (args.address or os.environ.get("BOOTSTRAP_DIR")):
if not (args.address or testnet_cleanup.is_framework_testnet()):
LOGGER.error(
"The address must be provided, or `BOOTSTRAP_DIR` environment variable must be set."
"The address and skey file must be provided when running with non-framework testnet."
)
return 1

Expand Down
19 changes: 1 addition & 18 deletions cardano_node_tests/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,8 @@ def pytest_addoption(parser: tp.Any) -> None:
)


def _check_cardano_node_socket_path() -> None:
"""Check that `CARDANO_NODE_SOCKET_PATH` value is valid for use by testing framework."""
socket_env = os.environ.get("CARDANO_NODE_SOCKET_PATH")
if not socket_env:
msg = "The `CARDANO_NODE_SOCKET_PATH` env variable is not set."
raise RuntimeError(msg)

socket_path = pl.Path(socket_env).expanduser().resolve()
parts = socket_path.parts
if not parts[-2].startswith("state-cluster") or parts[-1] not in (
"bft1.socket",
"relay1.socket",
):
msg = "The `CARDANO_NODE_SOCKET_PATH` value is not valid for use by testing framework."
raise RuntimeError(msg)


def pytest_configure(config: tp.Any) -> None:
_check_cardano_node_socket_path()
helpers.check_cardano_node_socket_path()

# Don't bother collecting metadata if all tests are skipped
if config.getvalue("skipall"):
Expand Down
22 changes: 22 additions & 0 deletions cardano_node_tests/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,25 @@ def get_pool_param(key: str, *, pool_params: dict) -> tp.Any:
val = pool_params.get(old_key)

return val


def check_cardano_node_socket_path() -> None:
"""Check that `CARDANO_NODE_SOCKET_PATH` value is valid for use by testing framework."""
socket_env = os.environ.get("CARDANO_NODE_SOCKET_PATH")
if not socket_env:
msg = "The `CARDANO_NODE_SOCKET_PATH` env variable is not set."
raise ValueError(msg)

socket_path = pl.Path(socket_env).expanduser().resolve()
parts = socket_path.parts
if (
len(parts) < 2
or not parts[-2].startswith("state-cluster")
or parts[-1]
not in (
"bft1.socket",
"relay1.socket",
)
):
msg = "The `CARDANO_NODE_SOCKET_PATH` value is not valid for use by testing framework."
raise ValueError(msg)
21 changes: 18 additions & 3 deletions cardano_node_tests/utils/testnet_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ def create_addr_record(*, addr_file: pl.Path) -> clusterlib.AddressRecord:
skey_file = basedir / f"{f_name}.skey"

if not (vkey_file.exists() and skey_file.exists()):
msg = f"{addr_file}: keys not available"
raise ValueError(msg)
err = f"{addr_file}: keys not available"
raise ValueError(err)

addr_record = clusterlib.AddressRecord(
address=clusterlib.read_address_from_file(addr_file),
Expand Down Expand Up @@ -505,6 +505,15 @@ def _run(files: list[pl.Path], payment_addr: clusterlib.AddressRecord) -> None:
)


def is_framework_testnet() -> bool:
"""Determine if the testnet is a testnet started by the testing framework."""
try:
helpers.check_cardano_node_socket_path()
except ValueError:
return False
return True


def _get_faucet_payment_rec(
*, address: str = "", skey_file: clusterlib.FileType = ""
) -> clusterlib.AddressRecord:
Expand All @@ -523,11 +532,17 @@ def _get_faucet_payment_rec(
vkey_file=pl.Path("/nonexistent"), # We don't need this for faucet
skey_file=pl.Path(skey_file),
)
else:
elif is_framework_testnet():
# Try to infer the faucet address and keys from cluster env
cluster_env = cluster_nodes.get_cluster_env()
faucet_addr_file = cluster_env.state_dir / "shelley" / "faucet.addr"
if not faucet_addr_file.exists():
err = f"Faucet address file not found at '{faucet_addr_file}'."
raise FileNotFoundError(err)
faucet_payment = create_addr_record(addr_file=faucet_addr_file)
Comment thread
mkoura marked this conversation as resolved.
else:
err = "Faucet address and keys need to be provided for non-framework testnets."
raise RuntimeError(err)

return faucet_payment

Expand Down
Loading