From d963fb66f3ef647a85c7221ca1252e519bcee115 Mon Sep 17 00:00:00 2001 From: fauxfire Date: Mon, 5 Jan 2026 19:06:20 +0800 Subject: [PATCH 1/6] test --- test-locally.sh | 201 +++++++++++++++++++++++++++++++----------------- 1 file changed, 131 insertions(+), 70 deletions(-) diff --git a/test-locally.sh b/test-locally.sh index a18641f9..9546ef72 100755 --- a/test-locally.sh +++ b/test-locally.sh @@ -6,12 +6,24 @@ set +m SOLANA_PID="" EPHEMERAL_PID="" +SOLANA_STARTED_BY_US=false +EPHEMERAL_STARTED_BY_US=false PASSED_TESTS=() FAILED_TESTS=() FAILED_TESTS_NAMES=() FAILED_TESTS_ERRORS=() TEST_COUNT=0 +# Check if a port is in use +check_port() { + local port=$1 + if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then + return 0 # Port is in use + else + return 1 # Port is not in use + fi +} + # Test runner function run_test() { local test_name=$1 @@ -251,39 +263,70 @@ cleanup() { # Clear current line echo -ne "\r \r" echo "" - echo -n "Stopping validators... " - - # Kill by PID if available - if [ -n "$SOLANA_PID" ]; then - kill -TERM $SOLANA_PID 2>/dev/null || true - fi - if [ -n "$EPHEMERAL_PID" ]; then - kill -TERM $EPHEMERAL_PID 2>/dev/null || true - fi - - # Give them a moment to gracefully shutdown - sleep 1 - - # Force kill any remaining processes - if [ -n "$SOLANA_PID" ]; then - kill -9 $SOLANA_PID 2>/dev/null || true - fi - if [ -n "$EPHEMERAL_PID" ]; then - kill -9 $EPHEMERAL_PID 2>/dev/null || true - fi - # Also kill by process name as fallback - pkill -f "solana-test-validator" 2>/dev/null || true - pkill -f "ephemeral-validator" 2>/dev/null || true - - # Wait for background jobs silently - { wait 2>/dev/null || true; } 2>/dev/null - - # Check if validators are actually stopped - if ! pgrep -f "solana-test-validator" >/dev/null 2>&1 && ! pgrep -f "ephemeral-validator" >/dev/null 2>&1; then - echo "✓ Stopped" + # Only stop validators if we started them + if [ "$SOLANA_STARTED_BY_US" = true ] || [ "$EPHEMERAL_STARTED_BY_US" = true ]; then + echo -n "Stopping validators... " + + # Kill by PID if available and we started them + if [ "$SOLANA_STARTED_BY_US" = true ] && [ -n "$SOLANA_PID" ]; then + kill -TERM $SOLANA_PID 2>/dev/null || true + fi + if [ "$EPHEMERAL_STARTED_BY_US" = true ] && [ -n "$EPHEMERAL_PID" ]; then + kill -TERM $EPHEMERAL_PID 2>/dev/null || true + fi + + # Give them a moment to gracefully shutdown + sleep 1 + + # Force kill any remaining processes + if [ "$SOLANA_STARTED_BY_US" = true ] && [ -n "$SOLANA_PID" ]; then + kill -9 $SOLANA_PID 2>/dev/null || true + fi + if [ "$EPHEMERAL_STARTED_BY_US" = true ] && [ -n "$EPHEMERAL_PID" ]; then + kill -9 $EPHEMERAL_PID 2>/dev/null || true + fi + + # Also kill by process name as fallback (only if we started them) + if [ "$SOLANA_STARTED_BY_US" = true ]; then + pkill -f "solana-test-validator" 2>/dev/null || true + fi + if [ "$EPHEMERAL_STARTED_BY_US" = true ]; then + pkill -f "ephemeral-validator" 2>/dev/null || true + fi + + # Wait for background jobs silently + { wait 2>/dev/null || true; } 2>/dev/null + + # Check if validators are actually stopped + local should_check=false + if [ "$SOLANA_STARTED_BY_US" = true ] && [ "$EPHEMERAL_STARTED_BY_US" = true ]; then + should_check=true + elif [ "$SOLANA_STARTED_BY_US" = true ]; then + if ! pgrep -f "solana-test-validator" >/dev/null 2>&1; then + echo "✓ Stopped" + else + echo "✗ Failed to stop" + fi + should_check=false + elif [ "$EPHEMERAL_STARTED_BY_US" = true ]; then + if ! pgrep -f "ephemeral-validator" >/dev/null 2>&1; then + echo "✓ Stopped" + else + echo "✗ Failed to stop" + fi + should_check=false + fi + + if [ "$should_check" = true ]; then + if ! pgrep -f "solana-test-validator" >/dev/null 2>&1 && ! pgrep -f "ephemeral-validator" >/dev/null 2>&1; then + echo "✓ Stopped" + else + echo "✗ Failed to stop" + fi + fi else - echo "✗ Failed to stop" + echo "Validators were already running, leaving them running..." fi exit 0 @@ -302,46 +345,64 @@ if [ ! -f ~/.config/solana/id.json ]; then solana-keygen new --no-bip39-passphrase --silent --outfile ~/.config/solana/id.json fi -# Start Solana Test Validator -echo "Starting Solana Test Validator..." -solana-test-validator \ - --ledger ./test-ledger \ - --reset \ - --clone mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev \ - --clone EpJnX7ueXk7fKojBymqmVuCuwyhDQsYcLVL1XMsBbvDX \ - --clone 7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg \ - --clone noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV \ - --clone-upgradeable-program DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh \ - --clone Cuj97ggrhhidhbu39TijNVqE74xvKJ69gDervRUXAxGh \ - --clone 5hBR571xnXppuCPveTrctfTU7tJLSN94nq7kv7FRK5Tc \ - --clone F72HqCR8nwYsVyeVd38pgKkjXmXFzVAM8rjZZsXWbdE \ - --clone vrfkfM4uoisXZQPrFiS2brY4oMkU9EWjyvmvqaFd5AS \ - --clone-upgradeable-program Vrf1RNUjXmQGjmQrQLvJHs9SNkvDJEsRVFPkfSQUwGz \ - --clone-upgradeable-program BTWAqWNBmF2TboMh3fxMJfgR16xGHYD7Kgr2dPwbRPBi \ - --url https://api.devnet.solana.com > ./test-ledger.log 2>&1 & - -SOLANA_PID=$! - -# Wait for validator to be ready -echo "Waiting for Solana validator..." -for i in {1..30}; do - if solana cluster-version --url http://localhost:8899 >/dev/null 2>&1; then - break - fi - sleep 1 -done -echo "Solana validator is ready, waiting for RPC to stabilize..." - -# Start MagicBlock Ephemeral Validator -echo "Starting MagicBlock Ephemeral Validator..." -RUST_LOG=info ephemeral-validator \ - --accounts-lifecycle ephemeral \ - --remote-cluster development \ - --remote-url http://localhost:8899 \ - --remote-ws-url ws://localhost:8900 \ - --rpc-port 7799 > ./ephemeral-validator.log 2>&1 & +# Check if Solana Test Validator is already running on port 8899 +if check_port 8899; then + echo "Solana Test Validator is already running on port 8899, skipping startup..." + SOLANA_STARTED_BY_US=false + # Try to get the PID of the running validator + SOLANA_PID=$(lsof -ti :8899 | head -1) +else + # Start Solana Test Validator + echo "Starting Solana Test Validator..." + solana-test-validator \ + --ledger ./test-ledger \ + --reset \ + --clone mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev \ + --clone EpJnX7ueXk7fKojBymqmVuCuwyhDQsYcLVL1XMsBbvDX \ + --clone 7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg \ + --clone noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV \ + --clone-upgradeable-program DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh \ + --clone Cuj97ggrhhidhbu39TijNVqE74xvKJ69gDervRUXAxGh \ + --clone 5hBR571xnXppuCPveTrctfTU7tJLSN94nq7kv7FRK5Tc \ + --clone F72HqCR8nwYsVyeVd38pgKkjXmXFzVAM8rjZZsXWbdE \ + --clone vrfkfM4uoisXZQPrFiS2brY4oMkU9EWjyvmvqaFd5AS \ + --clone-upgradeable-program Vrf1RNUjXmQGjmQrQLvJHs9SNkvDJEsRVFPkfSQUwGz \ + --clone-upgradeable-program BTWAqWNBmF2TboMh3fxMJfgR16xGHYD7Kgr2dPwbRPBi \ + --url https://api.devnet.solana.com > ./test-ledger.log 2>&1 & + + SOLANA_PID=$! + SOLANA_STARTED_BY_US=true + + # Wait for validator to be ready + echo "Waiting for Solana validator..." + for i in {1..30}; do + if solana cluster-version --url http://localhost:8899 >/dev/null 2>&1; then + break + fi + sleep 1 + done + echo "Solana validator is ready, waiting for RPC to stabilize..." +fi -EPHEMERAL_PID=$! +# Check if MagicBlock Ephemeral Validator is already running on port 7799 +if check_port 7799; then + echo "MagicBlock Ephemeral Validator is already running on port 7799, skipping startup..." + EPHEMERAL_STARTED_BY_US=false + # Try to get the PID of the running validator + EPHEMERAL_PID=$(lsof -ti :7799 | head -1) +else + # Start MagicBlock Ephemeral Validator + echo "Starting MagicBlock Ephemeral Validator..." + RUST_LOG=info ephemeral-validator \ + --accounts-lifecycle ephemeral \ + --remote-cluster development \ + --remote-url http://localhost:8899 \ + --remote-ws-url ws://localhost:8900 \ + --rpc-port 7799 > ./ephemeral-validator.log 2>&1 & + + EPHEMERAL_PID=$! + EPHEMERAL_STARTED_BY_US=true +fi echo "Validators ready. Running tests..." echo "" From 544227618556aa8a9fe016df620cf8623c728716 Mon Sep 17 00:00:00 2001 From: fauxfire Date: Mon, 5 Jan 2026 19:25:09 +0800 Subject: [PATCH 2/6] skip router tests on localnet --- fullstack-test.sh | 166 ++++++++++++++++++++++++++++------------------ 1 file changed, 101 insertions(+), 65 deletions(-) diff --git a/fullstack-test.sh b/fullstack-test.sh index c3a2973f..2186e802 100755 --- a/fullstack-test.sh +++ b/fullstack-test.sh @@ -7,6 +7,19 @@ GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color +MB_VALIDATOR_STARTED_BY_US=false +EPHEMERAL_VALIDATOR_STARTED_BY_US=false + +# Check if a port is in use +check_port() { + local port=$1 + if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then + return 0 # Port is in use + else + return 1 # Port is not in use + fi +} + # Check cluster from Anchor.toml ANCHOR_TOML="Anchor.toml" if [ ! -f "$ANCHOR_TOML" ]; then @@ -25,21 +38,33 @@ echo -e "${GREEN}Detected Cluster: ${CLUSTER}${NC}" # Cleanup function cleanup() { if [ "$CLUSTER" = "localnet" ]; then - echo -ne "\n[SETUP] ${YELLOW}Cleaning up validators...${NC}\r" - if [ ! -z "$MB_VALIDATOR_PID" ]; then - kill $MB_VALIDATOR_PID 2>/dev/null || true - fi - if [ ! -z "$EPHEMERAL_VALIDATOR_PID" ]; then - kill $EPHEMERAL_VALIDATOR_PID 2>/dev/null || true + # Only cleanup validators if we started them + if [ "$MB_VALIDATOR_STARTED_BY_US" = true ] || [ "$EPHEMERAL_VALIDATOR_STARTED_BY_US" = true ]; then + echo -ne "\n[SETUP] ${YELLOW}Cleaning up validators...${NC}\r" + if [ "$MB_VALIDATOR_STARTED_BY_US" = true ] && [ ! -z "$MB_VALIDATOR_PID" ]; then + kill $MB_VALIDATOR_PID 2>/dev/null || true + fi + if [ "$EPHEMERAL_VALIDATOR_STARTED_BY_US" = true ] && [ ! -z "$EPHEMERAL_VALIDATOR_PID" ]; then + kill $EPHEMERAL_VALIDATOR_PID 2>/dev/null || true + fi + # Kill any remaining validator processes (only if we started them) + if [ "$MB_VALIDATOR_STARTED_BY_US" = true ]; then + pkill -f "solana-test-validator" 2>/dev/null || true + pkill -f "mb-test-validator" 2>/dev/null || true + fi + if [ "$EPHEMERAL_VALIDATOR_STARTED_BY_US" = true ]; then + pkill -f "ephemeral-validator" 2>/dev/null || true + fi + # Clean up test ledger directories (only if we started the validators) + if [ "$MB_VALIDATOR_STARTED_BY_US" = true ]; then + echo -ne "${YELLOW}Cleaning up test ledger directories...${NC}\r" + rm -rf test-ledger 2>/dev/null || true + rm -rf test-ledger-magicblock 2>/dev/null || true + fi + echo -e "\033[2K${GREEN}Cleanup complete${NC}" + else + echo -e "\n[SETUP] ${GREEN}Validators were already running, leaving them running...${NC}" fi - # Kill any remaining validator processes - pkill -f "solana-test-validator" 2>/dev/null || true - pkill -f "ephemeral-validator" 2>/dev/null || true - # Clean up test ledger directories - echo -ne "${YELLOW}Cleaning up test ledger directories...${NC}\r" - rm -rf test-ledger 2>/dev/null || true - rm -rf test-ledger-magicblock 2>/dev/null || true - echo -e "\033[2K${GREEN}Cleanup complete${NC}" fi } @@ -54,60 +79,71 @@ if [ "$CLUSTER" = "localnet" ]; then exit 1 fi - # Kill any existing validators that might be running - echo -ne "[SETUP] ${YELLOW}Cleaning existing validators...${NC}\r" - pkill -f "mb-test-validator" 2>/dev/null || true - pkill -f "ephemeral-validator" 2>/dev/null || true - pkill -f "solana-test-validator" 2>/dev/null || true - sleep 2 - - echo -ne "[SETUP] ${GREEN}Starting mb-test-validator...${NC}\r" - mb-test-validator --reset > /tmp/mb-test-validator.log 2>&1 & - MB_VALIDATOR_PID=$! - # Set solana config to localhost solana config set --url localhost - # Wait for solana-test-validator to be ready - echo -ne "${YELLOW}Waiting for solana-test-validator to be ready...${NC}\r" - for i in {1..60}; do - if curl -s http://127.0.0.1:8899/health > /dev/null 2>&1; then - echo -e "\033[2K${GREEN}solana-test-validator is ready${NC}" - break - fi - if [ $i -eq 60 ]; then - echo -e "\033[2K${RED}Error: solana-test-validator failed to start${NC}" - echo "Check logs at /tmp/mb-test-validator.log" - exit 1 - fi - sleep 1 - done - - # Start ephemeral-validator - echo -ne "[SETUP] ${GREEN}Starting ephemeral-validator...${NC}\r" - RUST_LOG=info ephemeral-validator \ - --accounts-lifecycle ephemeral \ - --remote-cluster development \ - --remote-url http://127.0.0.1:8899 \ - --remote-ws-url ws://127.0.0.1:8900 \ - --rpc-port 7799 \ - > /tmp/ephemeral-validator.log 2>&1 & - EPHEMERAL_VALIDATOR_PID=$! - - # Wait for ephemeral-validator to be ready - echo -ne "${YELLOW}Waiting for ephemeral-validator to be ready...${NC}\r" - for i in {1..60}; do - if curl -s http://127.0.0.1:7799/health > /dev/null 2>&1; then - echo -e "\033[2K${GREEN}ephemeral-validator is ready${NC}" - break - fi - if [ $i -eq 60 ]; then - echo -e "\033[2K${RED}Error: ephemeral-validator failed to start${NC}" - echo "Check logs at /tmp/ephemeral-validator.log" - exit 1 - fi - sleep 1 - done + # Check if mb-test-validator (Solana validator) is already running on port 8899 + if check_port 8899; then + echo -e "[SETUP] ${GREEN}Solana validator is already running on port 8899, skipping startup...${NC}" + MB_VALIDATOR_STARTED_BY_US=false + # Try to get the PID of the running validator + MB_VALIDATOR_PID=$(lsof -ti :8899 | head -1) + else + echo -ne "[SETUP] ${GREEN}Starting mb-test-validator...${NC}\r" + mb-test-validator --reset > /tmp/mb-test-validator.log 2>&1 & + MB_VALIDATOR_PID=$! + MB_VALIDATOR_STARTED_BY_US=true + + # Wait for solana-test-validator to be ready + echo -ne "${YELLOW}Waiting for solana-test-validator to be ready...${NC}\r" + for i in {1..60}; do + if curl -s http://127.0.0.1:8899/health > /dev/null 2>&1; then + echo -e "\033[2K${GREEN}solana-test-validator is ready${NC}" + break + fi + if [ $i -eq 60 ]; then + echo -e "\033[2K${RED}Error: solana-test-validator failed to start${NC}" + echo "Check logs at /tmp/mb-test-validator.log" + exit 1 + fi + sleep 1 + done + fi + + # Check if ephemeral-validator is already running on port 7799 + if check_port 7799; then + echo -e "[SETUP] ${GREEN}Ephemeral validator is already running on port 7799, skipping startup...${NC}" + EPHEMERAL_VALIDATOR_STARTED_BY_US=false + # Try to get the PID of the running validator + EPHEMERAL_VALIDATOR_PID=$(lsof -ti :7799 | head -1) + else + # Start ephemeral-validator + echo -ne "[SETUP] ${GREEN}Starting ephemeral-validator...${NC}\r" + RUST_LOG=info ephemeral-validator \ + --accounts-lifecycle ephemeral \ + --remote-cluster development \ + --remote-url http://127.0.0.1:8899 \ + --remote-ws-url ws://127.0.0.1:8900 \ + --rpc-port 7799 \ + > /tmp/ephemeral-validator.log 2>&1 & + EPHEMERAL_VALIDATOR_PID=$! + EPHEMERAL_VALIDATOR_STARTED_BY_US=true + + # Wait for ephemeral-validator to be ready + echo -ne "${YELLOW}Waiting for ephemeral-validator to be ready...${NC}\r" + for i in {1..60}; do + if curl -s http://127.0.0.1:7799/health > /dev/null 2>&1; then + echo -e "\033[2K${GREEN}ephemeral-validator is ready${NC}" + break + fi + if [ $i -eq 60 ]; then + echo -e "\033[2K${RED}Error: ephemeral-validator failed to start${NC}" + echo "Check logs at /tmp/ephemeral-validator.log" + exit 1 + fi + sleep 1 + done + fi export EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 export EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 From e7c5410fcc710fd360ea1ebf6be1f2b35676e7e0 Mon Sep 17 00:00:00 2001 From: fauxfire Date: Mon, 5 Jan 2026 19:25:22 +0800 Subject: [PATCH 3/6] skip router tests on localnet --- anchor-counter/tests/advanced-magic.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/anchor-counter/tests/advanced-magic.ts b/anchor-counter/tests/advanced-magic.ts index 2c29d166..e640344f 100644 --- a/anchor-counter/tests/advanced-magic.ts +++ b/anchor-counter/tests/advanced-magic.ts @@ -9,7 +9,17 @@ import { const COUNTER_SEED = "counter"; -describe("magic-router-and-multiple-atomic-ixs", () => { +const anchorProvider = anchor.AnchorProvider.env(); +const isLocalnet = anchorProvider.connection.rpcEndpoint.includes("localhost") || + anchorProvider.connection.rpcEndpoint.includes("127.0.0.1"); + +if (isLocalnet) { + console.log("Skipping 'magic-router-and-multiple-atomic-ixs' test suite because it's running on localnet"); +} + +const testSuite = isLocalnet ? describe.skip : describe; + +testSuite("magic-router-and-multiple-atomic-ixs", () => { console.log("advanced-magic.ts") const connection = new ConnectionMagicRouter( From dcf94e8a7f54e5ef8255304685a506f674aa5dbb Mon Sep 17 00:00:00 2001 From: fauxfire Date: Mon, 5 Jan 2026 19:26:52 +0800 Subject: [PATCH 4/6] Revert "test" This reverts commit d963fb66f3ef647a85c7221ca1252e519bcee115. --- test-locally.sh | 201 +++++++++++++++++------------------------------- 1 file changed, 70 insertions(+), 131 deletions(-) diff --git a/test-locally.sh b/test-locally.sh index 9546ef72..a18641f9 100755 --- a/test-locally.sh +++ b/test-locally.sh @@ -6,24 +6,12 @@ set +m SOLANA_PID="" EPHEMERAL_PID="" -SOLANA_STARTED_BY_US=false -EPHEMERAL_STARTED_BY_US=false PASSED_TESTS=() FAILED_TESTS=() FAILED_TESTS_NAMES=() FAILED_TESTS_ERRORS=() TEST_COUNT=0 -# Check if a port is in use -check_port() { - local port=$1 - if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then - return 0 # Port is in use - else - return 1 # Port is not in use - fi -} - # Test runner function run_test() { local test_name=$1 @@ -263,70 +251,39 @@ cleanup() { # Clear current line echo -ne "\r \r" echo "" + echo -n "Stopping validators... " - # Only stop validators if we started them - if [ "$SOLANA_STARTED_BY_US" = true ] || [ "$EPHEMERAL_STARTED_BY_US" = true ]; then - echo -n "Stopping validators... " - - # Kill by PID if available and we started them - if [ "$SOLANA_STARTED_BY_US" = true ] && [ -n "$SOLANA_PID" ]; then - kill -TERM $SOLANA_PID 2>/dev/null || true - fi - if [ "$EPHEMERAL_STARTED_BY_US" = true ] && [ -n "$EPHEMERAL_PID" ]; then - kill -TERM $EPHEMERAL_PID 2>/dev/null || true - fi - - # Give them a moment to gracefully shutdown - sleep 1 - - # Force kill any remaining processes - if [ "$SOLANA_STARTED_BY_US" = true ] && [ -n "$SOLANA_PID" ]; then - kill -9 $SOLANA_PID 2>/dev/null || true - fi - if [ "$EPHEMERAL_STARTED_BY_US" = true ] && [ -n "$EPHEMERAL_PID" ]; then - kill -9 $EPHEMERAL_PID 2>/dev/null || true - fi - - # Also kill by process name as fallback (only if we started them) - if [ "$SOLANA_STARTED_BY_US" = true ]; then - pkill -f "solana-test-validator" 2>/dev/null || true - fi - if [ "$EPHEMERAL_STARTED_BY_US" = true ]; then - pkill -f "ephemeral-validator" 2>/dev/null || true - fi - - # Wait for background jobs silently - { wait 2>/dev/null || true; } 2>/dev/null - - # Check if validators are actually stopped - local should_check=false - if [ "$SOLANA_STARTED_BY_US" = true ] && [ "$EPHEMERAL_STARTED_BY_US" = true ]; then - should_check=true - elif [ "$SOLANA_STARTED_BY_US" = true ]; then - if ! pgrep -f "solana-test-validator" >/dev/null 2>&1; then - echo "✓ Stopped" - else - echo "✗ Failed to stop" - fi - should_check=false - elif [ "$EPHEMERAL_STARTED_BY_US" = true ]; then - if ! pgrep -f "ephemeral-validator" >/dev/null 2>&1; then - echo "✓ Stopped" - else - echo "✗ Failed to stop" - fi - should_check=false - fi - - if [ "$should_check" = true ]; then - if ! pgrep -f "solana-test-validator" >/dev/null 2>&1 && ! pgrep -f "ephemeral-validator" >/dev/null 2>&1; then - echo "✓ Stopped" - else - echo "✗ Failed to stop" - fi - fi + # Kill by PID if available + if [ -n "$SOLANA_PID" ]; then + kill -TERM $SOLANA_PID 2>/dev/null || true + fi + if [ -n "$EPHEMERAL_PID" ]; then + kill -TERM $EPHEMERAL_PID 2>/dev/null || true + fi + + # Give them a moment to gracefully shutdown + sleep 1 + + # Force kill any remaining processes + if [ -n "$SOLANA_PID" ]; then + kill -9 $SOLANA_PID 2>/dev/null || true + fi + if [ -n "$EPHEMERAL_PID" ]; then + kill -9 $EPHEMERAL_PID 2>/dev/null || true + fi + + # Also kill by process name as fallback + pkill -f "solana-test-validator" 2>/dev/null || true + pkill -f "ephemeral-validator" 2>/dev/null || true + + # Wait for background jobs silently + { wait 2>/dev/null || true; } 2>/dev/null + + # Check if validators are actually stopped + if ! pgrep -f "solana-test-validator" >/dev/null 2>&1 && ! pgrep -f "ephemeral-validator" >/dev/null 2>&1; then + echo "✓ Stopped" else - echo "Validators were already running, leaving them running..." + echo "✗ Failed to stop" fi exit 0 @@ -345,64 +302,46 @@ if [ ! -f ~/.config/solana/id.json ]; then solana-keygen new --no-bip39-passphrase --silent --outfile ~/.config/solana/id.json fi -# Check if Solana Test Validator is already running on port 8899 -if check_port 8899; then - echo "Solana Test Validator is already running on port 8899, skipping startup..." - SOLANA_STARTED_BY_US=false - # Try to get the PID of the running validator - SOLANA_PID=$(lsof -ti :8899 | head -1) -else - # Start Solana Test Validator - echo "Starting Solana Test Validator..." - solana-test-validator \ - --ledger ./test-ledger \ - --reset \ - --clone mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev \ - --clone EpJnX7ueXk7fKojBymqmVuCuwyhDQsYcLVL1XMsBbvDX \ - --clone 7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg \ - --clone noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV \ - --clone-upgradeable-program DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh \ - --clone Cuj97ggrhhidhbu39TijNVqE74xvKJ69gDervRUXAxGh \ - --clone 5hBR571xnXppuCPveTrctfTU7tJLSN94nq7kv7FRK5Tc \ - --clone F72HqCR8nwYsVyeVd38pgKkjXmXFzVAM8rjZZsXWbdE \ - --clone vrfkfM4uoisXZQPrFiS2brY4oMkU9EWjyvmvqaFd5AS \ - --clone-upgradeable-program Vrf1RNUjXmQGjmQrQLvJHs9SNkvDJEsRVFPkfSQUwGz \ - --clone-upgradeable-program BTWAqWNBmF2TboMh3fxMJfgR16xGHYD7Kgr2dPwbRPBi \ - --url https://api.devnet.solana.com > ./test-ledger.log 2>&1 & - - SOLANA_PID=$! - SOLANA_STARTED_BY_US=true - - # Wait for validator to be ready - echo "Waiting for Solana validator..." - for i in {1..30}; do - if solana cluster-version --url http://localhost:8899 >/dev/null 2>&1; then - break - fi - sleep 1 - done - echo "Solana validator is ready, waiting for RPC to stabilize..." -fi +# Start Solana Test Validator +echo "Starting Solana Test Validator..." +solana-test-validator \ + --ledger ./test-ledger \ + --reset \ + --clone mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev \ + --clone EpJnX7ueXk7fKojBymqmVuCuwyhDQsYcLVL1XMsBbvDX \ + --clone 7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg \ + --clone noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV \ + --clone-upgradeable-program DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh \ + --clone Cuj97ggrhhidhbu39TijNVqE74xvKJ69gDervRUXAxGh \ + --clone 5hBR571xnXppuCPveTrctfTU7tJLSN94nq7kv7FRK5Tc \ + --clone F72HqCR8nwYsVyeVd38pgKkjXmXFzVAM8rjZZsXWbdE \ + --clone vrfkfM4uoisXZQPrFiS2brY4oMkU9EWjyvmvqaFd5AS \ + --clone-upgradeable-program Vrf1RNUjXmQGjmQrQLvJHs9SNkvDJEsRVFPkfSQUwGz \ + --clone-upgradeable-program BTWAqWNBmF2TboMh3fxMJfgR16xGHYD7Kgr2dPwbRPBi \ + --url https://api.devnet.solana.com > ./test-ledger.log 2>&1 & -# Check if MagicBlock Ephemeral Validator is already running on port 7799 -if check_port 7799; then - echo "MagicBlock Ephemeral Validator is already running on port 7799, skipping startup..." - EPHEMERAL_STARTED_BY_US=false - # Try to get the PID of the running validator - EPHEMERAL_PID=$(lsof -ti :7799 | head -1) -else - # Start MagicBlock Ephemeral Validator - echo "Starting MagicBlock Ephemeral Validator..." - RUST_LOG=info ephemeral-validator \ - --accounts-lifecycle ephemeral \ - --remote-cluster development \ - --remote-url http://localhost:8899 \ - --remote-ws-url ws://localhost:8900 \ - --rpc-port 7799 > ./ephemeral-validator.log 2>&1 & - - EPHEMERAL_PID=$! - EPHEMERAL_STARTED_BY_US=true -fi +SOLANA_PID=$! + +# Wait for validator to be ready +echo "Waiting for Solana validator..." +for i in {1..30}; do + if solana cluster-version --url http://localhost:8899 >/dev/null 2>&1; then + break + fi + sleep 1 +done +echo "Solana validator is ready, waiting for RPC to stabilize..." + +# Start MagicBlock Ephemeral Validator +echo "Starting MagicBlock Ephemeral Validator..." +RUST_LOG=info ephemeral-validator \ + --accounts-lifecycle ephemeral \ + --remote-cluster development \ + --remote-url http://localhost:8899 \ + --remote-ws-url ws://localhost:8900 \ + --rpc-port 7799 > ./ephemeral-validator.log 2>&1 & + +EPHEMERAL_PID=$! echo "Validators ready. Running tests..." echo "" From 379a2fae826226dc706bd009a982ee341c9f5da1 Mon Sep 17 00:00:00 2001 From: fauxfire Date: Mon, 5 Jan 2026 19:37:34 +0800 Subject: [PATCH 5/6] do testing --- .github/workflows/test-examples.yml | 138 ++++++++++++++-------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/.github/workflows/test-examples.yml b/.github/workflows/test-examples.yml index 5136ec95..629b8de5 100644 --- a/.github/workflows/test-examples.yml +++ b/.github/workflows/test-examples.yml @@ -91,21 +91,21 @@ jobs: --skip-local-validator \ --skip-deploy - - name: Test anchor-minter - run: | - cd anchor-minter - anchor build && anchor deploy --provider.cluster localnet - yarn install - anchor test \ - --skip-deploy - - - name: Test anchor-rock-paper-scissor - run: | - cd anchor-rock-paper-scissor - anchor build - yarn install - anchor test \ - --skip-deploy + # - name: Test anchor-minter + # run: | + # cd anchor-minter + # anchor build && anchor deploy --provider.cluster localnet + # yarn install + # anchor test \ + # --skip-deploy + + # - name: Test anchor-rock-paper-scissor + # run: | + # cd anchor-rock-paper-scissor + # anchor build + # yarn install + # anchor test \ + # --skip-deploy # - name: Test bolt-counter # run: | @@ -117,57 +117,57 @@ jobs: # WS_ENDPOINT=http://localhost:8900 \ # yarn test - - name: Test dummy-token-transfer - run: | - cd dummy-token-transfer - yarn install - EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 \ - EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 \ - PROVIDER_ENDPOINT=http://localhost:8899 \ - WS_ENDPOINT=http://localhost:8900 \ - anchor test - - - name: Test magic-actions - run: | - cd magic-actions - yarn install - anchor build - yarn install - anchor test \ - --skip-deploy - - - name: Test oncurve-delegation - run: | - cd oncurve-delegation - yarn install - yarn test - yarn test-web3js - - - name: Test roll-dice - run: | - cd roll-dice - yarn install - EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 \ - EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 \ - PROVIDER_ENDPOINT=http://localhost:8899 \ - WS_ENDPOINT=http://localhost:8900 \ - anchor test - - - name: Test rust-counter - run: | - cd rust-counter - yarn install - EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 \ - EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 \ - PROVIDER_ENDPOINT=http://localhost:8899 \ - WS_ENDPOINT=http://localhost:8900 \ - yarn test - - - name: Test session-keys - run: | - cd session-keys - yarn install - anchor build - yarn install - anchor test \ - --skip-deploy + # - name: Test dummy-token-transfer + # run: | + # cd dummy-token-transfer + # yarn install + # EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 \ + # EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 \ + # PROVIDER_ENDPOINT=http://localhost:8899 \ + # WS_ENDPOINT=http://localhost:8900 \ + # anchor test + + # - name: Test magic-actions + # run: | + # cd magic-actions + # yarn install + # anchor build + # yarn install + # anchor test \ + # --skip-deploy + + # - name: Test oncurve-delegation + # run: | + # cd oncurve-delegation + # yarn install + # yarn test + # yarn test-web3js + + # - name: Test roll-dice + # run: | + # cd roll-dice + # yarn install + # EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 \ + # EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 \ + # PROVIDER_ENDPOINT=http://localhost:8899 \ + # WS_ENDPOINT=http://localhost:8900 \ + # anchor test + + # - name: Test rust-counter + # run: | + # cd rust-counter + # yarn install + # EPHEMERAL_PROVIDER_ENDPOINT=http://localhost:7799 \ + # EPHEMERAL_WS_ENDPOINT=ws://localhost:7800 \ + # PROVIDER_ENDPOINT=http://localhost:8899 \ + # WS_ENDPOINT=http://localhost:8900 \ + # yarn test + + # - name: Test session-keys + # run: | + # cd session-keys + # yarn install + # anchor build + # yarn install + # anchor test \ + # --skip-deploy From cbe2b58000b8a57e550b05fb481c03d320a5c791 Mon Sep 17 00:00:00 2001 From: fauxfire Date: Mon, 19 Jan 2026 23:20:53 +0700 Subject: [PATCH 6/6] fix: update workflow --- .github/workflows/test-examples.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-examples.yml b/.github/workflows/test-examples.yml index 629b8de5..540cdc4f 100644 --- a/.github/workflows/test-examples.yml +++ b/.github/workflows/test-examples.yml @@ -69,7 +69,6 @@ jobs: sudo sysctl fs.inotify.max_user_instances=1280 sudo sysctl fs.inotify.max_user_watches=655360 RUST_LOG=info ephemeral-validator \ - --accounts-lifecycle ephemeral \ --remote-cluster development \ --remote-url http://127.0.0.1:8899 \ --remote-ws-url ws://127.0.0.1:8900 \