Skip to content

Commit

Permalink
Merge pull request #243 from cheqd/rest
Browse files Browse the repository at this point in the history
Add REST system tests
  • Loading branch information
Andrew Nikitin authored Dec 9, 2021
2 parents 74f0d84 + 5dd5771 commit 68ddd2b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ jobs:

- name: Run test net container
run: |
docker run -d --rm -p "26657:26657" cheqd-testnet
docker run -d --rm -p "26657:26657" -p "1317:1317" cheqd-testnet
bash tests/networks/wait_for_chain.sh
- name: Set up and run tests
Expand Down
4 changes: 4 additions & 0 deletions docker/single_image_testnet/gen_node_configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ echo "##### [Node 0] Set fee"

sed -i $sed_extension 's/minimum-gas-prices = ""/minimum-gas-prices = "25ncheq"/g' "$HOME/.cheqdnode/config/app.toml"

echo "##### [Node 0] Switch on REST API"

sed -i $sed_extension 's/enable = false/enable = true/g' "$HOME/.cheqdnode/config/app.toml"

echo "##### [Node 0] Adjust consensus timeouts"

sed -i $sed_extension 's/timeout_propose = "3s"/timeout_propose = "500ms"/g' "$HOME/.cheqdnode/config/config.toml"
Expand Down
2 changes: 1 addition & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
-I "proto" \
-I "$cosmos_sdk_dir/third_party/proto" \
-I "$cosmos_sdk_dir/proto" \
--grpc-gateway_out=logtostderr=true:. \
--grpc-gateway_out=logtostderr=true,allow_colon_final_segments=true:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

Expand Down
73 changes: 73 additions & 0 deletions tests/cli/tests/query_did_2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

# set -euox pipefail

# sed in macos requires extra argument

sed_extension=''
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sed_extension=''
elif [[ "$OSTYPE" == "darwin"* ]]; then
sed_extension='.orig'
fi

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "$SCRIPT_DIR/common.sh"


# Creating DID
ALICE_VER_KEY="$(cheqd-noded debug ed25519 random)"
ALICE_VER_PUB_BASE_64=$(echo "${ALICE_VER_KEY}" | jq -r ".pub_key_base_64")
ALICE_VER_PRIV_BASE_64=$(echo "${ALICE_VER_KEY}" | jq -r ".priv_key_base_64")
ALICE_VER_PUB_MULTIBASE_58=$(cheqd-noded debug encoding base64-multibase58 "${ALICE_VER_PUB_BASE_64}")

DID="did:cheqd:testnet:$(random_string)"
KEY_ID="${DID}#key1"

MSG_CREATE_DID='{
"id": "'${DID}'",
"verification_method": [{
"id": "'${KEY_ID}'",
"type": "Ed25519VerificationKey2020",
"controller": "'${DID}'",
"public_key_multibase": "'${ALICE_VER_PUB_MULTIBASE_58}'"
}],
"authentication": [
"'${KEY_ID}'"
]
}';

RESULT=$(cheqd-noded tx cheqd create-did "${MSG_CREATE_DID}" "${KEY_ID}" --ver-key "${ALICE_VER_PRIV_BASE_64}" \
--from "${BASE_ACCOUNT_1}" ${TX_PARAMS})

assert_tx_successful "$RESULT"


# Query DID
RESULT=$(curl http://localhost:1317/cheqd/cheqdnode/cheqd/did/"${DID}")

EXPECTED='{
"context":[],
"id":"'${DID}'",
"controller":[],
"verification_method":[
{
"id":"'${KEY_ID}'",
"type":"Ed25519VerificationKey2020",
"controller":"'${DID}'",
"public_key_jwk":[],
"public_key_multibase":"'${ALICE_VER_PUB_MULTIBASE_58}'"
}
],
"authentication":[
"'${KEY_ID}'"
],
"assertion_method":[],
"capability_invocation":[],
"capability_delegation":[],
"key_agreement":[],
"service":[],
"also_known_as":[]
}'

assert_json_eq "${EXPECTED}" "$(echo "$RESULT" | jq -r ".did")"
10 changes: 10 additions & 0 deletions tests/networks/local_node/gen_node_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ sed -i $sed_extension 's/minimum-gas-prices = ""/minimum-gas-prices = "25ncheq"/
cheqd-noded keys add "node_operator" --keyring-backend "test"
cheqd-noded add-genesis-account "node_operator" 20000000000000000ncheq --keyring-backend "test"

echo "##### [Node 0] Switch on REST API"

sed -i $sed_extension 's/enable = false/enable = true/g' "$HOME/.cheqdnode/config/app.toml"

echo "##### [Node 0] Adjust consensus timeouts"

sed -i $sed_extension 's/timeout_propose = "3s"/timeout_propose = "500ms"/g' "$HOME/.cheqdnode/config/config.toml"
sed -i $sed_extension 's/timeout_prevote = "1s"/timeout_prevote = "500ms"/g' "$HOME/.cheqdnode/config/config.toml"
sed -i $sed_extension 's/timeout_precommit = "1s"/timeout_precommit = "500ms"/g' "$HOME/.cheqdnode/config/config.toml"
sed -i $sed_extension 's/timeout_commit = "5s"/timeout_commit = "500ms"/g' "$HOME/.cheqdnode/config/config.toml"

echo "##### Adding test accounts to the genesis"

Expand Down

0 comments on commit 68ddd2b

Please sign in to comment.