Skip to content

feat(cli): add localnet command for cluster lifecycle and faucet#666

Draft
ByteYue wants to merge 2 commits into
mainfrom
feat/cli-localnet
Draft

feat(cli): add localnet command for cluster lifecycle and faucet#666
ByteYue wants to merge 2 commits into
mainfrom
feat/cli-localnet

Conversation

@ByteYue
Copy link
Copy Markdown
Contributor

@ByteYue ByteYue commented Apr 19, 2026

Summary

gravity-cli localnet wraps the existing cluster/*.sh scripts and adds a one-shot faucet so the common dev-loop is accessible without bash invocations and remembered working directories:

  • localnet start [--nodes ...] [--wait-ready] — shells out to cluster/start.sh and (optionally) polls eth_blockNumber until the chain produces blocks.
  • localnet stop [--nodes ...] — shells out to cluster/stop.sh.
  • localnet faucet --to <addr> --amount <eth> — direct alloy transfer. Default funding key is the well-known anvil test account (matches cluster/faucet.sh); overridable via --from-key or GRAVITY_LOCALNET_FAUCET_KEY. Supports --wei for raw amounts and --output json.
  • localnet reset [--force] — stops the cluster and removes base_dir. Prompts before deleting paths outside /tmp unless --force is given.

Design notes

  • Cluster dir auto-discovery: walks up from CWD looking for cluster/start.sh (up to 6 levels). --cluster-dir / GRAVITY_CLUSTER_DIR override.
  • Config: defaults to <cluster_dir>/cluster.toml. We parse only cluster.base_dir and nodes[0].host/rpc_port — other keys are ignored.
  • Faucet key default comes from DEFAULT_ANVIL_FAUCET_KEY, the same anvil test account cluster/faucet.sh uses. Precedence: --from-key > GRAVITY_LOCALNET_FAUCET_KEY > default.
  • No new node-side endpoints; this is pure tooling.

Test plan

  • cargo build -p gravity_cli --profile quick-release clean
  • localnet stop from /tmp → clear "Could not locate cluster/start.sh" error
  • localnet stop from repo root → invokes stop.sh, reports no PID found
  • localnet faucet --to 0x... --amount 0.5 against running localnet → tx submitted, receipt received, exit 0
  • localnet faucet ... --wei 100 → treats amount as wei
  • GRAVITY_LOCALNET_FAUCET_KEY=<anvil_1> override → tx sent from anvil account 1
  • --output json localnet faucet → structured receipt
  • localnet reset --force with no cluster running → stops (no-op), reports base_dir missing, exits 0
  • Invalid --to → clear error, no tx submitted

ByteYue added 2 commits April 19, 2026 17:23
`gravity-cli localnet` wraps the existing `cluster/*.sh` scripts so the
common dev-loop tasks are one command away instead of bash invocations
with a remembered working directory:

  - `localnet start [--nodes ...] [--wait-ready]` shells out to
    `cluster/start.sh` and optionally polls `eth_blockNumber` until the
    chain is producing blocks.
  - `localnet stop [--nodes ...]` shells out to `cluster/stop.sh`.
  - `localnet faucet --to <addr> --amount <eth>` sends a direct transfer
    via alloy. Default funding key is the well-known anvil test account
    (matches `cluster/faucet.sh`); can be overridden with `--from-key`
    or `GRAVITY_LOCALNET_FAUCET_KEY`. Supports `--wei` for raw amounts
    and `--output json` for scripting.
  - `localnet reset [--force]` stops the cluster and removes the
    configured `base_dir`. Prompts before deleting paths outside /tmp
    unless `--force` is given.

The cluster scripts directory auto-discovers by walking up from CWD
looking for `cluster/start.sh` (up to 6 levels); `--cluster-dir` and
`GRAVITY_CLUSTER_DIR` override. `cluster.toml` is parsed for base_dir
and the first node's host/port so RPC URL derives automatically.
@ByteYue ByteYue marked this pull request as draft April 22, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant