Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Include additional flags to ape networks run #2482

Merged
merged 7 commits into from
Jan 31, 2025
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
2 changes: 2 additions & 0 deletions docs/userguides/networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ To use a different network, such as `hardhat` or Anvil nodes, use the `--network
ape networks run --network ethereum:local:foundry
```

To configure the network's block time, use the `--block-time` option.

## Provider Interaction

Once you are connected to a network, you now have access to a `.provider`.
Expand Down
1 change: 0 additions & 1 deletion src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,6 @@ def block_time(self) -> int:
mainnet:
block_time: 15
"""

return self.config.get("block_time", 0)

@property
Expand Down
9 changes: 8 additions & 1 deletion src/ape_networks/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def make_sub_tree(data: dict, create_tree: Callable) -> Tree:
@cli.command(short_help="Start a node process")
@ape_cli_context()
@network_option(default="ethereum:local:node")
def run(cli_ctx, provider):
@click.option("--block-time", default=None, type=int, help="Block time in seconds")
def run(cli_ctx, provider, block_time):
"""
Start a subprocess node as if running independently
and stream stdout and stderr.
Expand All @@ -128,13 +129,18 @@ def run(cli_ctx, provider):
elif provider.is_connected:
cli_ctx.abort("Process already running.")

# Set block time if provided
if block_time is not None:
provider.provider_settings.update({"block_time": block_time})

# Start showing process logs.
original_level = cli_ctx.logger.level
original_format = cli_ctx.logger.fmt
cli_ctx.logger.set_level(LogLevel.DEBUG)

# Change format to exclude log level (since it is always just DEBUG)
cli_ctx.logger.format(fmt="%(message)s")

try:
_run(cli_ctx, provider)
finally:
Expand All @@ -143,6 +149,7 @@ def run(cli_ctx, provider):


def _run(cli_ctx, provider: "SubprocessProvider"):

provider.connect()
if process := provider.process:
try:
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/cli/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ def test_run_custom_network(ape_cli, runner):
assert expected in result.output


@run_once
def test_run_block_time(ape_cli, runner):
cmd = (
"networks",
"run",
"--network",
"ethereum:local:test",
"--block-time",
"10",
)
result = runner.invoke(ape_cli, cmd)
expected = "`ape networks run` requires a provider that manages a process, not 'test'"
assert result.exit_code != 0
assert expected in result.output


@geth_process_test
@skip_projects_except("geth")
def test_run_already_running(networks_runner, integ_project, geth_provider):
Expand Down
Loading