Skip to content
Snippets Groups Projects
Commit 28cdc9e4 authored by Krzysztof Mochocki's avatar Krzysztof Mochocki
Browse files

Use AlternateChainSpecs class in node definition

parent a91ca3f3
No related branches found
No related tags found
1 merge request!197Summary MR for !194 and !192
......@@ -28,6 +28,7 @@ class AlternateChainSpecs(BaseModel):
initial_vesting: InitialVesting | None = None
init_witnesses: list[str] | None = None
hive_owner_update_limit: int | None = None
generate_missed_block_operations: bool | None = None
def export_to_file(self, output_dir: Path | None = None) -> Path:
if output_dir is None:
......
......@@ -30,6 +30,7 @@ if TYPE_CHECKING:
from helpy._interfaces.url import P2PUrl, WsUrl
from schemas.apis.network_node_api.response_schemas import SetAllowedPeers
from test_tools.__private.alternate_chain_specs import AlternateChainSpecs
from test_tools.__private.user_handles.handles.network_handle import NetworkHandle
from test_tools.__private.user_handles.handles.node_handles.node_handle_base import NodeHandleBase as NodeHandle
from test_tools.__private.wallet import Wallet
......@@ -55,6 +56,7 @@ class Node(BaseNode, ScopedObject):
self.__process = Process(self.directory, self.__executable, self.logger)
self.__notifications = self.__create_notifications_server()
self.__cleanup_policy: CleanupPolicy | None = None
self.__alternate_chain_specs: AlternateChainSpecs | None = None
self.config = create_default_config()
......@@ -80,6 +82,10 @@ class Node(BaseNode, ScopedObject):
return all(conditions)
@property
def alternate_chain_specs(self) -> AlternateChainSpecs | None:
return self.__alternate_chain_specs
@property
def block_log(self) -> BlockLog:
return BlockLog(self.directory / "blockchain" / "block_log")
......@@ -237,7 +243,7 @@ class Node(BaseNode, ScopedObject):
self.logger.remove(self.__notification_sink_id)
self.__notification_sink_id = None
def run( # noqa: C901 PLR0912
def run( # noqa: C901, PLR0912
self,
*,
load_snapshot_from: str | Path | Snapshot | None = None,
......@@ -250,6 +256,7 @@ class Node(BaseNode, ScopedObject):
environment_variables: dict[str, str] | None = None,
timeout: float = DEFAULT_WAIT_FOR_LIVE_TIMEOUT,
time_offset: str | None = None,
alternate_chain_specs: AlternateChainSpecs | None = None,
) -> None:
"""
Runs node.
......@@ -290,6 +297,12 @@ class Node(BaseNode, ScopedObject):
additional_arguments.append(f"--stop-at-block={stop_at_block}")
if exit_at_block is not None:
additional_arguments.append(f"--exit-at-block={exit_at_block}")
if alternate_chain_specs is not None or self.alternate_chain_specs is not None:
if alternate_chain_specs is not None: # write or override
self.__alternate_chain_specs = alternate_chain_specs
if self.__alternate_chain_specs is not None:
destination = self.__alternate_chain_specs.export_to_file(self.directory).absolute().as_posix()
additional_arguments.append(f"--alternate-chain-spec={destination}")
if replay_from is not None:
self.__handle_replay(replay_from, additional_arguments)
log_message += ", replaying"
......@@ -466,11 +479,20 @@ class Node(BaseNode, ScopedObject):
"""Override this method to hook just after handling the final cleanup."""
def restart(
self, wait_for_live: bool = True, timeout: float = DEFAULT_WAIT_FOR_LIVE_TIMEOUT, time_offset: str | None = None
self,
wait_for_live: bool = True,
timeout: float = DEFAULT_WAIT_FOR_LIVE_TIMEOUT,
time_offset: str | None = None,
alternate_chain_specs: AlternateChainSpecs | None = None,
) -> None:
self.__close_wallets()
self.close()
self.run(wait_for_live=wait_for_live, timeout=timeout, time_offset=time_offset)
self.run(
wait_for_live=wait_for_live,
timeout=timeout,
time_offset=time_offset,
alternate_chain_specs=alternate_chain_specs,
)
self.__run_wallets()
def __remove_files(self) -> None:
......
......@@ -11,6 +11,7 @@ if TYPE_CHECKING:
from pathlib import Path
from helpy._interfaces.url import HttpUrl, P2PUrl, WsUrl
from test_tools.__private.alternate_chain_specs import AlternateChainSpecs
from test_tools.__private.block_log import BlockLog
from test_tools.__private.constants import CleanupPolicy
from test_tools.__private.node_config import NodeConfig
......@@ -87,6 +88,7 @@ class RunnableNodeHandle(NodeHandleBase):
environment_variables: dict[str, str] | None = None,
timeout: float = DEFAULT_WAIT_FOR_LIVE_TIMEOUT,
time_offset: str | None = None,
alternate_chain_specs: AlternateChainSpecs | None = None,
) -> None:
"""
Starts node synchronously. By default, program execution is blocked until node enters live mode (see `wait_for_live` parameter for details).
......@@ -122,6 +124,10 @@ class RunnableNodeHandle(NodeHandleBase):
absolutely, relatively and speed up or slow down clock. Value passed in `time_offset` is written to
`FAKETIME` environment variable. For details and examples see libfaketime official documentation:
https://github.com/wolfcw/libfaketime.
:param alternate_chain_specs:
Allows to change few properties of blockchain so it acts for example faster in certain ways to reduce duration
of tests. If it is used once it is cached and will be used after restart and future runs for this
instance of hived, even if it's not passed directly.
"""
return self.__implementation.run(
load_snapshot_from=load_snapshot_from,
......@@ -134,6 +140,7 @@ class RunnableNodeHandle(NodeHandleBase):
environment_variables=environment_variables,
timeout=timeout,
time_offset=time_offset,
alternate_chain_specs=alternate_chain_specs,
)
def restart(
......@@ -209,3 +216,8 @@ class RunnableNodeHandle(NodeHandleBase):
values like 0.0.0.0 address or 0 port, special values are replaced with actually selected by node.
"""
return self.__implementation.get_p2p_endpoint()
@property
def alternate_chain_specs(self) -> AlternateChainSpecs | None:
"""Returns chain spec that is currently used by this node. If none is used, None will be returned."""
return self.__implementation.alternate_chain_specs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment