Skip to content

Commit 17c3751

Browse files
committed
Update env
1 parent 3806999 commit 17c3751

File tree

1 file changed

+148
-43
lines changed

1 file changed

+148
-43
lines changed

scripts/node-env.sh

Lines changed: 148 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ fi
2222
# Polkadot SDK directory path (can be overridden by environment variable)
2323
POLKADOT_SDK_DIR="${POLKADOT_SDK_DIR:-$HOME/polkadot-sdk}"
2424

25+
# Define the revive-differential-tests directory path (can be overridden by environment variable)
26+
RETESTER_DIR="${RETESTER_DIR:-$HOME/github/revive-differential-tests}"
27+
2528
# Sets environment variables for Hardhat to use the built binaries
2629
# Usage: set_hardhat_env [release|debug]
2730
# Examples:
@@ -357,7 +360,7 @@ function eth-rpc() {
357360

358361
# Default NODE_RPC_URL if not provided
359362
if [ -z "$NODE_RPC_URL" ]; then
360-
NODE_RPC_URL="wss://localhost:9944"
363+
NODE_RPC_URL="ws://localhost:9944"
361364
fi
362365

363366
# Kill any existing mitmproxy instances and start new one
@@ -422,7 +425,7 @@ function eth-rpc() {
422425

423426
# Default NODE_RPC_URL if not provided
424427
if [ -z "$NODE_RPC_URL" ]; then
425-
NODE_RPC_URL="wss://westend-asset-hub-rpc.polkadot.io"
428+
NODE_RPC_URL="ws://localhost:9944"
426429
fi
427430

428431
# Build and execute command with optional output redirection
@@ -476,7 +479,7 @@ function eth-rpc() {
476479

477480
# Default NODE_RPC_URL if not provided
478481
if [ -z "$NODE_RPC_URL" ]; then
479-
NODE_RPC_URL="wss://westend-asset-hub-rpc.polkadot.io"
482+
NODE_RPC_URL="ws://localhost:9944"
480483
fi
481484

482485
# Build and execute command with optional output redirection
@@ -596,9 +599,6 @@ function retester_test() {
596599
return 1
597600
fi
598601

599-
# Define the revive-differential-tests directory path (can be overridden by environment variable)
600-
RETESTER_DIR="${RETESTER_DIR:-$HOME/github/revive-differential-tests}"
601-
602602
# Check if directory exists
603603
if [ ! -d "$RETESTER_DIR" ]; then
604604
echo "Error: revive-differential-tests directory does not exist at $RETESTER_DIR"
@@ -898,61 +898,166 @@ function passet() {
898898

899899
# Runs geth (Ethereum node) in development mode
900900
# Useful for testing contracts against standard Ethereum
901-
# Usage: geth-dev [port]
901+
# Usage: geth-dev [proxy|run] [--retester] [--port <port>]
902902
# Examples:
903-
# geth-dev - Use default port 8545
904-
# geth-dev 8546 - Use custom port 8546
903+
# geth-dev - Use default run mode on port 8545
904+
# geth-dev run --port 8546 - Run on custom port 8546
905+
# geth-dev proxy - Run with mitmproxy (8545->8546)
906+
# geth-dev proxy --port 9000 - Run with mitmproxy (9000->9001)
907+
# geth-dev --retester - Use retester genesis spec
908+
# geth-dev proxy --retester - Use proxy with retester genesis spec
905909
function geth-dev() {
906-
# Parse port argument with default
907-
port="${1:-8545}"
908-
909-
# Rename tmux window if running in tmux
910-
if [ -n "$TMUX" ]; then
911-
tmux rename-window "geth"
910+
# Parse arguments
911+
local mode="run"
912+
local port="8545"
913+
local retester_flag="false"
914+
915+
# Check if first arg is mode
916+
if [[ "$1" =~ ^(proxy|run)$ ]]; then
917+
mode="$1"
918+
shift
912919
fi
913920

914-
# Start geth in development mode with HTTP RPC enabled
915-
geth --http --http.api web3,eth,txpool,miner,debug,net --http.port "$port" --dev
916-
}
921+
# Parse remaining arguments
922+
while [[ $# -gt 0 ]]; do
923+
case "$1" in
924+
--retester)
925+
retester_flag="true"
926+
shift
927+
;;
928+
--port)
929+
if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then
930+
port="$2"
931+
shift 2
932+
else
933+
echo "Error: --port requires a numeric argument"
934+
return 1
935+
fi
936+
;;
937+
*)
938+
echo "Unknown argument: $1"
939+
return 1
940+
;;
941+
esac
942+
done
917943

918-
# Runs geth (Ethereum node) with mitmproxy for traffic inspection
919-
# Useful for debugging Ethereum RPC calls during development
920-
# Usage: geth-proxy [proxy_port] [server_port]
921-
# Examples:
922-
# geth-proxy - Use default ports (8546->8547)
923-
# geth-proxy 8545 8546 - Listen on 8545, proxy to geth on 8546
924-
function geth-proxy() {
925-
# Parse port arguments with defaults
926-
proxy_port="${1:-8546}"
927-
server_port="${2:-8547}"
928-
929-
# Kill any existing mitmproxy instances
930-
pkill -f mitmproxy
944+
# Helper function to generate genesis spec
945+
generate_genesis_spec() {
946+
local geth_spec_path="$HOME/.revive/geth_spec.json"
947+
948+
if [ ! -f "$geth_spec_path" ]; then
949+
# Check if retester directory exists
950+
if [ ! -d "$RETESTER_DIR" ]; then
951+
echo "Error: RETESTER_DIR does not exist at $RETESTER_DIR"
952+
echo "Please clone the repository: git clone https://github.com/paritytech/revive-differential-tests.git $RETESTER_DIR"
953+
return 1
954+
fi
955+
956+
echo "Generating geth genesis spec at $geth_spec_path..."
957+
mkdir -p "$HOME/.revive"
958+
set -x
959+
cargo run --quiet --release --manifest-path "$RETESTER_DIR/Cargo.toml" -- \
960+
export-genesis geth-evm-solc \
961+
--revive-dev-node.path "$POLKADOT_SDK_DIR/target/debug/revive-dev-node" \
962+
>"$HOME/.revive/geth_spec_base.json"
963+
{ set +x; } 2>/dev/null
964+
965+
if [ ! -f "$HOME/.revive/geth_spec_base.json" ]; then
966+
echo "Error: Failed to generate geth genesis spec"
967+
return 1
968+
fi
969+
970+
# Patch the alloc section to give Alith account the same balance as others
971+
jq '.alloc["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"].balance = "0x785ee10d5da46d900f436a000000000"
972+
| .alloc["0x71562b71999873db5b286df957af199ec94617f7"].balance = "0x785ee10d5da46d900f436a000000000"' \
973+
"$HOME/.revive/geth_spec_base.json" >"$geth_spec_path"
974+
rm -f "$HOME/.revive/geth_spec_base.json"
975+
976+
echo "Successfully generated geth genesis spec at $geth_spec_path"
977+
else
978+
echo "Using existing geth genesis spec at $geth_spec_path"
979+
fi
980+
}
981+
982+
# Helper function to start geth
983+
start_geth() {
984+
local geth_port="$1"
985+
986+
if [ "$retester_flag" = "true" ]; then
987+
local geth_data_dir="/tmp/geth-retester-data"
988+
rm -rf "$geth_data_dir"
989+
mkdir -p "$geth_data_dir"
931990

932-
# Start mitmproxy with specified port mapping
933-
start_mitmproxy "${proxy_port}:${server_port}"
991+
set -x
992+
geth init --datadir "$geth_data_dir" "$HOME/.revive/geth_spec.json"
993+
geth --datadir "$geth_data_dir" --http --http.api web3,eth,txpool,miner,debug,net --http.port "$geth_port" --dev
994+
{ set +x; } 2>/dev/null
995+
else
996+
set -x
997+
geth --http --http.api web3,eth,txpool,miner,debug,net --http.port "$geth_port" --dev
998+
{ set +x; } 2>/dev/null
999+
fi
1000+
}
9341001

935-
# Rename tmux window if running in tmux
936-
if [ -n "$TMUX" ]; then
937-
tmux rename-window "geth"
1002+
# Generate genesis spec if needed
1003+
if [ "$retester_flag" = "true" ]; then
1004+
generate_genesis_spec || return 1
9381005
fi
9391006

940-
# Start geth in development mode with HTTP RPC enabled
941-
geth --http --http.api web3,eth,txpool,miner,debug,net --http.port "$server_port" --dev
1007+
# Execute based on mode
1008+
case "$mode" in
1009+
proxy)
1010+
# Calculate server port (port + 1)
1011+
local server_port=$((port + 1))
1012+
1013+
# Kill any existing mitmproxy instances
1014+
pkill -f mitmproxy
1015+
1016+
# Start mitmproxy
1017+
start_mitmproxy "${port}:${server_port}"
1018+
1019+
# Start geth on server port
1020+
start_geth "$server_port"
1021+
;;
1022+
run)
1023+
# Start geth directly
1024+
start_geth "$port"
1025+
;;
1026+
esac
9421027
}
9431028

944-
# Runs geth with mitmproxy in a new tmux window
945-
# Provides a quick way to start an Ethereum development node with traffic inspection
946-
# Usage: geth_stack
1029+
# Runs geth in a new tmux window
1030+
# Provides a quick way to start an Ethereum development node
1031+
# Usage: geth_stack [--proxy] [--retester]
1032+
# Examples:
1033+
# geth_stack - Run geth without proxy
1034+
# geth_stack --proxy - Run geth with proxy
1035+
# geth_stack --retester - Run geth with retester genesis spec
1036+
# geth_stack --proxy --retester - Run geth with proxy and retester genesis spec
9471037
function geth_stack() {
9481038
# Kill existing 'servers' window if it exists
9491039
tmux kill-window -t servers 2>/dev/null
9501040
# Kill existing 'mitmproxy' window if it exists
9511041
tmux kill-window -t mitmproxy 2>/dev/null
9521042

1043+
# Parse arguments
1044+
mode="run"
1045+
retester_flag=""
1046+
1047+
for arg in "$@"; do
1048+
case "$arg" in
1049+
--proxy)
1050+
mode="proxy"
1051+
;;
1052+
--retester)
1053+
retester_flag="--retester"
1054+
;;
1055+
esac
1056+
done
1057+
9531058
# Create new 'servers' window in detached mode
954-
# Source shell config and run geth-proxy with default ports (8545->8546)
955-
tmux new-window -d -n servers "$CURRENT_SHELL -c 'source $SHELL_RC; geth-proxy 8545 8546; exec \$SHELL'"
1059+
# Source shell config and run geth with specified mode
1060+
tmux new-window -d -n servers "$CURRENT_SHELL -c 'source $SHELL_RC; geth-dev $mode $retester_flag; exec \$SHELL'"
9561061
}
9571062

9581063
# Runs the complete Passet Hub stack (passet node + eth-rpc) in tmux window

0 commit comments

Comments
 (0)