From d78511103dc267fff6704e32c967ae09784de43d Mon Sep 17 00:00:00 2001 From: toktar Date: Tue, 7 Dec 2021 12:58:05 +0300 Subject: [PATCH 1/5] Add rest tests --- .github/workflows/node-ci.yml | 11 +++++- tests/rest/import_keys.sh | 28 ++++++++++++++ tests/rest/run_all.sh | 27 +++++++++++++ tests/rest/tests/common.sh | 52 +++++++++++++++++++++++++ tests/rest/tests/query_did.sh | 73 +++++++++++++++++++++++++++++++++++ 5 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 tests/rest/import_keys.sh create mode 100644 tests/rest/run_all.sh create mode 100644 tests/rest/tests/common.sh create mode 100644 tests/rest/tests/query_did.sh diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 32700f2c7..79f386394 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -312,11 +312,18 @@ 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 + - name: Set up and run CLI tests working-directory: tests/cli run: | bash import_keys.sh bash run_all.sh + + - name: Set up and run CLI+REST tests + working-directory: tests/rest + run: | + bash import_keys.sh + bash run_all.sh + \ No newline at end of file diff --git a/tests/rest/import_keys.sh b/tests/rest/import_keys.sh new file mode 100644 index 000000000..4cb17db8d --- /dev/null +++ b/tests/rest/import_keys.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -euox pipefail + +KEYRING_BACKEND="test" + +function import_key() { + ALIAS=${1} + MNEMONIC=${2} + + echo "Importing key: ${ALIAS}" + + if cheqd-noded keys show "${ALIAS}" --keyring-backend ${KEYRING_BACKEND} + then + echo "Key already exists" + return 0 + fi + + echo "Key doesn't exist" + echo "${MNEMONIC}" | cheqd-noded keys add "${ALIAS}" --keyring-backend ${KEYRING_BACKEND} --recover +} + +import_key "base_account_1" "sketch mountain erode window enact net enrich smoke claim kangaroo another visual write meat latin bacon pulp similar forum guilt father state erase bright" +import_key "base_account_2" "ugly dirt sorry girl prepare argue door man that manual glow scout bomb pigeon matter library transfer flower clown cat miss pluck drama dizzy" +import_key "base_vesting_account" "coach index fence broken very cricket someone casino dial truth fitness stay habit such three jump exotic spawn planet fragile walk enact angry great" +import_key "continous_vesting_account" "phone worry flame safe panther dirt picture pepper purchase tiny search theme issue genre orange merit stove spoil surface color garment mind chuckle image" +import_key "delayed_vesting_account" "pilot text keen deal economy donkey use artist divide foster walk pink breeze proud dish brown icon shaft infant level labor lift will tomorrow" +import_key "periodic_vesting_account" "want merge flame plate trouble moral submit wing whale sick meat lonely yellow lens enable oyster slight health vast weird radar mesh grab olive" diff --git a/tests/rest/run_all.sh b/tests/rest/run_all.sh new file mode 100644 index 000000000..a81da5670 --- /dev/null +++ b/tests/rest/run_all.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -euox pipefail + +function log() { + MESSAGE=$1 + + echo "*****************************************************************************************" + echo "* $MESSAGE" + echo "*****************************************************************************************" +} + +# Run all shell tests +TESTS=$(find tests -type f -not -name "common.sh") + +for TEST in ${TESTS} +do + log "Running $TEST" + + if bash "$TEST" + then + log "$TEST finished successfully" + else + log "$TEST failed" + exit 1 + fi +done diff --git a/tests/rest/tests/common.sh b/tests/rest/tests/common.sh new file mode 100644 index 000000000..0b6286daf --- /dev/null +++ b/tests/rest/tests/common.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +set -euox pipefail + +# Params +export RPC_URL="http://localhost:26657" +export CHAIN_ID="cheqd" +export GAS_PRICES="25ncheq" +export KEYRING_BACKEND="test" +export OUTPUT_FORMAT="json" + +export QUERY_PARAMS="--node ${RPC_URL} --output ${OUTPUT_FORMAT}" +export KEYS_PARAMS="--keyring-backend ${KEYRING_BACKEND} --output ${OUTPUT_FORMAT}" +export TX_PARAMS="--node ${RPC_URL} --keyring-backend ${KEYRING_BACKEND} --output ${OUTPUT_FORMAT} --chain-id ${CHAIN_ID} --gas-prices ${GAS_PRICES} --yes" + +# Accounts +export BASE_ACCOUNT_1="base_account_1" +export BASE_ACCOUNT_2="base_account_2" +export BASE_VESTING_ACCOUNT="base_vesting_account" +export CONTINOUS_VESTING_ACCOUNT="continous_vesting_account" +export DELAYED_VESTING_ACCOUNT="delayed_vesting_account" +export PERIODIC_VESTING_ACCOUNT="periodic_vesting_account" + +function random_string() { + echo $RANDOM | base64 | head -c 20 + return 0 +} + +function assert_eq() { + ACTUAL=$1 + EXPECTED=$2 + + if [[ "${ACTUAL}" != "${EXPECTED}" ]] + then + echo "Values are not equal. Actual: ${ACTUAL}, expected: ${EXPECTED}." + return 1 + fi + + return 0 +} + +function assert_json_eq() { + ACTUAL=$1 + EXPECTED=$2 + + assert_eq "$(echo "${ACTUAL}" | jq --sort-keys ".")" "$(echo "${EXPECTED}" | jq --sort-keys ".")" +} + +function assert_tx_successful() { + OUTPUT=$1 + assert_eq "$(echo "${OUTPUT}" | jq -r ".code")" "0" +} diff --git a/tests/rest/tests/query_did.sh b/tests/rest/tests/query_did.sh new file mode 100644 index 000000000..6f69e6f6c --- /dev/null +++ b/tests/rest/tests/query_did.sh @@ -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")" From fd6a99c94f32ec0730f674267852469e89bd431c Mon Sep 17 00:00:00 2001 From: toktar Date: Tue, 7 Dec 2021 15:21:00 +0300 Subject: [PATCH 2/5] Update gen_node_configs.sh --- docker/single_image_testnet/gen_node_configs.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/single_image_testnet/gen_node_configs.sh b/docker/single_image_testnet/gen_node_configs.sh index ff4450ec6..31e130940 100755 --- a/docker/single_image_testnet/gen_node_configs.sh +++ b/docker/single_image_testnet/gen_node_configs.sh @@ -27,6 +27,10 @@ echo "##### [Node 0] Setting fee" sed -i $sed_extension 's/minimum-gas-prices = ""/minimum-gas-prices = "25ncheq"/g' "$HOME/.cheqdnode/config/app.toml" +echo "##### [Node 0] Switching on REST API" + +sed -i $sed_extension 's/enable = false/enable = true/g' "$HOME/.cheqdnode/config/app.toml" + echo "##### [Validator operator] Generating key" cheqd-noded keys add alice --keyring-backend test From 32e9c218a4413f3ebde9e090721bdf9b6280c99f Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Tue, 7 Dec 2021 20:36:51 +0300 Subject: [PATCH 3/5] Move query test to cli dir --- .github/workflows/node-ci.yml | 9 +--- .../query_did.sh => cli/tests/query_did_2.sh} | 0 tests/rest/import_keys.sh | 28 ---------- tests/rest/run_all.sh | 27 ---------- tests/rest/tests/common.sh | 52 ------------------- 5 files changed, 1 insertion(+), 115 deletions(-) rename tests/{rest/tests/query_did.sh => cli/tests/query_did_2.sh} (100%) delete mode 100644 tests/rest/import_keys.sh delete mode 100644 tests/rest/run_all.sh delete mode 100644 tests/rest/tests/common.sh diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index cd967147f..f5ff5fedb 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -317,15 +317,8 @@ jobs: docker run -d --rm -p "26657:26657" -p "1317:1317" cheqd-testnet bash tests/networks/wait_for_chain.sh - - name: Set up and run CLI tests + - name: Set up and run tests working-directory: tests/cli run: | bash import_keys.sh bash run_all.sh - - - name: Set up and run CLI+REST tests - working-directory: tests/rest - run: | - bash import_keys.sh - bash run_all.sh - \ No newline at end of file diff --git a/tests/rest/tests/query_did.sh b/tests/cli/tests/query_did_2.sh similarity index 100% rename from tests/rest/tests/query_did.sh rename to tests/cli/tests/query_did_2.sh diff --git a/tests/rest/import_keys.sh b/tests/rest/import_keys.sh deleted file mode 100644 index 4cb17db8d..000000000 --- a/tests/rest/import_keys.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -euox pipefail - -KEYRING_BACKEND="test" - -function import_key() { - ALIAS=${1} - MNEMONIC=${2} - - echo "Importing key: ${ALIAS}" - - if cheqd-noded keys show "${ALIAS}" --keyring-backend ${KEYRING_BACKEND} - then - echo "Key already exists" - return 0 - fi - - echo "Key doesn't exist" - echo "${MNEMONIC}" | cheqd-noded keys add "${ALIAS}" --keyring-backend ${KEYRING_BACKEND} --recover -} - -import_key "base_account_1" "sketch mountain erode window enact net enrich smoke claim kangaroo another visual write meat latin bacon pulp similar forum guilt father state erase bright" -import_key "base_account_2" "ugly dirt sorry girl prepare argue door man that manual glow scout bomb pigeon matter library transfer flower clown cat miss pluck drama dizzy" -import_key "base_vesting_account" "coach index fence broken very cricket someone casino dial truth fitness stay habit such three jump exotic spawn planet fragile walk enact angry great" -import_key "continous_vesting_account" "phone worry flame safe panther dirt picture pepper purchase tiny search theme issue genre orange merit stove spoil surface color garment mind chuckle image" -import_key "delayed_vesting_account" "pilot text keen deal economy donkey use artist divide foster walk pink breeze proud dish brown icon shaft infant level labor lift will tomorrow" -import_key "periodic_vesting_account" "want merge flame plate trouble moral submit wing whale sick meat lonely yellow lens enable oyster slight health vast weird radar mesh grab olive" diff --git a/tests/rest/run_all.sh b/tests/rest/run_all.sh deleted file mode 100644 index a81da5670..000000000 --- a/tests/rest/run_all.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -set -euox pipefail - -function log() { - MESSAGE=$1 - - echo "*****************************************************************************************" - echo "* $MESSAGE" - echo "*****************************************************************************************" -} - -# Run all shell tests -TESTS=$(find tests -type f -not -name "common.sh") - -for TEST in ${TESTS} -do - log "Running $TEST" - - if bash "$TEST" - then - log "$TEST finished successfully" - else - log "$TEST failed" - exit 1 - fi -done diff --git a/tests/rest/tests/common.sh b/tests/rest/tests/common.sh deleted file mode 100644 index 0b6286daf..000000000 --- a/tests/rest/tests/common.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -set -euox pipefail - -# Params -export RPC_URL="http://localhost:26657" -export CHAIN_ID="cheqd" -export GAS_PRICES="25ncheq" -export KEYRING_BACKEND="test" -export OUTPUT_FORMAT="json" - -export QUERY_PARAMS="--node ${RPC_URL} --output ${OUTPUT_FORMAT}" -export KEYS_PARAMS="--keyring-backend ${KEYRING_BACKEND} --output ${OUTPUT_FORMAT}" -export TX_PARAMS="--node ${RPC_URL} --keyring-backend ${KEYRING_BACKEND} --output ${OUTPUT_FORMAT} --chain-id ${CHAIN_ID} --gas-prices ${GAS_PRICES} --yes" - -# Accounts -export BASE_ACCOUNT_1="base_account_1" -export BASE_ACCOUNT_2="base_account_2" -export BASE_VESTING_ACCOUNT="base_vesting_account" -export CONTINOUS_VESTING_ACCOUNT="continous_vesting_account" -export DELAYED_VESTING_ACCOUNT="delayed_vesting_account" -export PERIODIC_VESTING_ACCOUNT="periodic_vesting_account" - -function random_string() { - echo $RANDOM | base64 | head -c 20 - return 0 -} - -function assert_eq() { - ACTUAL=$1 - EXPECTED=$2 - - if [[ "${ACTUAL}" != "${EXPECTED}" ]] - then - echo "Values are not equal. Actual: ${ACTUAL}, expected: ${EXPECTED}." - return 1 - fi - - return 0 -} - -function assert_json_eq() { - ACTUAL=$1 - EXPECTED=$2 - - assert_eq "$(echo "${ACTUAL}" | jq --sort-keys ".")" "$(echo "${EXPECTED}" | jq --sort-keys ".")" -} - -function assert_tx_successful() { - OUTPUT=$1 - assert_eq "$(echo "${OUTPUT}" | jq -r ".code")" "0" -} From ed2c2e9ac40a4a12a0991df7ab19e6fde3a372c5 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Wed, 8 Dec 2021 13:45:59 +0300 Subject: [PATCH 4/5] Fix config script --- tests/networks/local_node/gen_node_config.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/networks/local_node/gen_node_config.sh b/tests/networks/local_node/gen_node_config.sh index e98be0ed0..1d3a3fd20 100755 --- a/tests/networks/local_node/gen_node_config.sh +++ b/tests/networks/local_node/gen_node_config.sh @@ -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" From 5e3c8d5c16e39c1f62213a9dca20791da824c36a Mon Sep 17 00:00:00 2001 From: toktar Date: Thu, 9 Dec 2021 00:58:06 +0300 Subject: [PATCH 5/5] Update protocgen.sh --- scripts/protocgen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index cadf77b2f..2e0420791 100644 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -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