Skip to content

Commit

Permalink
Connor/cli smoke test (#1196)
Browse files Browse the repository at this point in the history
* start script for smoke tests

* validate FULLNODE_API_INFO is set and use value

* stash

* getting output; RPC returning 0 code and not hitting endpoint

* formatting for individual tests

* attempted fixups

* line splitting for pretty-ness

* fix token errors

* cleanup

* cleanup and iterate over multiple endpoints

* figure out nuance with variable expansion

* error with http1 and using curl calls

* fix malformated JSON

* output

* its working and it looks good

* add balance to list for testing

* print http code

* color output and display results of tests

* remove unwrap call from wallet_api

* round out wallet smoke tests

* add smoke-test recipe to makefile

* add more endpoints

* smoke test documentation and state endpoints

* add state documentation

* use temp directory and setup with auth api-info

* wrong names for state api endpoints

* 500 is still a passing test

* add state_replay method

* No longer need to run forest; update docs
  • Loading branch information
connormullett authored Aug 6, 2021
1 parent 7d5b333 commit bf3936a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ test-release:
cargo test --release -p forest_message --features blst --no-default-features
cargo test --release -p forest_message --features pairing --no-default-features

smoke-test:
./scripts/smoke_test.sh

test-all: test-release run-vectors

# Checks if all headers are present and adds if not
Expand Down
23 changes: 23 additions & 0 deletions docs/SMOKE_TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# Running Smoke Tests for Forest's RPC API

## Prerequisites
The only requirement for running these smoke tests is that Forest is installed and on your system PATH.

## Running the Tests
* Use `make install` to create a binary on your path
* Run `make smoke-test`

This will execute a blank request to all endpoints listed defined and check the HTTP
status code of the response. If a response is received, this should be considered a good
test, even if an error has occured. No parameters are passed to the API endpoints.
An `OK` will be displayed if a test passes, and a `FAIL` will be displayed with an HTTP/curl code
if a test fails.

## Adding Future Endpoints
Endpoints in the script `./scripts/smoke_test.sh` are stored in an array identified as `RPC_ENDPOINTS`.

Add the endpoint identifier minus the prefix `Forest` to the module that it belongs to (ie gas, net, state, etc)
or add a new section if a new API is added.

This should be checked during the review process if new API methods are added to keep this script and test suite up to date.
6 changes: 5 additions & 1 deletion node/rpc/src/wallet_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ where
DB: BlockStore + Send + Sync + 'static,
B: Beacon + Send + Sync + 'static,
{
let key_info: wallet::KeyInfo = params.first().cloned().unwrap().into();
let key_info: wallet::KeyInfo = match params.first().cloned() {
Some(key_info) => key_info.into(),
None => return Err(JsonRpcError::INTERNAL_ERROR),
};

let key = Key::try_from(key_info)?;

let addr = format!("wallet-{}", key.address.to_string());
Expand Down
79 changes: 79 additions & 0 deletions scripts/smoke_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# set temporary configuration
FOREST_CONFIG="/tmp/temp_config.toml"
echo "encrypt_keystore=false" > $FOREST_CONFIG

# start forest daemon
RUST_LOG=off forest -c $FOREST_CONFIG > /dev/null &

# get token and multiaddr info
FULL_ADDR=$(forest -c $FOREST_CONFIG auth api-info -p admin)

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

# extract token from auth api-info output
TOKEN="$(cut -d':' -f1 <<< $FULL_ADDR)"
TOKEN=${TOKEN#"FULLNODE_API_INFO=\""}

# set headers for http requests
AUTH_HEADER="Authorization: Bearer ${TOKEN}"
CONTENT_TYPE_HEADER="Content-Type: application/json-rpc"

# Wallet
RPC_ENDPOINTS=("WalletList" "WalletBalance" "WalletDefaultAddress" "WalletExport" "WalletHas" "WalletImport" "WalletNew")
RPC_ENDPOINTS+=("WalletSetDefault" "WalletSign" "WalletVerify")

# Sync
RPC_ENDPOINTS+=("SyncCheckBad" "SyncMarkBad" "SyncState" "SyncSubmitBlock")

# Message Pool
RPC_ENDPOINTS+=("MpoolEstimateGasPrice" "MpoolGetNonce" "MpoolPending" "MpoolPush" "MpoolPushMessage" "MpoolSelect")

# Chain
RPC_ENDPOINTS+=("ChainGetMessage" "ChainReadObj" "ChainHasObj" "ChainGetBlockMessages" "ChainGetTipsetByHeight" "ChainGetGenesis")
RPC_ENDPOINTS+=("ChainHead" "ChainHeadSubscription" "ChainNotify" "ChainTipSetWeight" "ChainGetBlock" "ChainGetTipSet")
RPC_ENDPOINTS+=("ChainGetRandomnessFromTickets" "ChainGetRandomnessFromBeacon")

# Auth
RPC_ENDPOINTS+=("AuthNew" "AuthVerify")

# Net
RPC_ENDPOINTS+=("NetAddrsListen" "NetPeers" "NetConnect" "NetDisconnect")

# Common
RPC_ENDPOINTS+=("Version")

# Gas
RPC_ENDPOINTS+=("GasEstimateFeeCap" "GasEstimateGasPremium" "GasEstimateGasLimit" "GasEstimateMessageGas")

# State
RPC_ENDPOINTS+=("StateMinerSectors" "StateCall" "StateMinerDeadlines" "StateSectorPrecommitInfo" "StateMinerInfo")
RPC_ENDPOINTS+=("StateSectorGetInfo" "StateMinerProvingDeadline" "StateMinerFaults" "StateAllMinerFaults")
RPC_ENDPOINTS+=("StateMinerRecoveries" "StateMinerPartitions" "StateReplay" "StateNetworkName" "StateNetworkVersion")
RPC_ENDPOINTS+=("StateGetActor" "StateAccountKey" "StateLookupId" "StateMarketBalance" "StateMarketDeals")
RPC_ENDPOINTS+=("StateGetReceipt" "StateWaitMsg" "MinerCreateBlock" "StateMinerSectorAllocated" "StateMinerPreCommitDepositForPower")
RPC_ENDPOINTS+=("StateMinerInitialPledgeCollateral" "MinerGetBaseInfo")


# send requests programmatically
for endpoint in ${RPC_ENDPOINTS[@]}; do
METHOD="Filecoin.${endpoint}"
REQUEST_BODY="{\"jsonrpc\": \"2.0\", \"method\": \"$METHOD\", \"params\":[], \"id\": 0}"

RESPONSE_CODE=$(curl -w "%{http_code}" -s -o /dev/null -X POST -H "$CONTENT_TYPE_HEADER" -H "$AUTH_HEADER" -d "$REQUEST_BODY" http://127.0.0.1:1234/rpc/v0)

# a response is a response and considered a passing test
# we are not passing params to endpoints so some methods will fail due to lack of params
if [ $RESPONSE_CODE = '200' ] || [ $RESPONSE_CODE = '500' ]; then
echo -e "${METHOD} ${GREEN} OK ${NC}"
else
echo -e "${METHOD} ${RED} FAIL ${RESPONSE_CODE} ${NC}"
fi

done

# Kill forest daemon
ps -ef | grep forest | grep -v grep | awk '{print $2}' | xargs kill

0 comments on commit bf3936a

Please sign in to comment.