diff --git a/.github/workflows/test-examples.yml b/.github/workflows/test-examples.yml index 5136ec95..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 \ @@ -91,21 +90,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 +116,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 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( 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