-
Notifications
You must be signed in to change notification settings - Fork 224
testing some rpcserver calls #1016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master-n3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,5 +9,6 @@ RUN apt-get update && \ | |
| librocksdb-dev \ | ||
| libsnappy-dev \ | ||
| libunwind8-dev \ | ||
| jq \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Comment on lines
+10
to
+21
|
||
|
|
||
| # 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) | ||
|
Comment on lines
+10
to
+25
|
||
| 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!" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/.resultvalidation once and returns the parsed JSON for method-specific assertions.