diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 136d75897..63b45c5f6 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -9,5 +9,6 @@ RUN apt-get update && \ librocksdb-dev \ libsnappy-dev \ libunwind8-dev \ + jq \ && rm -rf /var/lib/apt/lists/* diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d553405f1..19140f7ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,9 +80,41 @@ jobs: rm -f ./out/Plugins/TokensTracker/RpcServer.dll rm -f ./out/Plugins/StateService/RpcServer.dll - name: Install dependencies - run: sudo apt-get install -y libleveldb-dev expect + run: sudo apt-get install -y libleveldb-dev expect jq - name: Run tests with expect run: expect ./.github/workflows/test-neo-cli-plugins.expect + - name: Start neo-cli with plugins + run: | + dotnet out/neo-cli.dll & + NEO_PID=$! + echo "NEO_PID=$NEO_PID" >> $GITHUB_ENV + + echo "Waiting for neo-cli RPC endpoint to become ready..." + ATTEMPTS=0 + MAX_ATTEMPTS=30 + SLEEP_SECONDS=2 + until curl -s -H "Content-Type: application/json" \ + -d '{"jsonrpc":"2.0","method":"getversion","params":[],"id":1}' \ + http://localhost:10332 | jq -e '.jsonrpc' >/dev/null 2>&1; do + ATTEMPTS=$((ATTEMPTS+1)) + if [ "$ATTEMPTS" -ge "$MAX_ATTEMPTS" ]; then + echo "neo-cli RPC endpoint did not become ready in time" + exit 1 + fi + sleep "$SLEEP_SECONDS" + done + echo "neo-cli RPC endpoint is ready." + - name: Test RPC calls + run: | + chmod +x ./.github/workflows/test-rpc-calls.sh + ./.github/workflows/test-rpc-calls.sh + - name: Stop neo-cli + if: always() + run: | + if [ -n "$NEO_PID" ]; then + kill "$NEO_PID" || true + wait "$NEO_PID" || true + fi Release: if: github.ref == 'refs/heads/master-n3' && github.repository == 'neo-project/neo-node' diff --git a/.github/workflows/test-rpc-calls.sh b/.github/workflows/test-rpc-calls.sh new file mode 100755 index 000000000..89349d5e5 --- /dev/null +++ b/.github/workflows/test-rpc-calls.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Test RPC server calls +RPC_URL="http://127.0.0.1:10332" + +echo "Testing RPC server consistency..." + +# Test 1: getversion +echo "Testing getversion..." +response=$(curl -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id": 1, "method": "getversion"}' $RPC_URL) +if [[ $? -ne 0 ]]; then + echo "Failed to call getversion" + exit 1 +fi +echo "getversion response: $response" + +# Check if response contains expected fields +if ! echo "$response" | jq -e '.result.tcpport' > /dev/null; then + echo "getversion response missing tcpport" + exit 1 +fi + +# Test 2: getbestblockhash +echo "Testing getbestblockhash..." +response=$(curl -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id": 2, "method": "getbestblockhash"}' $RPC_URL) +if [[ $? -ne 0 ]]; then + echo "Failed to call getbestblockhash" + exit 1 +fi +echo "getbestblockhash response: $response" + +# Should be a string hash +if ! echo "$response" | jq -e '.result | type == "string"' > /dev/null; then + echo "getbestblockhash response not a string" + exit 1 +fi + +# Test 3: getblockcount +echo "Testing getblockcount..." +response=$(curl -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id": 3, "method": "getblockcount"}' $RPC_URL) +if [[ $? -ne 0 ]]; then + echo "Failed to call getblockcount" + exit 1 +fi +echo "getblockcount response: $response" + +# Should be a number +if ! echo "$response" | jq -e '.result | type == "number"' > /dev/null; then + echo "getblockcount response not a number" + exit 1 +fi + +# Test 4: listplugins +echo "Testing listplugins..." +response=$(curl -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id": 4, "method": "listplugins"}' $RPC_URL) +if [[ $? -ne 0 ]]; then + echo "Failed to call listplugins" + exit 1 +fi +echo "listplugins response: $response" + +# Should be an array +if ! echo "$response" | jq -e '.result | type == "array"' > /dev/null; then + echo "listplugins response not an array" + exit 1 +fi + +# Check if RpcServer is in the list +if ! echo "$response" | jq -e '.result[] | select(.name == "RpcServer")' > /dev/null; then + echo "RpcServer not found in plugins list" + exit 1 +fi + +echo "All RPC tests passed!" \ No newline at end of file