From 2c84c98898947483d1fd253427cb42e802efc453 Mon Sep 17 00:00:00 2001 From: gloskull Date: Fri, 17 Jul 2026 18:44:43 +0100 Subject: [PATCH 1/2] Add local developer onboarding script --- .gitignore | 5 +- CONTRIBUTING.md | 5 +- README.md | 13 +++ meter-simulator/scripts/setup.sh | 0 scripts/onboard.sh | 151 +++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 2 deletions(-) mode change 100644 => 100755 meter-simulator/scripts/setup.sh create mode 100755 scripts/onboard.sh diff --git a/.gitignore b/.gitignore index 1754383..fa5db87 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ target AGENTS.md .agent/ agents/ -issue.md \ No newline at end of file +issue.md + +# JavaScript dependencies +node_modules/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index afb7b91..6e5930d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -154,12 +154,15 @@ make test ## 🚀 Contribution Workflow -### 1. Fork and Clone +### 1. Fork, Clone, and Onboard ```bash git clone https://github.com/your-username/Utility-contracts.git cd Utility-contracts +./scripts/onboard.sh ``` +Use `./scripts/onboard.sh --check-only` in CI-like environments where you only want prerequisite validation and do not want dependency installation. The script checks the Rust/Soroban-oriented toolchain, installs the `wasm32-unknown-unknown` target when needed, prepares JavaScript workspaces, and reports follow-up validation commands. + ### 2. Create Feature Branch ```bash git checkout -b feature/hardware-meter-optimization diff --git a/README.md b/README.md index 2a092ec..6f504cb 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,19 @@ Verified via 15 property tests with 100+ randomized cases each, covering pause/r ## Development +### One-command local onboarding + +Run the repository onboarding script before your first local build. It validates Git, ripgrep, Rust/Cargo, rustup, the WASM target, Node.js, and npm; installs npm dependencies for the JavaScript workspaces unless skipped; and prints the recommended validation commands. + +```bash +./scripts/onboard.sh + +# Validate prerequisites without installing dependencies +./scripts/onboard.sh --check-only +``` + +### Manual build and test commands + ```bash # Build cd contracts && cargo build --target wasm32-unknown-unknown --release diff --git a/meter-simulator/scripts/setup.sh b/meter-simulator/scripts/setup.sh old mode 100644 new mode 100755 diff --git a/scripts/onboard.sh b/scripts/onboard.sh new file mode 100755 index 0000000..a958139 --- /dev/null +++ b/scripts/onboard.sh @@ -0,0 +1,151 @@ +#!/usr/bin/env bash +# Developer onboarding script for Utility-contracts local development. +# It verifies required tools, installs safe local dependencies, and prints next steps. + +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +CHECK_ONLY=false +SKIP_NPM=false +SKIP_RUST_TARGET=false + +usage() { + cat <&2; usage; exit 2 ;; + esac + shift +done + +info() { printf 'â„šī¸ %s\n' "$*"; } +success() { printf '✅ %s\n' "$*"; } +warn() { printf 'âš ī¸ %s\n' "$*"; } +fail() { printf '❌ %s\n' "$*" >&2; } + +require_command() { + local cmd="$1" + local hint="$2" + if command -v "$cmd" >/dev/null 2>&1; then + success "Found $cmd ($(command -v "$cmd"))" + else + fail "Missing $cmd. $hint" + return 1 + fi +} + +version_ge() { + local current="$1" + local required="$2" + [[ "$(printf '%s\n' "$required" "$current" | sort -V | head -n1)" == "$required" ]] +} + +check_node_version() { + require_command node "Install Node.js 16 or newer." || return 1 + local node_version + node_version="$(node --version | sed 's/^v//')" + if version_ge "$node_version" "16.0.0"; then + success "Node.js $node_version satisfies >=16.0.0" + else + fail "Node.js $node_version is too old; install Node.js 16 or newer." + return 1 + fi +} + +check_rust_version() { + require_command rustc "Install Rust via https://rustup.rs/." || return 1 + require_command cargo "Install Cargo via https://rustup.rs/." || return 1 + local rust_version + rust_version="$(rustc --version | awk '{print $2}')" + if version_ge "$rust_version" "1.70.0"; then + success "Rust $rust_version satisfies >=1.70.0" + else + fail "Rust $rust_version is too old; install Rust 1.70 or newer." + return 1 + fi +} + +install_rust_target() { + if rustup target list --installed | rg -q '^wasm32-unknown-unknown$'; then + success "Rust WASM target is installed" + elif [[ "$CHECK_ONLY" == true || "$SKIP_RUST_TARGET" == true ]]; then + warn "Rust WASM target wasm32-unknown-unknown is not installed" + else + info "Installing Rust WASM target wasm32-unknown-unknown" + rustup target add wasm32-unknown-unknown + fi +} + +install_npm_workspace() { + local workspace="$1" + local package_json="$ROOT_DIR/$workspace/package.json" + [[ -f "$package_json" ]] || return 0 + + if [[ "$CHECK_ONLY" == true || "$SKIP_NPM" == true ]]; then + if [[ -d "$ROOT_DIR/$workspace/node_modules" ]]; then + success "$workspace dependencies are installed" + else + warn "$workspace dependencies are not installed" + fi + return 0 + fi + + info "Installing npm dependencies in $workspace" + (cd "$ROOT_DIR/$workspace" && npm install) +} + +create_env_file() { + local workspace="$1" + local example="$ROOT_DIR/$workspace/.env.example" + local env_file="$ROOT_DIR/$workspace/.env" + [[ -f "$example" ]] || return 0 + if [[ -f "$env_file" ]]; then + success "$workspace/.env already exists" + elif [[ "$CHECK_ONLY" == true ]]; then + warn "$workspace/.env is missing; copy from .env.example before running services" + else + cp "$example" "$env_file" + success "Created $workspace/.env from .env.example" + fi +} + +main() { + cd "$ROOT_DIR" + info "Starting Utility-contracts local onboarding from $ROOT_DIR" + + require_command git "Install Git from https://git-scm.com/." + require_command rg "Install ripgrep for fast repository searches." + check_rust_version + require_command rustup "Install rustup from https://rustup.rs/." + install_rust_target + check_node_version + require_command npm "Install npm with Node.js." + + install_npm_workspace meter-simulator + install_npm_workspace usage-dashboard + create_env_file meter-simulator + chmod +x scripts/onboard.sh meter-simulator/scripts/setup.sh scripts/deploy.sh 2>/dev/null || true + + info "Recommended validation commands:" + printf ' cargo fmt --all -- --check\n' + printf ' cargo test\n' + printf ' (cd meter-simulator && npm test)\n' + + success "Local onboarding completed" +} + +main "$@" From e31517d6d12f25074defb638d6e10d5a95eadfd2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 17 Jul 2026 18:01:16 +0000 Subject: [PATCH 2/2] Add developer onboarding script and fix insurance pool demo test - Implement `./scripts/onboard.sh` to check system requirements, configure .env files, and install JS/Rust targets and packages. - Update README.md and CONTRIBUTING.md to include onboarding instructions. - Add node_modules to .gitignore. - Fix insurance_pool_demo.rs claim processing bug so that newly onboarded devs can run the example tests immediately and successfully. Co-authored-by: gloskull <189399494+gloskull@users.noreply.github.com> --- .gitignore | 5 +- CONTRIBUTING.md | 5 +- README.md | 13 +++ examples/insurance_pool_demo.rs | 5 +- meter-simulator/scripts/setup.sh | 0 scripts/onboard.sh | 151 +++++++++++++++++++++++++++++++ 6 files changed, 175 insertions(+), 4 deletions(-) mode change 100644 => 100755 meter-simulator/scripts/setup.sh create mode 100755 scripts/onboard.sh diff --git a/.gitignore b/.gitignore index 1754383..fa5db87 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ target AGENTS.md .agent/ agents/ -issue.md \ No newline at end of file +issue.md + +# JavaScript dependencies +node_modules/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index afb7b91..6e5930d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -154,12 +154,15 @@ make test ## 🚀 Contribution Workflow -### 1. Fork and Clone +### 1. Fork, Clone, and Onboard ```bash git clone https://github.com/your-username/Utility-contracts.git cd Utility-contracts +./scripts/onboard.sh ``` +Use `./scripts/onboard.sh --check-only` in CI-like environments where you only want prerequisite validation and do not want dependency installation. The script checks the Rust/Soroban-oriented toolchain, installs the `wasm32-unknown-unknown` target when needed, prepares JavaScript workspaces, and reports follow-up validation commands. + ### 2. Create Feature Branch ```bash git checkout -b feature/hardware-meter-optimization diff --git a/README.md b/README.md index 2a092ec..6f504cb 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,19 @@ Verified via 15 property tests with 100+ randomized cases each, covering pause/r ## Development +### One-command local onboarding + +Run the repository onboarding script before your first local build. It validates Git, ripgrep, Rust/Cargo, rustup, the WASM target, Node.js, and npm; installs npm dependencies for the JavaScript workspaces unless skipped; and prints the recommended validation commands. + +```bash +./scripts/onboard.sh + +# Validate prerequisites without installing dependencies +./scripts/onboard.sh --check-only +``` + +### Manual build and test commands + ```bash # Build cd contracts && cargo build --target wasm32-unknown-unknown --release diff --git a/examples/insurance_pool_demo.rs b/examples/insurance_pool_demo.rs index 24d7f0e..afbcf37 100644 --- a/examples/insurance_pool_demo.rs +++ b/examples/insurance_pool_demo.rs @@ -135,14 +135,15 @@ impl InsurancePoolDemo { claimant: claimant.clone(), amount, auto_approved, - is_processed: auto_approved, + is_processed: false, // Start as false so process_claim can transition it }; + self.claims.insert(claim_id, claim); + if auto_approved { self.process_claim(claim_id)?; } - self.claims.insert(claim_id, claim); Ok(claim_id) } diff --git a/meter-simulator/scripts/setup.sh b/meter-simulator/scripts/setup.sh old mode 100644 new mode 100755 diff --git a/scripts/onboard.sh b/scripts/onboard.sh new file mode 100755 index 0000000..a958139 --- /dev/null +++ b/scripts/onboard.sh @@ -0,0 +1,151 @@ +#!/usr/bin/env bash +# Developer onboarding script for Utility-contracts local development. +# It verifies required tools, installs safe local dependencies, and prints next steps. + +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +CHECK_ONLY=false +SKIP_NPM=false +SKIP_RUST_TARGET=false + +usage() { + cat <&2; usage; exit 2 ;; + esac + shift +done + +info() { printf 'â„šī¸ %s\n' "$*"; } +success() { printf '✅ %s\n' "$*"; } +warn() { printf 'âš ī¸ %s\n' "$*"; } +fail() { printf '❌ %s\n' "$*" >&2; } + +require_command() { + local cmd="$1" + local hint="$2" + if command -v "$cmd" >/dev/null 2>&1; then + success "Found $cmd ($(command -v "$cmd"))" + else + fail "Missing $cmd. $hint" + return 1 + fi +} + +version_ge() { + local current="$1" + local required="$2" + [[ "$(printf '%s\n' "$required" "$current" | sort -V | head -n1)" == "$required" ]] +} + +check_node_version() { + require_command node "Install Node.js 16 or newer." || return 1 + local node_version + node_version="$(node --version | sed 's/^v//')" + if version_ge "$node_version" "16.0.0"; then + success "Node.js $node_version satisfies >=16.0.0" + else + fail "Node.js $node_version is too old; install Node.js 16 or newer." + return 1 + fi +} + +check_rust_version() { + require_command rustc "Install Rust via https://rustup.rs/." || return 1 + require_command cargo "Install Cargo via https://rustup.rs/." || return 1 + local rust_version + rust_version="$(rustc --version | awk '{print $2}')" + if version_ge "$rust_version" "1.70.0"; then + success "Rust $rust_version satisfies >=1.70.0" + else + fail "Rust $rust_version is too old; install Rust 1.70 or newer." + return 1 + fi +} + +install_rust_target() { + if rustup target list --installed | rg -q '^wasm32-unknown-unknown$'; then + success "Rust WASM target is installed" + elif [[ "$CHECK_ONLY" == true || "$SKIP_RUST_TARGET" == true ]]; then + warn "Rust WASM target wasm32-unknown-unknown is not installed" + else + info "Installing Rust WASM target wasm32-unknown-unknown" + rustup target add wasm32-unknown-unknown + fi +} + +install_npm_workspace() { + local workspace="$1" + local package_json="$ROOT_DIR/$workspace/package.json" + [[ -f "$package_json" ]] || return 0 + + if [[ "$CHECK_ONLY" == true || "$SKIP_NPM" == true ]]; then + if [[ -d "$ROOT_DIR/$workspace/node_modules" ]]; then + success "$workspace dependencies are installed" + else + warn "$workspace dependencies are not installed" + fi + return 0 + fi + + info "Installing npm dependencies in $workspace" + (cd "$ROOT_DIR/$workspace" && npm install) +} + +create_env_file() { + local workspace="$1" + local example="$ROOT_DIR/$workspace/.env.example" + local env_file="$ROOT_DIR/$workspace/.env" + [[ -f "$example" ]] || return 0 + if [[ -f "$env_file" ]]; then + success "$workspace/.env already exists" + elif [[ "$CHECK_ONLY" == true ]]; then + warn "$workspace/.env is missing; copy from .env.example before running services" + else + cp "$example" "$env_file" + success "Created $workspace/.env from .env.example" + fi +} + +main() { + cd "$ROOT_DIR" + info "Starting Utility-contracts local onboarding from $ROOT_DIR" + + require_command git "Install Git from https://git-scm.com/." + require_command rg "Install ripgrep for fast repository searches." + check_rust_version + require_command rustup "Install rustup from https://rustup.rs/." + install_rust_target + check_node_version + require_command npm "Install npm with Node.js." + + install_npm_workspace meter-simulator + install_npm_workspace usage-dashboard + create_env_file meter-simulator + chmod +x scripts/onboard.sh meter-simulator/scripts/setup.sh scripts/deploy.sh 2>/dev/null || true + + info "Recommended validation commands:" + printf ' cargo fmt --all -- --check\n' + printf ' cargo test\n' + printf ' (cd meter-simulator && npm test)\n' + + success "Local onboarding completed" +} + +main "$@"