Skip to content

feat(cli): Add nibid localnet script command#2616

Merged
Unique-Divine merged 1 commit into
mainfrom
ud/embed-localnet
Jun 22, 2026
Merged

feat(cli): Add nibid localnet script command#2616
Unique-Divine merged 1 commit into
mainfrom
ud/embed-localnet

Conversation

@Unique-Divine

@Unique-Divine Unique-Divine commented Jun 22, 2026

Copy link
Copy Markdown
Member

feat(cli): Add nibid localnet script command

Adds a nibid localnet CLI command that ships the localnet setup script inside the binary, so developers can start a single-node localnet without hunting for contrib/scripts/localnet.sh in the repo.

Key Changes

  • Add nibid localnet with a --script flag that prints an embedded bash script for piping to bash: nibid localnet --script | bash; without --script, the command shows help.
  • Embed a copy of contrib/scripts/localnet.sh tuned for CLI use: it always skips building (--no-build is accepted for compatibility) and runs the localnet by default.
  • Update contrib/scripts/localnet.sh to honor a BINARY env override and use basename for process detection and cleanup, so custom binary paths work reliably.

Appendix

Verification: go test ./cmd/nibid, go run ./cmd/nibid localnet, go run ./cmd/nibid localnet --script | bash -n, git diff --check.

@Unique-Divine
Unique-Divine requested a review from a team as a code owner June 22, 2026 09:24
@cursor

cursor Bot commented Jun 22, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
CLI and dev-only localnet scripting; no production node or consensus logic changes, though running the script resets local chain data and kills matching nibid processes.

Overview
Adds nibid localnet, which embeds the localnet bootstrap shell script and prints it when --script is set (intended flow: nibid localnet --script | bash). Without --script, the command shows help only.

The embedded script is a self-contained single-node localnet flow: reset chain data under ~/.nibid, init nibiru-localnet-0, turn on API/GRPC/JSON-RPC (including debug EVM API, indexer, swagger, CORS), fund genesis accounts, set the validator as sudo root, and seed canonical mainnet WNIBI in genesis (auth + EVM bytecode/storage via jq slurpfile), then gentx and nibid start. It always skips make install ( --no-build is compatibility-only) and defaults to running immediately.

contrib/scripts/localnet.sh is aligned slightly: BINARY can be overridden via env, and process stop uses basename "$BINARY" for pgrep/killall instead of a hardcoded name.

Reviewed by Cursor Bugbot for commit de55f7e. Configure here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new localnet command to nibid that embeds and outputs a shell script for running a single-node Nibiru localnet. The embedded script automates network initialization, configuration updates, and genesis setup, including seeding a canonical WNIBI contract. Review feedback suggests improving the script's robustness by adding early checks for required dependencies like jq and the nibid binary, as well as refactoring the macOS sed compatibility logic with a wrapper function to avoid creating unwanted backup files.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread cmd/nibid/localnet.sh
Comment on lines +169 to +172
SEDOPTION=""
if [[ "$OSTYPE" == "darwin"* ]]; then
SEDOPTION="''"
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

On macOS, setting SEDOPTION="''" and running sed -i $SEDOPTION passes literal single quotes as the backup extension to sed because the shell does not perform quote removal on expanded variables. This results in unwanted backup files like app.toml'' being created in the configuration directory.

A cleaner, more robust, and cross-platform way to handle this is to define a wrapper function for sed that automatically handles the -i flag differences between GNU and BSD/macOS sed without needing to modify any of the downstream sed invocations.

Suggested change
SEDOPTION=""
if [[ "$OSTYPE" == "darwin"* ]]; then
SEDOPTION="''"
fi
SEDOPTION=""
sed() {
if [[ "$1" == "-i" && "$OSTYPE" == "darwin"* ]]; then
shift
command sed -i '' "$@"
else
command sed "$@"
fi
}

Comment thread cmd/nibid/localnet.sh
echo "$1"
echo "${COLOR_RESET}"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the script more robust and user-friendly, we should add early checks for required dependencies:

  1. BINARY Check & Fallback: If nibid is not in the PATH but exists in the current working directory (e.g., a local build), automatically fall back to ./nibid. Otherwise, fail early with a clear error message.
  2. jq Check: Since jq is heavily used to manipulate the genesis file, the script will fail or corrupt files if it is missing. Checking for it upfront prevents partial execution failures.
Suggested change
if ! which_ok "$BINARY" >/dev/null; then
if [[ -f "./$(basename "$BINARY")" ]]; then
BINARY="./$(basename "$BINARY")"
else
echo_error "Error: $BINARY is not in PATH and no local binary found in the current directory."
exit 1
fi
fi
if ! which_ok jq >/dev/null; then
echo_error "Error: jq is required but not installed. Please install jq to run this script."
exit 1
fi

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.75000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/nibid/localnet.go 66.66% 4 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Unique-Divine
Unique-Divine merged commit 94fcc98 into main Jun 22, 2026
12 checks passed
@Unique-Divine
Unique-Divine deleted the ud/embed-localnet branch June 22, 2026 09:37
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