testing some rpcserver calls#1016
Conversation
|
I plan to add new calls to RPCSever if we are moving this forward, maybe even diagnostic for genesis block, something like that. I believe it is a good way to ensure that key neo-node essential tools are working properly. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master-n3 #1016 +/- ##
==========================================
Coverage 43.73% 43.73%
==========================================
Files 274 274
Lines 15682 15682
Branches 1959 1959
==========================================
Hits 6859 6859
Misses 8461 8461
Partials 362 362 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a lightweight RPC-level integration check to the CI pipeline to validate that neo-cli starts correctly with plugins and that basic RpcServer JSON-RPC methods behave as expected.
Changes:
- Add a bash script that issues a small set of JSON-RPC calls (
getversion,getbestblockhash,getblockcount,listplugins) and validates response shapes. - Update the GitHub Actions workflow to install
jq, startneo-cliin the background, run the RPC script, and then stop the process. - Add
jqto the devcontainer image to support running the same checks in development environments.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
.github/workflows/test-rpc-calls.sh |
New script that performs and validates several JSON-RPC calls against a local RPC endpoint. |
.github/workflows/main.yml |
CI job updates to install jq, start/stop neo-cli, and execute the RPC test script. |
.devcontainer/Dockerfile |
Adds jq to the devcontainer dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 |
There was a problem hiding this comment.
The script only checks curl's exit code, but JSON-RPC failures typically come back as HTTP 200 with an .error object (curl still exits 0). This can lead to misleading failures (or passing checks against an empty/incorrect .result). Consider asserting .error == null (and .result exists) for each call before validating fields like .result.tcpport.
| 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) |
There was a problem hiding this comment.
All curl invocations use -s without timeouts/retries. If the node is slow to start or the port is unreachable, the job can hang for a long time and/or fail flakily. Consider adding -sS plus bounded timeouts (e.g., connect/max time) and retry/poll logic (or a dedicated readiness loop before the tests).
| # 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" |
There was a problem hiding this comment.
There is a lot of repeated curl + jq boilerplate across the individual RPC tests, which will make it harder to extend this script with more plugin RPC checks later. Consider introducing a small helper function (e.g., rpc_call method id) that performs the POST + .error/.result validation once and returns the parsed JSON for method-specific assertions.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The idea here is to add calls for RPCServer and other plugins in the future, making this integration tests for neo-node to test different plugins functionalities.
For now it can be enabled always. In the future we can trigger it on specific moments if it starts to become a problem.