Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 69 additions & 70 deletions .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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: |
Expand All @@ -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
12 changes: 11 additions & 1 deletion anchor-counter/tests/advanced-magic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
166 changes: 101 additions & 65 deletions fullstack-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
Expand Down
Loading