From 1842b159f11c83a7403c30823e71b08569ecf37c Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 15:13:24 +0300 Subject: [PATCH 01/76] Introduce first ginkgo tests --- .github/workflows/build.yml | 4 +- .github/workflows/test.yml | 487 ++++++++++++++++-------------- x/cheqd/utils/crypto_test.go | 127 ++++---- x/cheqd/utils/utils_suite_test.go | 13 + 4 files changed, 343 insertions(+), 288 deletions(-) create mode 100644 x/cheqd/utils/utils_suite_test.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 35c41a0e2..14e3bfe82 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,8 +35,8 @@ jobs: name: cheqd-noded path: dist/**/cheqd-noded - - name: Run Golang unit tests - run: go test -v ./... + # - name: Run Golang unit tests + # run: go test -v ./... build-docker: name: "Docker image" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2fdf826c..3630f7b54 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,248 +15,267 @@ permissions: packages: read jobs: - - test-new-node-setup: - name: "New node setup" - runs-on: ubuntu-latest - env: - VERSION: ${{ inputs.VERSION }} - - steps: - - uses: actions/checkout@v3 - - - name: Install cheqd-noded binary - working-directory: ./tests/e2e-complex/interactive-install - run: sudo sh -c 'python3 ../../../installer/installer.py 1 < .answers' - - - name: Download node Docker image - uses: actions/download-artifact@v3 - with: - name: cheqd-node-image.tar - - - name: Load node Docker image - run: docker load -i cheqd-node-image.tar - - - name: Setup 4 Validators + 2 Observers Docker localnet - working-directory: ./docker/localnet - run: | - set -euo pipefail - bash gen-network-config.sh - CHEQD_NODE_IMAGE=cheqd-node DOCKER_IMAGE_VERSION=latest docker compose up -d - - - name: Check all Docker localnet nodes are active - run: | - set -euo pipefail - bash ./tests/tools/wait-for-chain.sh - - - name: Add an Observer node using Interactive installer - working-directory: ./tests/e2e-complex/interactive-install - run: | - set -euo pipefail - bash add-observer.sh - bash wait.sh "[[ $(cheqd-noded status -n 'tcp://localhost:26677' 2>&1 | wc -l) == 1 ]] && echo "Observer node is up"" - - - name: Promote Observer to Validator - working-directory: ./tests/e2e-complex/interactive-install - run: | - bash promote-validator.sh - bash check-promotion.sh - # shellcheck disable=SC2016 - bash wait.sh '[[ $(curl -s localhost:26657/block | sed -nr '"'"'s/.*signature": (.*?).*/\1/p'"'"' | wc -l) == 5 ]] && echo "There are 5 validators signatures in block!"' - # shellcheck disable=SC2016 - bash wait.sh '[[ $(curl -s localhost:26657/block | sed -nr '"'"'s/.*(signature": null).*/\1/p'"'"' | wc -l) == 0 ]] && echo "There are no null signatures in block!"' - - - name: Gather logs on failure - if: ${{ failure() }} - run: | - journalctl -ex | grep cheqd - - python-integration-tests: - name: "Python based Cosmos and identity tests" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Load node binary artifact - uses: actions/download-artifact@v3 - with: - name: cheqd-noded - path: /home/runner/.local/bin - - - name: Restore binary permissions - run: sudo chmod +x /home/runner/.local/bin/cheqd-noded - - - name: Download node Docker image - uses: actions/download-artifact@v3 - with: - name: cheqd-node-image.tar - - - name: Load node Docker image - run: docker load -i cheqd-node-image.tar - - - name: Setup 4 Validators + 2 Observers Docker localnet - working-directory: ./docker/localnet - run: | - bash gen-network-config.sh - CHEQD_NODE_IMAGE=cheqd-node DOCKER_IMAGE_VERSION=latest docker compose up -d - - - name: Check all Docker localnet nodes are active - run: bash tests/tools/wait-for-chain.sh - - - name: Setup Python environment - working-directory: ./tests/e2e-pytest - run: | - set -euo pipefail - pip3 install -r requirements.txt >> /dev/null - cp -Rf "${NODE_CONFIGS_BASE}"/validator-0/. /home/runner/.cheqdnode/ - cp -Rf "${NODE_CONFIGS_BASE}"/validator-1/. /home/runner/.cheqdnode/ - sudo chmod -R 775 /home/runner/ - - - name: Run Cosmos-related tests - working-directory: ./tests/e2e-pytest - run: | - set -euo pipefail - OP0_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" --home "${NODE_CONFIGS_BASE}/validator-0" | sed -nr 's/.*address: (.*?).*/\1/p' | sed 's/\r//g') - export OP0_ADDRESS - OP1_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" --home "${NODE_CONFIGS_BASE}/validator-1" | sed -nr 's/.*address: (.*?).*/\1/p' | sed 's/\r//g') - export OP1_ADDRESS - pytest -v -rP test_cosmos.py - - - name: Run identity-related tests # TODO: Move into separate stage? - working-directory: ./tests/e2e-pytest - run: | - set -euo pipefail - OP0_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" | sed -nr 's/.*address: (.*?).*/\1/p' | sed -n 1p | sed 's/\r//g') - export OP0_ADDRESS - OP1_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" | sed -nr 's/.*address: (.*?).*/\1/p' | sed -n 2p | sed 's/\r//g') - export OP1_ADDRESS - pytest -v -rP test_identity.py - - bash-integration-tests: - name: "Bash-based identity tests" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Load binary artifact - uses: actions/download-artifact@v3 - with: - name: cheqd-noded - path: /home/runner/.local/bin - - - name: Restore binary permissions - run: sudo chmod +x /home/runner/.local/bin/cheqd-noded - - - name: Download node Docker image - uses: actions/download-artifact@v3 - with: - name: cheqd-node-image.tar - - - name: Load node Docker image - run: docker load -i cheqd-node-image.tar - - - name: Setup 4 Validators + 2 Observers Docker localnet - working-directory: ./docker/localnet - run: | - bash gen-network-config.sh - CHEQD_NODE_IMAGE=cheqd-node DOCKER_IMAGE_VERSION=latest docker compose up -d - - - name: Check all Docker localnet nodes are active - run: bash ./tests/tools/wait-for-chain.sh - - - name: Import keys - working-directory: ./docker/localnet - run: | - bash import_keys.sh - - - name: Run tests - working-directory: ./tests/e2e-bash - run: | - bash run_all.sh - - node-upgrade-test: - name: "Run positive case for upgrade" + ginkgo-tests: + name: "Ginkgo-based unit tests" runs-on: ubuntu-latest - env: - VERSION: ${{ inputs.VERSION }} steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Download cheqd-cli Docker image - uses: actions/download-artifact@v3 + - uses: actions/setup-go@v3 with: - name: cheqd-node-image.tar - - - name: Load cheqd-cli Docker image - run: docker load -i cheqd-node-image.tar + go-version-file: ./go.mod + cache: true - - name: Give current user ownership - run: sudo chown "$USER":"$USER" . - - - name: Prepare nodes for upgrade - working-directory: ./tests/e2e-complex/upgrade - run: bash prepare.sh - - - name: Initiate upgrade - working-directory: ./tests/e2e-complex/upgrade - run: bash initiate_upgrade.sh - - - name: Check for successful upgrade - working-directory: ./tests/e2e-complex/upgrade - run: bash upgrade_and_check.sh - - node-cosmovisor-upgrade-test: - name: "Run positive case for upgrade with Cosmovisor installed" - runs-on: ubuntu-latest - env: - NODE_CONFIGS_BASE: "/home/runner/work/cheqd-node/cheqd-node/tests/e2e-complex/upgrade/node_configs" - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Download cheqd-cli Docker image - uses: actions/download-artifact@v3 - with: - name: cheqd-node-image.tar - - - name: Load cheqd-cli Docker image - run: docker load -i cheqd-node-image.tar - - - name: Install cheqd-noded binary - working-directory: ./tests/e2e-complex/upgrade/cosmovisor - run: sudo sh -c 'python3 ../../../../installer/installer.py 1 < .answers' - - - name: Give current user ownership - run: sudo chown "$USER":"$USER" . - - - name: Prepare nodes for upgrade - working-directory: ./tests/e2e-complex/upgrade - run: bash prepare.sh - - - name: Add observer with Cosmovisor - working-directory: ./tests/e2e-complex/upgrade/cosmovisor - run: bash add-observer.sh - - - name: Initiate upgrade - id: initiate-upgrade - working-directory: ./tests/e2e-complex/upgrade + - name: Install ginkgo run: | - START_HEIGHT=$(printf '%d' "$(cheqd-noded status 2>&1 | jq ".SyncInfo.latest_block_height" | tr -d '"')") - echo ::set-output name=START_HEIGHT::"$START_HEIGHT" - START_HEIGHT=$START_HEIGHT bash initiate_upgrade.sh + go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo + go get github.com/onsi/gomega/... - - name: Check for successful upgrade - working-directory: ./tests/e2e-complex/upgrade - run: START_HEIGHT=${{ steps.initiate-upgrade.outputs.START_HEIGHT }} bash upgrade_and_check.sh + - name: Run Ginkgo tests + run: ginkego -v ./... - - name: Check that node with Cosmovisor was upgraded - working-directory: ./tests/e2e-complex/upgrade/cosmovisor - run: START_HEIGHT=${{ steps.initiate-upgrade.outputs.START_HEIGHT }} bash check_upgrade.sh + # test-new-node-setup: + # name: "New node setup" + # runs-on: ubuntu-latest + # env: + # VERSION: ${{ inputs.VERSION }} + + # steps: + # - uses: actions/checkout@v3 + + # - name: Install cheqd-noded binary + # working-directory: ./tests/e2e-complex/interactive-install + # run: sudo sh -c 'python3 ../../../installer/installer.py 1 < .answers' + + # - name: Download node Docker image + # uses: actions/download-artifact@v3 + # with: + # name: cheqd-node-image.tar + + # - name: Load node Docker image + # run: docker load -i cheqd-node-image.tar + + # - name: Setup 4 Validators + 2 Observers Docker localnet + # working-directory: ./docker/localnet + # run: | + # set -euo pipefail + # bash gen-network-config.sh + # CHEQD_NODE_IMAGE=cheqd-node DOCKER_IMAGE_VERSION=latest docker compose up -d + + # - name: Check all Docker localnet nodes are active + # run: | + # set -euo pipefail + # bash ./tests/tools/wait-for-chain.sh + + # - name: Add an Observer node using Interactive installer + # working-directory: ./tests/e2e-complex/interactive-install + # run: | + # set -euo pipefail + # bash add-observer.sh + # bash wait.sh "[[ $(cheqd-noded status -n 'tcp://localhost:26677' 2>&1 | wc -l) == 1 ]] && echo "Observer node is up"" + + # - name: Promote Observer to Validator + # working-directory: ./tests/e2e-complex/interactive-install + # run: | + # bash promote-validator.sh + # bash check-promotion.sh + # # shellcheck disable=SC2016 + # bash wait.sh '[[ $(curl -s localhost:26657/block | sed -nr '"'"'s/.*signature": (.*?).*/\1/p'"'"' | wc -l) == 5 ]] && echo "There are 5 validators signatures in block!"' + # # shellcheck disable=SC2016 + # bash wait.sh '[[ $(curl -s localhost:26657/block | sed -nr '"'"'s/.*(signature": null).*/\1/p'"'"' | wc -l) == 0 ]] && echo "There are no null signatures in block!"' + + # - name: Gather logs on failure + # if: ${{ failure() }} + # run: | + # journalctl -ex | grep cheqd + + # python-integration-tests: + # name: "Python based Cosmos and identity tests" + # runs-on: ubuntu-latest + + # steps: + # - uses: actions/checkout@v3 + + # - name: Load node binary artifact + # uses: actions/download-artifact@v3 + # with: + # name: cheqd-noded + # path: /home/runner/.local/bin + + # - name: Restore binary permissions + # run: sudo chmod +x /home/runner/.local/bin/cheqd-noded + + # - name: Download node Docker image + # uses: actions/download-artifact@v3 + # with: + # name: cheqd-node-image.tar + + # - name: Load node Docker image + # run: docker load -i cheqd-node-image.tar + + # - name: Setup 4 Validators + 2 Observers Docker localnet + # working-directory: ./docker/localnet + # run: | + # bash gen-network-config.sh + # CHEQD_NODE_IMAGE=cheqd-node DOCKER_IMAGE_VERSION=latest docker compose up -d + + # - name: Check all Docker localnet nodes are active + # run: bash tests/tools/wait-for-chain.sh + + # - name: Setup Python environment + # working-directory: ./tests/e2e-pytest + # run: | + # set -euo pipefail + # pip3 install -r requirements.txt >> /dev/null + # cp -Rf "${NODE_CONFIGS_BASE}"/validator-0/. /home/runner/.cheqdnode/ + # cp -Rf "${NODE_CONFIGS_BASE}"/validator-1/. /home/runner/.cheqdnode/ + # sudo chmod -R 775 /home/runner/ + + # - name: Run Cosmos-related tests + # working-directory: ./tests/e2e-pytest + # run: | + # set -euo pipefail + # OP0_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" --home "${NODE_CONFIGS_BASE}/validator-0" | sed -nr 's/.*address: (.*?).*/\1/p' | sed 's/\r//g') + # export OP0_ADDRESS + # OP1_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" --home "${NODE_CONFIGS_BASE}/validator-1" | sed -nr 's/.*address: (.*?).*/\1/p' | sed 's/\r//g') + # export OP1_ADDRESS + # pytest -v -rP test_cosmos.py + + # - name: Run identity-related tests # TODO: Move into separate stage? + # working-directory: ./tests/e2e-pytest + # run: | + # set -euo pipefail + # OP0_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" | sed -nr 's/.*address: (.*?).*/\1/p' | sed -n 1p | sed 's/\r//g') + # export OP0_ADDRESS + # OP1_ADDRESS=$(cheqd-noded keys list --keyring-backend "test" | sed -nr 's/.*address: (.*?).*/\1/p' | sed -n 2p | sed 's/\r//g') + # export OP1_ADDRESS + # pytest -v -rP test_identity.py + + # bash-integration-tests: + # name: "Bash-based identity tests" + # runs-on: ubuntu-latest + + # steps: + # - uses: actions/checkout@v3 + + # - name: Load binary artifact + # uses: actions/download-artifact@v3 + # with: + # name: cheqd-noded + # path: /home/runner/.local/bin + + # - name: Restore binary permissions + # run: sudo chmod +x /home/runner/.local/bin/cheqd-noded + + # - name: Download node Docker image + # uses: actions/download-artifact@v3 + # with: + # name: cheqd-node-image.tar + + # - name: Load node Docker image + # run: docker load -i cheqd-node-image.tar + + # - name: Setup 4 Validators + 2 Observers Docker localnet + # working-directory: ./docker/localnet + # run: | + # bash gen-network-config.sh + # CHEQD_NODE_IMAGE=cheqd-node DOCKER_IMAGE_VERSION=latest docker compose up -d + + # - name: Check all Docker localnet nodes are active + # run: bash ./tests/tools/wait-for-chain.sh + + # - name: Import keys + # working-directory: ./docker/localnet + # run: | + # bash import_keys.sh + + # - name: Run tests + # working-directory: ./tests/e2e-bash + # run: | + # bash run_all.sh + + # node-upgrade-test: + # name: "Run positive case for upgrade" + # runs-on: ubuntu-latest + # env: + # VERSION: ${{ inputs.VERSION }} + + # steps: + # - uses: actions/checkout@v3 + # with: + # fetch-depth: 0 + + # - name: Download cheqd-cli Docker image + # uses: actions/download-artifact@v3 + # with: + # name: cheqd-node-image.tar + + # - name: Load cheqd-cli Docker image + # run: docker load -i cheqd-node-image.tar + + # - name: Give current user ownership + # run: sudo chown "$USER":"$USER" . + + # - name: Prepare nodes for upgrade + # working-directory: ./tests/e2e-complex/upgrade + # run: bash prepare.sh + + # - name: Initiate upgrade + # working-directory: ./tests/e2e-complex/upgrade + # run: bash initiate_upgrade.sh + + # - name: Check for successful upgrade + # working-directory: ./tests/e2e-complex/upgrade + # run: bash upgrade_and_check.sh + + # node-cosmovisor-upgrade-test: + # name: "Run positive case for upgrade with Cosmovisor installed" + # runs-on: ubuntu-latest + # env: + # NODE_CONFIGS_BASE: "/home/runner/work/cheqd-node/cheqd-node/tests/e2e-complex/upgrade/node_configs" + + # steps: + # - uses: actions/checkout@v3 + # with: + # fetch-depth: 0 + + # - name: Download cheqd-cli Docker image + # uses: actions/download-artifact@v3 + # with: + # name: cheqd-node-image.tar + + # - name: Load cheqd-cli Docker image + # run: docker load -i cheqd-node-image.tar + + # - name: Install cheqd-noded binary + # working-directory: ./tests/e2e-complex/upgrade/cosmovisor + # run: sudo sh -c 'python3 ../../../../installer/installer.py 1 < .answers' + + # - name: Give current user ownership + # run: sudo chown "$USER":"$USER" . + + # - name: Prepare nodes for upgrade + # working-directory: ./tests/e2e-complex/upgrade + # run: bash prepare.sh + + # - name: Add observer with Cosmovisor + # working-directory: ./tests/e2e-complex/upgrade/cosmovisor + # run: bash add-observer.sh + + # - name: Initiate upgrade + # id: initiate-upgrade + # working-directory: ./tests/e2e-complex/upgrade + # run: | + # START_HEIGHT=$(printf '%d' "$(cheqd-noded status 2>&1 | jq ".SyncInfo.latest_block_height" | tr -d '"')") + # echo ::set-output name=START_HEIGHT::"$START_HEIGHT" + # START_HEIGHT=$START_HEIGHT bash initiate_upgrade.sh + + # - name: Check for successful upgrade + # working-directory: ./tests/e2e-complex/upgrade + # run: START_HEIGHT=${{ steps.initiate-upgrade.outputs.START_HEIGHT }} bash upgrade_and_check.sh + + # - name: Check that node with Cosmovisor was upgraded + # working-directory: ./tests/e2e-complex/upgrade/cosmovisor + # run: START_HEIGHT=${{ steps.initiate-upgrade.outputs.START_HEIGHT }} bash check_upgrade.sh diff --git a/x/cheqd/utils/crypto_test.go b/x/cheqd/utils/crypto_test.go index c8feb4f08..fdd7afb75 100644 --- a/x/cheqd/utils/crypto_test.go +++ b/x/cheqd/utils/crypto_test.go @@ -1,60 +1,83 @@ -package utils +package utils_test import ( - "testing" + // "testing" "github.com/multiformats/go-multibase" - "github.com/stretchr/testify/require" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) -func TestValidateEd25519PubKey(t *testing.T) { - cases := []struct { - name string - key string - valid bool - errorMsg string - }{ - {"Valid: General Ed25519 public key", "zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX", true, ""}, - {"Valid: General Ed25519 public key", "zF1hVGXXK9rmx5HhMTpGnGQJiab9qr1111111111111", false, "ed25519: bad public key length: 31"}, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - _, keyBytes, _ := multibase.Decode(tc.key) - err := ValidateEd25519PubKey(keyBytes) - - if tc.valid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Contains(t, err.Error(), tc.errorMsg) - } +var _ = Describe("Utils", func() { + Describe("ValidateEd25519PubKey", func() { + Context("Valid: General Ed25519 public key", func() { + It("should return no error", func() { + _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX") + err := ValidateEd25519PubKey(keyBytes) + Expect(err).To(BeNil()) + }) }) - } -} - -func TestValidateJwk(t *testing.T) { - cases := []struct { - name string - key string - valid bool - errorMsg string - }{ - {"positive ed25519", "{\"crv\":\"Ed25519\",\"kty\":\"OKP\",\"x\":\"9Ov80OqMlNrILAUG8DBBlYQ1rUhp7wDomr2I5muzpTc\"}", true, ""}, - {"positive ecdsa", "{\"crv\":\"P-256\",\"kty\":\"EC\",\"x\":\"tcEgxIPyYMiyR2_Vh_YMYG6Grg7axhK2N8JjWta5C0g\",\"y\":\"imiXD9ahVA_MKY066TrNA9r6l35lRrerP6JRey5SryQ\"}", true, ""}, - {"positive rsa", "{\"e\":\"AQAB\",\"kty\":\"RSA\",\"n\":\"skKXRn44WN2DpXDwm4Ip25kIAGRA8y3iXlaoAhPmFiuSDkx97lXcJYrjxX0wSfehgCiSoZOBv6mFzgSVv0_pXQ6zI35xi2dsbexrc87m7Q24q2chpG33ttnVwQkoXrrm0zDzSX32EVxYQyTu9aWp-zxUdAWcrWUarT24RmgjU78v8JmUzkLmwbzsEImnIZ8Hce2ruisAmuAQBVVA4bWwQm_x1KPoQW-TP5_UR3gGugvf0XrQfMJaVpcxcJ9tduMUw6ffZOsqgbvAiZYnrezxSIjnd5lFTFBIEYdGR6ZgjYZoWvQB7U72o_TJoka-zfSODOUbxNBvxvFhA3uhoo3ZKw\"}", true, ""}, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := ValidateJWK(tc.key) - - if tc.valid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Contains(t, err.Error(), tc.errorMsg) - } + + Context("NotValid: Bad Ed25519 public key length", func() { + It("should return error", func() { + _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qr1111111111111") + err := ValidateEd25519PubKey(keyBytes) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("ed25519: bad public key length: 31")) + }) }) - } -} + }) +}) + +// func TestValidateEd25519PubKey(t *testing.T) { +// cases := []struct { +// name string +// key string +// valid bool +// errorMsg string +// }{ +// {"Valid: General Ed25519 public key", "zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX", true, ""}, +// {"Valid: General Ed25519 public key", "zF1hVGXXK9rmx5HhMTpGnGQJiab9qr1111111111111", false, "ed25519: bad public key length: 31"}, +// } + +// for _, tc := range cases { +// t.Run(tc.name, func(t *testing.T) { +// _, keyBytes, _ := multibase.Decode(tc.key) +// err := ValidateEd25519PubKey(keyBytes) + +// if tc.valid { +// require.NoError(t, err) +// } else { +// require.Error(t, err) +// require.Contains(t, err.Error(), tc.errorMsg) +// } +// }) +// } +// } + +// func TestValidateJwk(t *testing.T) { +// cases := []struct { +// name string +// key string +// valid bool +// errorMsg string +// }{ +// {"positive ed25519", "{\"crv\":\"Ed25519\",\"kty\":\"OKP\",\"x\":\"9Ov80OqMlNrILAUG8DBBlYQ1rUhp7wDomr2I5muzpTc\"}", true, ""}, +// {"positive ecdsa", "{\"crv\":\"P-256\",\"kty\":\"EC\",\"x\":\"tcEgxIPyYMiyR2_Vh_YMYG6Grg7axhK2N8JjWta5C0g\",\"y\":\"imiXD9ahVA_MKY066TrNA9r6l35lRrerP6JRey5SryQ\"}", true, ""}, +// {"positive rsa", "{\"e\":\"AQAB\",\"kty\":\"RSA\",\"n\":\"skKXRn44WN2DpXDwm4Ip25kIAGRA8y3iXlaoAhPmFiuSDkx97lXcJYrjxX0wSfehgCiSoZOBv6mFzgSVv0_pXQ6zI35xi2dsbexrc87m7Q24q2chpG33ttnVwQkoXrrm0zDzSX32EVxYQyTu9aWp-zxUdAWcrWUarT24RmgjU78v8JmUzkLmwbzsEImnIZ8Hce2ruisAmuAQBVVA4bWwQm_x1KPoQW-TP5_UR3gGugvf0XrQfMJaVpcxcJ9tduMUw6ffZOsqgbvAiZYnrezxSIjnd5lFTFBIEYdGR6ZgjYZoWvQB7U72o_TJoka-zfSODOUbxNBvxvFhA3uhoo3ZKw\"}", true, ""}, +// } + +// for _, tc := range cases { +// t.Run(tc.name, func(t *testing.T) { +// err := ValidateJWK(tc.key) + +// if tc.valid { +// require.NoError(t, err) +// } else { +// require.Error(t, err) +// require.Contains(t, err.Error(), tc.errorMsg) +// } +// }) +// } +// } diff --git a/x/cheqd/utils/utils_suite_test.go b/x/cheqd/utils/utils_suite_test.go new file mode 100644 index 000000000..c731605ec --- /dev/null +++ b/x/cheqd/utils/utils_suite_test.go @@ -0,0 +1,13 @@ +package utils_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "testing" +) + +func TestUtils(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Utils Suite") +} \ No newline at end of file From 92271e94990944cbd9878f1e19dbdc9d5a4142dd Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 15:18:54 +0300 Subject: [PATCH 02/76] Add go.mod changes --- go.mod | 9 ++++++--- go.sum | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 16610166f..1a42d535b 100644 --- a/go.mod +++ b/go.mod @@ -67,6 +67,7 @@ require ( github.com/gogo/gateway v1.1.0 // indirect github.com/golang/snappy v0.0.3 // indirect github.com/google/btree v1.0.0 // indirect + github.com/google/go-cmp v0.5.8 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect @@ -102,6 +103,8 @@ require ( github.com/mtibben/percent v0.2.1 // indirect github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect + github.com/onsi/ginkgo/v2 v2.1.4 // indirect + github.com/onsi/gomega v1.20.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect @@ -127,11 +130,11 @@ require ( github.com/zondax/hid v0.9.0 // indirect go.etcd.io/bbolt v1.3.6 // indirect golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect - golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect - golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect + golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect + golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect - google.golang.org/protobuf v1.28.0 // indirect + google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.4 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 621d895f6..c9c416b2b 100644 --- a/go.sum +++ b/go.sum @@ -368,6 +368,7 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -469,6 +470,7 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -776,12 +778,16 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= +github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= +github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q= +github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -1232,6 +1238,8 @@ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= +golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1372,6 +1380,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= @@ -1458,6 +1468,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1621,6 +1632,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 71598d16368e6a1d93db91287bdca2152b7f8203 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 15:39:07 +0300 Subject: [PATCH 03/76] Disable lint --- .github/workflows/dispatch.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 0aa8557d0..fcdc91294 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -7,13 +7,13 @@ concurrency: jobs: - call-lint: - name: "Lint" - uses: ./.github/workflows/lint.yml + # call-lint: + # name: "Lint" + # uses: ./.github/workflows/lint.yml call-build: name: "Build" - needs: call-lint + # needs: call-lint uses: ./.github/workflows/build.yml secrets: inherit From 979b2f25a379280ed6805937b497446555e0a61f Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 16:12:09 +0300 Subject: [PATCH 04/76] Enable tests --- .github/workflows/dispatch.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index fcdc91294..30eb541c8 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -17,10 +17,10 @@ jobs: uses: ./.github/workflows/build.yml secrets: inherit - # call-test: - # name: "Test" - # needs: call-build - # uses: ./.github/workflows/test.yml + call-test: + name: "Test" + needs: call-build + uses: ./.github/workflows/test.yml call-release: name: "Release" From 28a8637fd3b09d1a3902f7e948bc6d5b380dd457 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 16:46:50 +0300 Subject: [PATCH 05/76] Add tests with DescribeTable functionality --- .github/workflows/dispatch.yml | 2 +- .github/workflows/test.yml | 2 +- go.mod | 6 +- go.sum | 19 ++-- x/cheqd/utils/crypto_test.go | 2 +- x/cheqd/utils/did_url_test.go | 194 ++++++++++++++++++--------------- 6 files changed, 128 insertions(+), 97 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 30eb541c8..849d97413 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -24,7 +24,7 @@ jobs: call-release: name: "Release" - # needs: [call-test, call-build] + needs: [call-test, call-build] needs: call-build if: ${{ github.ref_protected == true }} uses: ./.github/workflows/release.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3630f7b54..ecfb30084 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: go get github.com/onsi/gomega/... - name: Run Ginkgo tests - run: ginkego -v ./... + run: ginkgo -v ./... # test-new-node-setup: # name: "New node setup" diff --git a/go.mod b/go.mod index 1a42d535b..f3e700d22 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,8 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/lestrrat-go/jwx v1.2.25 github.com/multiformats/go-multibase v0.1.1 + github.com/onsi/ginkgo v1.16.4 + github.com/onsi/gomega v1.20.0 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.5.0 @@ -103,8 +105,7 @@ require ( github.com/mtibben/percent v0.2.1 // indirect github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect - github.com/onsi/ginkgo/v2 v2.1.4 // indirect - github.com/onsi/gomega v1.20.0 // indirect + github.com/nxadm/tail v1.4.8 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect @@ -136,6 +137,7 @@ require ( golang.org/x/text v0.3.7 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.4 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect diff --git a/go.sum b/go.sum index c9c416b2b..14adf811f 100644 --- a/go.sum +++ b/go.sum @@ -368,7 +368,6 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -468,9 +467,9 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -778,14 +777,16 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q= github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= @@ -1051,6 +1052,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -1122,6 +1124,7 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210915214749-c084706c2272/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= @@ -1169,6 +1172,7 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1228,6 +1232,7 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211208012354-db4efeb81f4b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -1236,7 +1241,6 @@ golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= @@ -1367,6 +1371,7 @@ golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1375,10 +1380,11 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1468,7 +1474,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1630,7 +1636,6 @@ google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX7 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/x/cheqd/utils/crypto_test.go b/x/cheqd/utils/crypto_test.go index fdd7afb75..027d276be 100644 --- a/x/cheqd/utils/crypto_test.go +++ b/x/cheqd/utils/crypto_test.go @@ -9,7 +9,7 @@ import ( . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) -var _ = Describe("Utils", func() { +var _ = Describe("Crypto", func() { Describe("ValidateEd25519PubKey", func() { Context("Valid: General Ed25519 public key", func() { It("should return no error", func() { diff --git a/x/cheqd/utils/did_url_test.go b/x/cheqd/utils/did_url_test.go index 0d1f1e4df..bbea28e67 100644 --- a/x/cheqd/utils/did_url_test.go +++ b/x/cheqd/utils/did_url_test.go @@ -1,93 +1,117 @@ -package utils +package utils_test import ( - "testing" - - "github.com/stretchr/testify/require" + . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) -func TestIsDidURL(t *testing.T) { - cases := []struct { - name string - valid bool - didUrl string - }{ - // Path: all the possible symbols - {"Valid: the whole alphabet for path", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"}, - {"Valid: several paths", true, "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"}, - {"Valid: the whole alphabet with query", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"}, - {"Valid: the whole alphabet with query and fragment", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"}, - {"Valid: each possible symbols as a path", true, "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"}, - {"Valid: empty path", true, "did:cheqd:testnet:123456789abcdefg/"}, - // Query: all the possible variants - {"Valid: the whole alphabet for query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"}, - {"Valid: the whole alphabet for query and another query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"}, - // Fragment: - {"Valid: the whole alphabet for fragment", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"}, - {"Valid: the whole alphabet with query and apth", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"}, - {"Valid: only fragment", true, "did:cheqd:testnet:123456789abcdefg#fragment"}, - {"Valid: only query", true, "did:cheqd:testnet:123456789abcdefg?query"}, - // Wrong cases - {"Not valid: wrong HEXDIG for path (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path%20%zz"}, - {"Not valid: wrong HEXDIG for query (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query%20%zz"}, - {"Not valid: wrong HEXDIG for fragment (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query#fragment%20%zz"}, - // Wrong splitting (^did:([^:]+?)(:([^:]+?))?:([^:]+)$) - {"Not valid: starts with not 'did'", false, "did123:cheqd:::123456789abcdefg/path?query#fragment"}, - {"Not valid: empty namespace", false, "did:cheqd::123456789abcdefg/path?query#fragment"}, - {"Not valid: a lot of ':'", false, "did:cheqd:::123456789abcdefg/path?query#fragment"}, - {"Not valid: two DIDs in one", false, "did:cheqd:testnet:123456789abcdefg:did:cheqd:testnet:123456789abcdefg/path?query#fragment"}, - // Wrong namespace (^[a-zA-Z0-9]*) - {"Not valid: / - is not allowed for namespace", false, "did:cheqd:testnet/:123456789abcdefg/path?query#fragment"}, - {"Not valid: _ - is not allowed for namespace", false, "did:cheqd:testnet_:123456789abcdefg/path?query#fragment"}, - {"Not valid: % - is not allowed for namespace", false, "did:cheqd:testnet%:123456789abcdefg/path?query#fragment"}, - {"Not valid: * - is not allowed for namespace", false, "did:cheqd:testnet*:123456789abcdefg/path?query#fragment"}, - {"Not valid: & - is not allowed for namespace", false, "did:cheqd:testnet&:123456789abcdefg/path?query#fragment"}, - {"Not valid: @ - is not allowed for namespace", false, "did:cheqd:testnet@/:123456789abcdefg/path?query#fragment"}, - // Base58 checks (^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]*$) - {"Not valid: O - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefO/path?query#fragment"}, - {"Not valid: I - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefI/path?query#fragment"}, - {"Not valid: l - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefl/path?query#fragment"}, - {"Not valid: 0 - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdef0/path?query#fragment"}, - // Length checks (should be exactly 16 or 32) - {"Not valid: UniqueID less then 16 symbols", false, "did:cheqd:testnet:123/path?query#fragment"}, - {"Not valid: UniqueID more then 16 symbols but less then 32", false, "did:cheqd:testnet:123456789abcdefgABCDEF/path?query#fragment"}, - {"Not valid: UniqueID more then 32 symbols", false, "did:cheqd:testnet:123456789abcdefg123456789abcdefgABCDEF/path?query#fragment"}, - {"Not valid: Split should return error", false, "qwerty"}, - } +// func TestIsDidURL(t *testing.T) { +// cases := []struct { +// name string +// valid bool +// didUrl string +// }{ +// // Path: all the possible symbols +// {"Valid: the whole alphabet for path", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"}, +// {"Valid: several paths", true, "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"}, +// {"Valid: the whole alphabet with query", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"}, +// {"Valid: the whole alphabet with query and fragment", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"}, +// {"Valid: each possible symbols as a path", true, "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"}, +// {"Valid: empty path", true, "did:cheqd:testnet:123456789abcdefg/"}, +// // Query: all the possible variants +// {"Valid: the whole alphabet for query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"}, +// {"Valid: the whole alphabet for query and another query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"}, +// // Fragment: +// {"Valid: the whole alphabet for fragment", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"}, +// {"Valid: the whole alphabet with query and apth", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"}, +// {"Valid: only fragment", true, "did:cheqd:testnet:123456789abcdefg#fragment"}, +// {"Valid: only query", true, "did:cheqd:testnet:123456789abcdefg?query"}, +// // Wrong cases +// {"Not valid: wrong HEXDIG for path (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path%20%zz"}, +// {"Not valid: wrong HEXDIG for query (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query%20%zz"}, +// {"Not valid: wrong HEXDIG for fragment (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query#fragment%20%zz"}, +// // Wrong splitting (^did:([^:]+?)(:([^:]+?))?:([^:]+)$) +// {"Not valid: starts with not 'did'", false, "did123:cheqd:::123456789abcdefg/path?query#fragment"}, +// {"Not valid: empty namespace", false, "did:cheqd::123456789abcdefg/path?query#fragment"}, +// {"Not valid: a lot of ':'", false, "did:cheqd:::123456789abcdefg/path?query#fragment"}, +// {"Not valid: two DIDs in one", false, "did:cheqd:testnet:123456789abcdefg:did:cheqd:testnet:123456789abcdefg/path?query#fragment"}, +// // Wrong namespace (^[a-zA-Z0-9]*) +// {"Not valid: / - is not allowed for namespace", false, "did:cheqd:testnet/:123456789abcdefg/path?query#fragment"}, +// {"Not valid: _ - is not allowed for namespace", false, "did:cheqd:testnet_:123456789abcdefg/path?query#fragment"}, +// {"Not valid: % - is not allowed for namespace", false, "did:cheqd:testnet%:123456789abcdefg/path?query#fragment"}, +// {"Not valid: * - is not allowed for namespace", false, "did:cheqd:testnet*:123456789abcdefg/path?query#fragment"}, +// {"Not valid: & - is not allowed for namespace", false, "did:cheqd:testnet&:123456789abcdefg/path?query#fragment"}, +// {"Not valid: @ - is not allowed for namespace", false, "did:cheqd:testnet@/:123456789abcdefg/path?query#fragment"}, +// // Base58 checks (^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]*$) +// {"Not valid: O - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefO/path?query#fragment"}, +// {"Not valid: I - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefI/path?query#fragment"}, +// {"Not valid: l - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefl/path?query#fragment"}, +// {"Not valid: 0 - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdef0/path?query#fragment"}, +// // Length checks (should be exactly 16 or 32) +// {"Not valid: UniqueID less then 16 symbols", false, "did:cheqd:testnet:123/path?query#fragment"}, +// {"Not valid: UniqueID more then 16 symbols but less then 32", false, "did:cheqd:testnet:123456789abcdefgABCDEF/path?query#fragment"}, +// {"Not valid: UniqueID more then 32 symbols", false, "did:cheqd:testnet:123456789abcdefg123456789abcdefgABCDEF/path?query#fragment"}, +// {"Not valid: Split should return error", false, "qwerty"}, +// } + +// for _, tc := range cases { +// t.Run(tc.name, func(t *testing.T) { +// isDid := IsValidDIDUrl(tc.didUrl, "", []string{}) + +// if tc.valid { +// require.True(t, isDid) +// } else { +// require.False(t, isDid) +// } +// }) +// } +// } - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - isDid := IsValidDIDUrl(tc.didUrl, "", []string{}) +var _ = Describe("DID-URL tests", func() { + DescribeTable("Check the DID-URL join functionality (without functionality)", - if tc.valid { - require.True(t, isDid) - } else { - require.False(t, isDid) - } - }) - } -} + func(did_url string) { + did, path, query, fragment := MustSplitDIDUrl(did_url) + joined_did_url := JoinDIDUrl(did, path, query, fragment) + Expect(joined_did_url).To(Equal(did_url)) + }, + Entry("All symbols", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("All symbols for path", "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"), + Entry("All symbols for path and query", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"), + Entry("All symbols for path and query and fragment", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"), + Entry("All variants for path", "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"), + Entry("Empty path", "did:cheqd:testnet:123456789abcdefg/"), + Entry("All symbols for query", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("All symbols for query and a lot of queries", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"), + Entry("All symbols for fragment", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("All symbols for fragment and query", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("Just fragment", "did:cheqd:testnet:123456789abcdefg#fragment"), + Entry("Just query", "did:cheqd:testnet:123456789abcdefg?query"), + ) +}) -func TestDidURLJoin(t *testing.T) { - cases := []string{ - "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", - "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/", - "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query", - "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment", - "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff", - "did:cheqd:testnet:123456789abcdefg/", - "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?", - "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4", - "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", - "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?", - "did:cheqd:testnet:123456789abcdefg#fragment", - "did:cheqd:testnet:123456789abcdefg?query", - } +// func TestDidURLJoin(t *testing.T) { +// cases := []string{ +// "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", +// "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/", +// "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query", +// "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment", +// "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff", +// "did:cheqd:testnet:123456789abcdefg/", +// "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?", +// "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4", +// "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", +// "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?", +// "did:cheqd:testnet:123456789abcdefg#fragment", +// "did:cheqd:testnet:123456789abcdefg?query", +// } - for _, tc := range cases { - t.Run("split/join"+tc, func(t *testing.T) { - did, path, query, fragment := MustSplitDIDUrl(tc) - require.Equal(t, tc, JoinDIDUrl(did, path, query, fragment)) - }) - } -} +// for _, tc := range cases { +// t.Run("split/join"+tc, func(t *testing.T) { +// did, path, query, fragment := MustSplitDIDUrl(tc) +// require.Equal(t, tc, JoinDIDUrl(did, path, query, fragment)) +// }) +// } +// } From 2e9e5eb1bd5c2fa28d84e050192b082ecb90540d Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 16:50:16 +0300 Subject: [PATCH 06/76] Fix dispatch yml --- .github/workflows/dispatch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 849d97413..75e231fe5 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -25,7 +25,7 @@ jobs: call-release: name: "Release" needs: [call-test, call-build] - needs: call-build + # needs: call-build if: ${{ github.ref_protected == true }} uses: ./.github/workflows/release.yml secrets: inherit From 756c1051d69968caf5cf5b34e559b7dad72efb50 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 17:15:31 +0300 Subject: [PATCH 07/76] Fix ginko calling and add another couple of tests --- .github/workflows/test.yml | 2 +- x/cheqd/utils/did_url_test.go | 102 +++++++++++++++++++++++++--------- 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ecfb30084..f49c354d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: go get github.com/onsi/gomega/... - name: Run Ginkgo tests - run: ginkgo -v ./... + run: ginkgo -r --race --randomizeAllSpecs --randomizeSuites -v # test-new-node-setup: # name: "New node setup" diff --git a/x/cheqd/utils/did_url_test.go b/x/cheqd/utils/did_url_test.go index bbea28e67..1cd51e5f3 100644 --- a/x/cheqd/utils/did_url_test.go +++ b/x/cheqd/utils/did_url_test.go @@ -7,6 +7,79 @@ import ( . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) +var _ = Describe("DID-URL tests", func() { + DescribeTable("Check the DID-URL join functionality (without functionality)", + + func(did_url string) { + did, path, query, fragment := MustSplitDIDUrl(did_url) + joined_did_url := JoinDIDUrl(did, path, query, fragment) + Expect(joined_did_url).To(Equal(did_url)) + }, + Entry("All symbols", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("All symbols for path", "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"), + Entry("All symbols for path and query", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"), + Entry("All symbols for path and query and fragment", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"), + Entry("All variants for path", "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"), + Entry("Empty path", "did:cheqd:testnet:123456789abcdefg/"), + Entry("All symbols for query", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("All symbols for query and a lot of queries", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"), + Entry("All symbols for fragment", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("All symbols for fragment and query", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("Just fragment", "did:cheqd:testnet:123456789abcdefg#fragment"), + Entry("Just query", "did:cheqd:testnet:123456789abcdefg?query"), + ) + + DescribeTable("Check the DID-URL Validation", + + func(expected bool, did_url string) { + isValid := IsValidDIDUrl(did_url, "", []string{}) + + Expect(isValid).To(Equal(expected)) + }, + // Path: all the possible symbols + Entry("Valid: the whole alphabet for path", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("Valid: several paths", true, "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"), + Entry("Valid: the whole alphabet with query", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"), + Entry("Valid: the whole alphabet with query and fragment", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"), + Entry("Valid: each possible symbols as a path", true, "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"), + Entry("Valid: empty path", true, "did:cheqd:testnet:123456789abcdefg/"), + // Query: all the possible variants + Entry("Valid: the whole alphabet for query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("Valid: the whole alphabet for query and another query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"), + // Fragment: + Entry("Valid: the whole alphabet for fragment", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("Valid: the whole alphabet with query and apth", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("Valid: only fragment", true, "did:cheqd:testnet:123456789abcdefg#fragment"), + Entry("Valid: only query", true, "did:cheqd:testnet:123456789abcdefg?query"), + // Wrong cases + Entry("Not valid: wrong HEXDIG for path (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path%20%zz"), + Entry("Not valid: wrong HEXDIG for query (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query%20%zz"), + Entry("Not valid: wrong HEXDIG for fragment (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query#fragment%20%zz"), + // Wrong splitting (^did:([^:]+?)(:([^:]+?))?:([^:]+)$) + Entry("Not valid: starts with not 'did'", false, "did123:cheqd:::123456789abcdefg/path?query#fragment"), + Entry("Not valid: empty namespace", false, "did:cheqd::123456789abcdefg/path?query#fragment"), + Entry("Not valid: a lot of ':'", false, "did:cheqd:::123456789abcdefg/path?query#fragment"), + Entry("Not valid: two DIDs in one", false, "did:cheqd:testnet:123456789abcdefg:did:cheqd:testnet:123456789abcdefg/path?query#fragment"), + // Wrong namespace (^[a-zA-Z0-9]*) + Entry("Not valid: / - is not allowed for namespace", false, "did:cheqd:testnet/:123456789abcdefg/path?query#fragment"), + Entry("Not valid: _ - is not allowed for namespace", false, "did:cheqd:testnet_:123456789abcdefg/path?query#fragment"), + Entry("Not valid: % - is not allowed for namespace", false, "did:cheqd:testnet%:123456789abcdefg/path?query#fragment"), + Entry("Not valid: * - is not allowed for namespace", false, "did:cheqd:testnet*:123456789abcdefg/path?query#fragment"), + Entry("Not valid: & - is not allowed for namespace", false, "did:cheqd:testnet&:123456789abcdefg/path?query#fragment"), + Entry("Not valid: @ - is not allowed for namespace", false, "did:cheqd:testnet@/:123456789abcdefg/path?query#fragment"), + // Base58 checks (^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]*$) + Entry("Not valid: O - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefO/path?query#fragment"), + Entry("Not valid: I - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefI/path?query#fragment"), + Entry("Not valid: l - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefl/path?query#fragment"), + Entry("Not valid: 0 - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdef0/path?query#fragment"), + // Length checks (should be exactly 16 or 32) + Entry("Not valid: UniqueID less then 16 symbols", false, "did:cheqd:testnet:123/path?query#fragment"), + Entry("Not valid: UniqueID more then 16 symbols but less then 32", false, "did:cheqd:testnet:123456789abcdefgABCDEF/path?query#fragment"), + Entry("Not valid: UniqueID more then 32 symbols", false, "did:cheqd:testnet:123456789abcdefg123456789abcdefgABCDEF/path?query#fragment"), + Entry("Not valid: Split should return error", false, "qwerty"), + ) +}) + // func TestIsDidURL(t *testing.T) { // cases := []struct { // name string @@ -69,31 +142,8 @@ import ( // } // } -var _ = Describe("DID-URL tests", func() { - DescribeTable("Check the DID-URL join functionality (without functionality)", - - func(did_url string) { - did, path, query, fragment := MustSplitDIDUrl(did_url) - joined_did_url := JoinDIDUrl(did, path, query, fragment) - Expect(joined_did_url).To(Equal(did_url)) - }, - Entry("All symbols", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), - Entry("All symbols for path", "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"), - Entry("All symbols for path and query", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"), - Entry("All symbols for path and query and fragment", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"), - Entry("All variants for path", "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"), - Entry("Empty path", "did:cheqd:testnet:123456789abcdefg/"), - Entry("All symbols for query", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), - Entry("All symbols for query and a lot of queries", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"), - Entry("All symbols for fragment", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), - Entry("All symbols for fragment and query", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), - Entry("Just fragment", "did:cheqd:testnet:123456789abcdefg#fragment"), - Entry("Just query", "did:cheqd:testnet:123456789abcdefg?query"), - ) -}) - -// func TestDidURLJoin(t *testing.T) { -// cases := []string{ +// func TestDidURLJoin(t *testing.T) Entry("", +// cases := []stringEntry("", // "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", // "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/", // "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query", @@ -108,7 +158,7 @@ var _ = Describe("DID-URL tests", func() { // "did:cheqd:testnet:123456789abcdefg?query", // } -// for _, tc := range cases { +// for _, tc := range cases Entry("", // t.Run("split/join"+tc, func(t *testing.T) { // did, path, query, fragment := MustSplitDIDUrl(tc) // require.Equal(t, tc, JoinDIDUrl(did, path, query, fragment)) From 10e9c9f3c1dc9f99de328cbc033e666c82220d5e Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 17:50:26 +0300 Subject: [PATCH 08/76] Get rid of depricated options --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f49c354d8..9b00e17c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: go get github.com/onsi/gomega/... - name: Run Ginkgo tests - run: ginkgo -r --race --randomizeAllSpecs --randomizeSuites -v + run: ginkgo -r --race --randomize-all --randomize-suites -v # test-new-node-setup: # name: "New node setup" From e66736bb9e7889a68a9b7b21a7d41fbccb5341e6 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 17 Aug 2022 18:27:48 +0300 Subject: [PATCH 09/76] Move to v2 for ginkgo --- go.mod | 4 +++ go.sum | 15 +++------ x/cheqd/utils/crypto_test.go | 10 +++--- x/cheqd/utils/did_url_test.go | 53 +++++++++++++++---------------- x/cheqd/utils/utils_suite_test.go | 4 +-- 5 files changed, 42 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index f3e700d22..4aff31ac2 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( github.com/go-kit/log v0.2.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/gateway v1.1.0 // indirect @@ -71,6 +72,7 @@ require ( github.com/google/btree v1.0.0 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/google/orderedcode v0.0.1 // indirect + github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect @@ -106,6 +108,7 @@ require ( github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect github.com/nxadm/tail v1.4.8 // indirect + github.com/onsi/ginkgo/v2 v2.1.4 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect @@ -135,6 +138,7 @@ require ( golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect + golang.org/x/tools v0.1.10 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.4 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect diff --git a/go.sum b/go.sum index 14adf811f..86db6d4ec 100644 --- a/go.sum +++ b/go.sum @@ -368,6 +368,7 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -467,9 +468,9 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -777,15 +778,15 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= -github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q= github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= @@ -1052,7 +1053,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -1124,7 +1124,6 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210915214749-c084706c2272/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= @@ -1172,7 +1171,6 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1232,7 +1230,6 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211208012354-db4efeb81f4b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -1371,7 +1368,6 @@ golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1380,10 +1376,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= @@ -1474,6 +1468,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/x/cheqd/utils/crypto_test.go b/x/cheqd/utils/crypto_test.go index 027d276be..d29055a26 100644 --- a/x/cheqd/utils/crypto_test.go +++ b/x/cheqd/utils/crypto_test.go @@ -3,25 +3,25 @@ package utils_test import ( // "testing" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" "github.com/multiformats/go-multibase" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) var _ = Describe("Crypto", func() { Describe("ValidateEd25519PubKey", func() { Context("Valid: General Ed25519 public key", func() { It("should return no error", func() { - _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX") + _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX") err := ValidateEd25519PubKey(keyBytes) Expect(err).To(BeNil()) }) }) - + Context("NotValid: Bad Ed25519 public key length", func() { It("should return error", func() { - _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qr1111111111111") + _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qr1111111111111") err := ValidateEd25519PubKey(keyBytes) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("ed25519: bad public key length: 31")) diff --git a/x/cheqd/utils/did_url_test.go b/x/cheqd/utils/did_url_test.go index 1cd51e5f3..6946f7f40 100644 --- a/x/cheqd/utils/did_url_test.go +++ b/x/cheqd/utils/did_url_test.go @@ -1,41 +1,40 @@ package utils_test import ( - . "github.com/onsi/ginkgo/extensions/table" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" . "github.com/cheqd/cheqd-node/x/cheqd/utils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) var _ = Describe("DID-URL tests", func() { DescribeTable("Check the DID-URL join functionality (without functionality)", - func(did_url string) { - did, path, query, fragment := MustSplitDIDUrl(did_url) - joined_did_url := JoinDIDUrl(did, path, query, fragment) - Expect(joined_did_url).To(Equal(did_url)) - }, - Entry("All symbols", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), - Entry("All symbols for path", "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"), - Entry("All symbols for path and query", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"), - Entry("All symbols for path and query and fragment", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"), - Entry("All variants for path", "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"), - Entry("Empty path", "did:cheqd:testnet:123456789abcdefg/"), - Entry("All symbols for query", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), - Entry("All symbols for query and a lot of queries", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"), - Entry("All symbols for fragment", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), - Entry("All symbols for fragment and query", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), - Entry("Just fragment", "did:cheqd:testnet:123456789abcdefg#fragment"), - Entry("Just query", "did:cheqd:testnet:123456789abcdefg?query"), + func(did_url string) { + did, path, query, fragment := MustSplitDIDUrl(did_url) + joined_did_url := JoinDIDUrl(did, path, query, fragment) + Expect(joined_did_url).To(Equal(did_url)) + }, + Entry("All symbols", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("All symbols for path", "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"), + Entry("All symbols for path and query", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"), + Entry("All symbols for path and query and fragment", "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"), + Entry("All variants for path", "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"), + Entry("Empty path", "did:cheqd:testnet:123456789abcdefg/"), + Entry("All symbols for query", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("All symbols for query and a lot of queries", "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"), + Entry("All symbols for fragment", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), + Entry("All symbols for fragment and query", "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"), + Entry("Just fragment", "did:cheqd:testnet:123456789abcdefg#fragment"), + Entry("Just query", "did:cheqd:testnet:123456789abcdefg?query"), ) DescribeTable("Check the DID-URL Validation", - func(expected bool, did_url string) { - isValid := IsValidDIDUrl(did_url, "", []string{}) + func(expected bool, did_url string) { + isValid := IsValidDIDUrl(did_url, "", []string{}) - Expect(isValid).To(Equal(expected)) - }, + Expect(isValid).To(Equal(expected)) + }, // Path: all the possible symbols Entry("Valid: the whole alphabet for path", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"), Entry("Valid: several paths", true, "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"), @@ -142,8 +141,8 @@ var _ = Describe("DID-URL tests", func() { // } // } -// func TestDidURLJoin(t *testing.T) Entry("", -// cases := []stringEntry("", +// func TestDidURLJoin(t *testing.T) Entry("", +// cases := []stringEntry("", // "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", // "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/", // "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query", @@ -158,7 +157,7 @@ var _ = Describe("DID-URL tests", func() { // "did:cheqd:testnet:123456789abcdefg?query", // } -// for _, tc := range cases Entry("", +// for _, tc := range cases Entry("", // t.Run("split/join"+tc, func(t *testing.T) { // did, path, query, fragment := MustSplitDIDUrl(tc) // require.Equal(t, tc, JoinDIDUrl(did, path, query, fragment)) diff --git a/x/cheqd/utils/utils_suite_test.go b/x/cheqd/utils/utils_suite_test.go index c731605ec..feade1121 100644 --- a/x/cheqd/utils/utils_suite_test.go +++ b/x/cheqd/utils/utils_suite_test.go @@ -1,7 +1,7 @@ package utils_test import ( - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "testing" @@ -10,4 +10,4 @@ import ( func TestUtils(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Utils Suite") -} \ No newline at end of file +} From 7454e88a39208ed2e83fec07b3f961dbfdb310b3 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 23 Aug 2022 12:23:41 +0300 Subject: [PATCH 10/76] Another portion of tests with ginkgo --- x/cheqd/utils/did_test.go | 181 +++++++++++++--------------- x/cheqd/utils/did_url_test.go | 86 -------------- x/cheqd/utils/encoding_test.go | 112 +++++++----------- x/cheqd/utils/proto_test.go | 19 ++- x/cheqd/utils/str_test.go | 208 +++++++++++++++------------------ 5 files changed, 227 insertions(+), 379 deletions(-) diff --git a/x/cheqd/utils/did_test.go b/x/cheqd/utils/did_test.go index 39bad227a..13186fd49 100644 --- a/x/cheqd/utils/did_test.go +++ b/x/cheqd/utils/did_test.go @@ -1,123 +1,100 @@ -package utils +package utils_test import ( - "testing" - - "github.com/stretchr/testify/require" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) -func TestIsId(t *testing.T) { - cases := []struct { - valid bool - id string - }{ - {true, "123456789abcdefg"}, - {true, "123456789abcdefg123456789abcdefg"}, - {true, "3b9b8eec-5b5d-4382-86d8-9185126ff130"}, - {false, "sdf"}, - {false, "sdf:sdf"}, - {false, "12345"}, - } +var _ = Describe("DID checks", func() { + DescribeTable("Check is valid ID (for example did:cheqD:testnet:123456789abcdefg and ID is 123456789abcdefg)", - for _, tc := range cases { - t.Run(tc.id, func(t *testing.T) { - isDid := IsValidID(tc.id) + func(expected bool, did string) { + Expect(IsValidID(did)).To(Equal(expected)) + }, + Entry("Valid base58, 16 symbols", true, "123456789abcdefg"), + Entry("Valid base58, 32 symbols", true, "123456789abcdefg123456789abcdefg"), + Entry("Valid UUID", true, "3b9b8eec-5b5d-4382-86d8-9185126ff130"), + Entry("Not valid, not base58 symbols", false, "12345678abcdIlO0"), + Entry("Not valid, length", false, "sdf"), + Entry("Not valid, length and format", false, "sdf:sdf"), + Entry("Not valid, length", false, "12345"), + ) - if tc.valid { - require.True(t, isDid) - } else { - require.False(t, isDid) - } - }) - } -} + DescribeTable("DID validation", -func TestIsDid(t *testing.T) { - cases := []struct { - name string - valid bool - did string - method string - allowedNS []string - }{ - {"Valid: Inputs: Method and namespace are set", true, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"testnet"}}, - {"Valid: Inputs: Method and namespaces are set", true, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"testnet", "mainnet"}}, - {"Valid: Inputs: Method not set", true, "did:cheqd:testnet:123456789abcdefg", "", []string{"testnet"}}, - {"Valid: Inputs: Method and namespaces are empty", true, "did:cheqd:testnet:123456789abcdefg", "", []string{}}, - {"Valid: Namespace is absent in DID", true, "did:cheqd:123456789abcdefg", "", []string{}}, + func(expected bool, did string, method string, allowedNamespaces []string) { + Expect(IsValidDID(did, method, allowedNamespaces)).To(Equal(expected)) + }, + + Entry("Valid: Inputs: Method and namespace are set", true, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"testnet"}), + Entry("Valid: Inputs: Method and namespaces are set", true, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"testnet", "mainnet"}), + Entry("Valid: Inputs: Method not set", true, "did:cheqd:testnet:123456789abcdefg", "", []string{"testnet"}), + Entry("Valid: Inputs: Method and namespaces are empty", true, "did:cheqd:testnet:123456789abcdefg", "", []string{}), + Entry("Valid: Namespace is absent in DID", true, "did:cheqd:123456789abcdefg", "", []string{}), // Generic method validation - {"Valid: Inputs: Method is not set and passed for NOTcheqd", true, "did:NOTcheqd:123456789abcdefg", "", []string{}}, - {"Valid: Inputs: Method and Namespaces are not set and passed for NOTcheqd", true, "did:NOTcheqd:123456789abcdefg123456789abcdefg", "", []string{}}, + Entry("Valid: Inputs: Method is not set and passed for NOTcheqd", true, "did:NOTcheqd:123456789abcdefg", "", []string{}), + Entry("Valid: Inputs: Method and Namespaces are not set and passed for NOTcheqd", true, "did:NOTcheqd:123456789abcdefg123456789abcdefg", "", []string{}), - {"Valid: Inputs: Order of namespaces changed", true, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"mainnet", "testnet"}}, + Entry("Valid: Inputs: Order of namespaces changed", true, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"mainnet", "testnet"}), // Wrong splitting (^did:([^:]+?)(:([^:]+?))?:([^:]+)$) - {"Not valid: DID is not started from 'did'", false, "did123:cheqd:::123456789abcdefg", "cheqd", []string{"testnet"}}, - {"Not valid: empty namespace", false, "did:cheqd::123456789abcdefg", "cheqd", []string{"testnet"}}, - {"Not valid: a lot of ':'", false, "did:cheqd:::123456789abcdefg", "cheqd", []string{"testnet"}}, - {"Not valid: several DIDs in one string", false, "did:cheqd:testnet:123456789abcdefg:did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"testnet"}}, + Entry("Not valid: DID is not started from 'did'", false, "did123:cheqd:::123456789abcdefg", "cheqd", []string{"testnet"}), + Entry("Not valid: empty namespace", false, "did:cheqd::123456789abcdefg", "cheqd", []string{"testnet"}), + Entry("Not valid: a lot of ':'", false, "did:cheqd:::123456789abcdefg", "cheqd", []string{"testnet"}), + Entry("Not valid: several DIDs in one string", false, "did:cheqd:testnet:123456789abcdefg:did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"testnet"}), // Wrong method - {"Not valid: method in DID is not the same as from Inputs", false, "did:NOTcheqd:testnet:123456789abcdefg", "cheqd", []string{"mainnet", "testnet"}}, - {"Not valid: method in Inputs is not the same as from DID", false, "did:cheqd:testnet:123456789abcdefg", "NOTcheqd", []string{"mainnet", "testnet"}}, + Entry("Not valid: method in DID is not the same as from Inputs", false, "did:NOTcheqd:testnet:123456789abcdefg", "cheqd", []string{"mainnet", "testnet"}), + Entry("Not valid: method in Inputs is not the same as from DID", false, "did:cheqd:testnet:123456789abcdefg", "NOTcheqd", []string{"mainnet", "testnet"}), // Wrong namespace (^[a-zA-Z0-9]*) - {"Not valid: / is not allowed for namespace", false, "did:cheqd:testnet/:123456789abcdefg", "cheqd", []string{}}, - {"Not valid: _ is not allowed for namespace", false, "did:cheqd:testnet_:123456789abcdefg", "cheqd", []string{}}, - {"Not valid: % is not allowed for namespace", false, "did:cheqd:testnet%:123456789abcdefg", "cheqd", []string{}}, - {"Not valid: * is not allowed for namespace", false, "did:cheqd:testnet*:123456789abcdefg", "cheqd", []string{}}, - {"Not valid: & is not allowed for namespace", false, "did:cheqd:testnet&:123456789abcdefg", "cheqd", []string{}}, - {"Not valid: @ is not allowed for namespace", false, "did:cheqd:testnet@:123456789abcdefg", "cheqd", []string{}}, - {"Not valid: namespace from Inputs is not the same as from DID", false, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"not_testnet"}}, + Entry("Not valid: / is not allowed for namespace", false, "did:cheqd:testnet/:123456789abcdefg", "cheqd", []string{}), + Entry("Not valid: _ is not allowed for namespace", false, "did:cheqd:testnet_:123456789abcdefg", "cheqd", []string{}), + Entry("Not valid: % is not allowed for namespace", false, "did:cheqd:testnet%:123456789abcdefg", "cheqd", []string{}), + Entry("Not valid: * is not allowed for namespace", false, "did:cheqd:testnet*:123456789abcdefg", "cheqd", []string{}), + Entry("Not valid: & is not allowed for namespace", false, "did:cheqd:testnet&:123456789abcdefg", "cheqd", []string{}), + Entry("Not valid: @ is not allowed for namespace", false, "did:cheqd:testnet@:123456789abcdefg", "cheqd", []string{}), + Entry("Not valid: namespace from Inputs is not the same as from DID", false, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"not_testnet"}), // Base58 checks (^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]*$) - {"Not valid: O - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdefO", "cheqd", []string{}}, - {"Not valid: I - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdefI", "cheqd", []string{}}, - {"Not valid: l - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdefl", "cheqd", []string{}}, - {"Not valid: 0 - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdef0", "cheqd", []string{}}, + Entry("Not valid: O - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdefO", "cheqd", []string{}), + Entry("Not valid: I - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdefI", "cheqd", []string{}), + Entry("Not valid: l - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdefl", "cheqd", []string{}), + Entry("Not valid: 0 - is not allowed for UniqueID", false, "did:cheqd:testnet:123456789abcdef0", "cheqd", []string{}), // Length checks (should be exactly 16 or 32) - {"Not valid: UniqueID less then 16 symbols", false, "did:cheqd:testnet:123", "cheqd", []string{}}, - {"Not valid: UniqueID more then 16 symbols but less then 32", false, "did:cheqd:testnet:123456789abcdefgABCDEF", "cheqd", []string{}}, - {"Not valid: UniqueID more then 32 symbols", false, "did:cheqd:testnet:123456789abcdefg123456789abcdefgABCDEF", "cheqd", []string{}}, - } + Entry("Not valid: UniqueID less then 16 symbols", false, "did:cheqd:testnet:123", "cheqd", []string{}), + Entry("Not valid: UniqueID more then 16 symbols but less then 32", false, "did:cheqd:testnet:123456789abcdefgABCDEF", "cheqd", []string{}), + Entry("Not valid: UniqueID more then 32 symbols", false, "did:cheqd:testnet:123456789abcdefg123456789abcdefgABCDEF", "cheqd", []string{}), + ) - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - isDid := IsValidDID(tc.did, tc.method, tc.allowedNS) + // The next test will check more functionality aspects. This one is for testing corner cases + Describe("Check splitting functionality", func() { - if tc.valid { - require.True(t, isDid) - } else { - require.False(t, isDid) - } + Context("Valid DID", func() { + It("should return expected method, namespace and DID", func() { + method, namespace, id := MustSplitDID("did:cheqd:mainnet:qqqqqqqqqqqqqqqq") + Expect(method).To(Equal("cheqd")) + Expect(namespace).To(Equal("mainnet")) + Expect(id).To(Equal("qqqqqqqqqqqqqqqq")) + }) }) - } -} - -func TestSplitJoin(t *testing.T) { - cases := []string{ - "did:cheqd:testnet:123456789abcdefg", - "did:cheqd:testnet:123456789abcdefg", - "did:cheqd:testnet:123456789abcdefg", - "did:cheqd:testnet:123456789abcdefg", - "did:cheqd:123456789abcdefg", - "did:NOTcheqd:123456789abcdefg", - "did:NOTcheqd:123456789abcdefg123456789abcdefg", - "did:cheqd:testnet:123456789abcdefg", - } - for _, tc := range cases { - // Test split/join - t.Run("split/join "+tc, func(t *testing.T) { - method, namespace, id := MustSplitDID(tc) - require.Equal(t, tc, JoinDID(method, namespace, id)) + Context("Not valid DID string at all", func() { + It("should panic", func() { + panicDID := "Not " + Expect(func (){ + MustSplitDID(panicDID) + }).To(Panic()) + }) }) - } -} + }) -func TestMustSplitDID(t *testing.T) { - require.Panicsf(t, func() { - MustSplitDID("not did") - }, "must panic") + DescribeTable("Check DID splitting and joining", - method, namespace, id := MustSplitDID("did:cheqd:mainnet:qqqqqqqqqqqqqqqq") - require.Equal(t, "cheqd", method) - require.Equal(t, "mainnet", namespace) - require.Equal(t, "qqqqqqqqqqqqqqqq", id) -} + func(did string) { + method, namespace, id := MustSplitDID(did) + Expect(did).To(Equal(JoinDID(method, namespace, id))) + }, + Entry("Full DID", "did:cheqd:testnet:123456789abcdefg"), + Entry("Without namespace", "did:cheqd:123456789abcdefg"), + Entry("Not cheqd method", "did:NOTcheqd:123456789abcdefg"), + Entry("32-symbols ID", "did:NOTcheqd:123456789abcdefg123456789abcdefg"), + ) +}) diff --git a/x/cheqd/utils/did_url_test.go b/x/cheqd/utils/did_url_test.go index 6946f7f40..874c0d1c4 100644 --- a/x/cheqd/utils/did_url_test.go +++ b/x/cheqd/utils/did_url_test.go @@ -78,89 +78,3 @@ var _ = Describe("DID-URL tests", func() { Entry("Not valid: Split should return error", false, "qwerty"), ) }) - -// func TestIsDidURL(t *testing.T) { -// cases := []struct { -// name string -// valid bool -// didUrl string -// }{ -// // Path: all the possible symbols -// {"Valid: the whole alphabet for path", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"}, -// {"Valid: several paths", true, "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/"}, -// {"Valid: the whole alphabet with query", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query"}, -// {"Valid: the whole alphabet with query and fragment", true, "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment"}, -// {"Valid: each possible symbols as a path", true, "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff"}, -// {"Valid: empty path", true, "did:cheqd:testnet:123456789abcdefg/"}, -// // Query: all the possible variants -// {"Valid: the whole alphabet for query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"}, -// {"Valid: the whole alphabet for query and another query", true, "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4"}, -// // Fragment: -// {"Valid: the whole alphabet for fragment", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff"}, -// {"Valid: the whole alphabet with query and apth", true, "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?"}, -// {"Valid: only fragment", true, "did:cheqd:testnet:123456789abcdefg#fragment"}, -// {"Valid: only query", true, "did:cheqd:testnet:123456789abcdefg?query"}, -// // Wrong cases -// {"Not valid: wrong HEXDIG for path (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path%20%zz"}, -// {"Not valid: wrong HEXDIG for query (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query%20%zz"}, -// {"Not valid: wrong HEXDIG for fragment (pct-encoded phrase)", false, "did:cheqd:testnet:123456789abcdefg/path?query#fragment%20%zz"}, -// // Wrong splitting (^did:([^:]+?)(:([^:]+?))?:([^:]+)$) -// {"Not valid: starts with not 'did'", false, "did123:cheqd:::123456789abcdefg/path?query#fragment"}, -// {"Not valid: empty namespace", false, "did:cheqd::123456789abcdefg/path?query#fragment"}, -// {"Not valid: a lot of ':'", false, "did:cheqd:::123456789abcdefg/path?query#fragment"}, -// {"Not valid: two DIDs in one", false, "did:cheqd:testnet:123456789abcdefg:did:cheqd:testnet:123456789abcdefg/path?query#fragment"}, -// // Wrong namespace (^[a-zA-Z0-9]*) -// {"Not valid: / - is not allowed for namespace", false, "did:cheqd:testnet/:123456789abcdefg/path?query#fragment"}, -// {"Not valid: _ - is not allowed for namespace", false, "did:cheqd:testnet_:123456789abcdefg/path?query#fragment"}, -// {"Not valid: % - is not allowed for namespace", false, "did:cheqd:testnet%:123456789abcdefg/path?query#fragment"}, -// {"Not valid: * - is not allowed for namespace", false, "did:cheqd:testnet*:123456789abcdefg/path?query#fragment"}, -// {"Not valid: & - is not allowed for namespace", false, "did:cheqd:testnet&:123456789abcdefg/path?query#fragment"}, -// {"Not valid: @ - is not allowed for namespace", false, "did:cheqd:testnet@/:123456789abcdefg/path?query#fragment"}, -// // Base58 checks (^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]*$) -// {"Not valid: O - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefO/path?query#fragment"}, -// {"Not valid: I - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefI/path?query#fragment"}, -// {"Not valid: l - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdefl/path?query#fragment"}, -// {"Not valid: 0 - is not allowed for base58", false, "did:cheqd:testnet:123456789abcdef0/path?query#fragment"}, -// // Length checks (should be exactly 16 or 32) -// {"Not valid: UniqueID less then 16 symbols", false, "did:cheqd:testnet:123/path?query#fragment"}, -// {"Not valid: UniqueID more then 16 symbols but less then 32", false, "did:cheqd:testnet:123456789abcdefgABCDEF/path?query#fragment"}, -// {"Not valid: UniqueID more then 32 symbols", false, "did:cheqd:testnet:123456789abcdefg123456789abcdefgABCDEF/path?query#fragment"}, -// {"Not valid: Split should return error", false, "qwerty"}, -// } - -// for _, tc := range cases { -// t.Run(tc.name, func(t *testing.T) { -// isDid := IsValidDIDUrl(tc.didUrl, "", []string{}) - -// if tc.valid { -// require.True(t, isDid) -// } else { -// require.False(t, isDid) -// } -// }) -// } -// } - -// func TestDidURLJoin(t *testing.T) Entry("", -// cases := []stringEntry("", -// "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", -// "did:cheqd:testnet:123456789abcdefg/path/to/some/other/place/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff/", -// "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query", -// "did:cheqd:testnet:123456789abcdefg/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query#fragment", -// "did:cheqd:testnet:123456789abcdefg/12/ab/AB/-/./_/~/!/$/&/'/(/)/*/+/,/;/=/:/@/%20/%ff", -// "did:cheqd:testnet:123456789abcdefg/", -// "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?", -// "did:cheqd:testnet:123456789abcdefg/path?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?query=2?query=3/query=%A4", -// "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff", -// "did:cheqd:testnet:123456789abcdefg/path?query#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$&'()*+,;=:@%20%ff?", -// "did:cheqd:testnet:123456789abcdefg#fragment", -// "did:cheqd:testnet:123456789abcdefg?query", -// } - -// for _, tc := range cases Entry("", -// t.Run("split/join"+tc, func(t *testing.T) { -// did, path, query, fragment := MustSplitDIDUrl(tc) -// require.Equal(t, tc, JoinDIDUrl(did, path, query, fragment)) -// }) -// } -// } diff --git a/x/cheqd/utils/encoding_test.go b/x/cheqd/utils/encoding_test.go index d06f74dda..f6ec66f15 100644 --- a/x/cheqd/utils/encoding_test.go +++ b/x/cheqd/utils/encoding_test.go @@ -1,11 +1,10 @@ -package utils +package utils_test import ( "encoding/json" - "testing" - - "github.com/multiformats/go-multibase" - "github.com/stretchr/testify/require" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) type TestJWKKey struct { @@ -40,76 +39,53 @@ var ( NotValidJWKByte, _ = json.Marshal(NotValidJWKKey) ) -func TestValidateMultibase(t *testing.T) { - cases := []struct { - name string - data string - encoding multibase.Encoding - valid bool - }{ - {"Valid: General pmbkey", "zABCDEFG123456789", multibase.Base58BTC, true}, - {"Not Valid: cannot be empty", "", multibase.Base58BTC, false}, - {"Not Valid: without z but base58", "ABCDEFG123456789", multibase.Base58BTC, false}, - {"Not Valid: without z and not base58", "OIl0ABCDEFG123456789", multibase.Base58BTC, false}, - {"Not Valid: with z but not base58", "zOIl0ABCDEFG123456789", multibase.Base58BTC, false}, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := ValidateMultibase(tc.data) +var _ = Describe("Encoding checks", func() { + DescribeTable("Is valid multibase key", - if tc.valid { - require.NoError(t, err) + func(data string, isValid bool) { + _err := ValidateMultibase(data) + if isValid { + Ω(_err).ShouldNot(HaveOccurred()) } else { - require.Error(t, err) + Ω(_err).Should(HaveOccurred()) } - }) - } -} + }, -func TestValidateBase58(t *testing.T) { - cases := []struct { - name string - data string - valid bool - }{ - {"Valid: General pmbkey", "ABCDEFG123456789", true}, - {"Not Valid: cannot be empty", "", false}, - {"Not Valid: not base58", "OIl0ABCDEFG123456789", false}, - } + Entry("Valid: General pmbkey", "zABCDEFG123456789", true), + Entry("Not Valid: cannot be empty", "", false), + Entry("Not Valid: without z but base58", "ABCDEFG123456789", false), + Entry("Not Valid: without z and not base58", "OIl0ABCDEFG123456789", false), + Entry("Not Valid: with z but not base58", "zOIl0ABCDEFG123456789", false), + ) - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := ValidateBase58(tc.data) + DescribeTable("Validate Base58", - if tc.valid { - require.NoError(t, err) + func(data string, isValid bool) { + _err := ValidateBase58(data) + if isValid { + Ω(_err).ShouldNot(HaveOccurred()) } else { - require.Error(t, err) - } - }) - } -} + Ω(_err).Should(HaveOccurred()) + } + }, -func TestValidateJWK(t *testing.T) { - cases := []struct { - name string - data string - valid bool - }{ - {"Valid: General jwk", string(ValidJWKByte), true}, - {"Not Valid: Bad jwk", string(NotValidJWKByte), false}, - } + Entry("Valid: General pmbkey", "ABCDEFG123456789", true), + Entry("Not Valid: cannot be empty", "", false), + Entry("Not Valid: not base58", "OIl0ABCDEFG123456789", false), + ) - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := ValidateJWK(tc.data) + DescribeTable("Validate JWK", - if tc.valid { - require.NoError(t, err) - } else { - require.Error(t, err) - } - }) - } -} + func(data string, isValid bool) { + _err := ValidateJWK(data) + if isValid { + Ω(_err).ShouldNot(HaveOccurred()) + } else { + Ω(_err).Should(HaveOccurred()) + } + }, + + Entry("Valid: General jwk", string(ValidJWKByte), true), + Entry("Not Valid: Bad jwk", string(NotValidJWKByte), false), +) +}) diff --git a/x/cheqd/utils/proto_test.go b/x/cheqd/utils/proto_test.go index d62252a9b..11d4f7a02 100644 --- a/x/cheqd/utils/proto_test.go +++ b/x/cheqd/utils/proto_test.go @@ -1,12 +1,19 @@ -package utils +package utils_test import ( - "testing" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" bank_types "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/assert" ) -func Test_MsgTypeUrl(t *testing.T) { - assert.Equal(t, "/cosmos.bank.v1beta1.DenomUnit", MsgTypeURL(&bank_types.DenomUnit{})) -} +var _ = Describe("Proto", func() { + Describe("Check that DenomUnit from bank type has expected value", func() { + Context("Denom Unit from cosmos-sdk" ,func () { + It("should return expected value", func() { + Expect(MsgTypeURL(&bank_types.DenomUnit{})).To(Equal("/cosmos.bank.v1beta1.DenomUnit")) + }) + }) + }) +}) diff --git a/x/cheqd/utils/str_test.go b/x/cheqd/utils/str_test.go index 80a91eb4f..cb3b5d64e 100644 --- a/x/cheqd/utils/str_test.go +++ b/x/cheqd/utils/str_test.go @@ -1,122 +1,96 @@ -package utils +package utils_test import ( + . "github.com/cheqd/cheqd-node/x/cheqd/utils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "sort" - "testing" - - "github.com/stretchr/testify/require" ) -func TestIndexOf(t *testing.T) { - cases := []struct { - array []string - searchElement string - fromIndex int - expectedResult int - }{ - {[]string{}, "", 0, -1}, - {nil, "", 0, -1}, - {[]string{"1", "2"}, "1", 0, 0}, - {[]string{"1", "2", "3"}, "3", 0, 2}, - {[]string{"1", "2", "3"}, "4", 0, -1}, - {[]string{"4", "1", "6", "2", "3", "4"}, "4", 0, 0}, - {[]string{"4", "1", "6", "2", "3", "4"}, "4", 1, 5}, - {[]string{"4", "1", "6", "2", "3", "4"}, "4", 3, 5}, - } - - for _, tc := range cases { - actual := IndexOf(tc.array, tc.searchElement, tc.fromIndex) - require.Equal(t, tc.expectedResult, actual) - } -} - -func TestContains(t *testing.T) { - cases := []struct { - array []string - searchElement string - expectedResult bool - }{ - {[]string{}, "", false}, - {nil, "", false}, - {[]string{"1", "2"}, "1", true}, - {[]string{"1", "2", "3"}, "2", true}, - {[]string{"1", "2", "3"}, "3", true}, - {[]string{"1", "2", "3"}, "123", false}, - } - - for _, tc := range cases { - actual := Contains(tc.array, tc.searchElement) - require.Equal(t, tc.expectedResult, actual) - } -} - -func TestSubtract(t *testing.T) { - cases := []struct { - first []string - second []string - expected []string - }{ - {[]string{}, []string{}, []string{}}, - {nil, []string{}, []string{}}, - {nil, nil, []string{}}, - {[]string{"1", "2"}, []string{"1", "2"}, []string{}}, - {[]string{"1", "2", "3"}, []string{}, []string{"1", "2", "3"}}, - {[]string{"1", "2", "3"}, nil, []string{"1", "2", "3"}}, - {[]string{"1", "2", "3"}, []string{"4", "5", "6"}, []string{"1", "2", "3"}}, - {[]string{"1", "2", "3"}, []string{"1", "5", "2"}, []string{"3"}}, - {[]string{"4", "1", "6", "2", "3"}, []string{"1", "5", "2"}, []string{"3", "4", "6"}}, - } - - for _, tc := range cases { - actual := Subtract(tc.first, tc.second) - // We can't compare arrays directly cause result of `subtract` is not deterministic - sort.Strings(actual) - require.Equal(t, tc.expected, actual) - } -} - -func TestUnique(t *testing.T) { - cases := []struct { - array []string - expected []string - }{ - {[]string{}, []string{}}, - {nil, []string{}}, - {[]string{"1", "2"}, []string{"1", "2"}}, - {[]string{"1", "3", "2"}, []string{"1", "2", "3"}}, - {[]string{"4", "1", "6", "2", "3", "1", "3", "1"}, []string{"1", "2", "3", "4", "6"}}, - } - - for _, tc := range cases { - actual := Unique(tc.array) - // We can't compare arrays directly cause result of `unique` is not deterministic - sort.Strings(actual) - require.Equal(t, tc.expected, actual) - } -} - -func TestReplaceInList(t *testing.T) { - list := []string{"1", "2", "3", "2"} - ReplaceInSlice(list, "2", "3") - - require.Equal(t, []string{"1", "3", "3", "3"}, list) -} - -func TestUniqueSorted(t *testing.T) { - cases := []struct { - name string - input []string - output []string - }{ - {"General alphabet list", []string{"aa", "bb"}, []string{"aa", "bb"}}, - {"General alphabet reverse list", []string{"bb", "aa"}, []string{"aa", "bb"}}, - {"General number list", []string{"22", "11"}, []string{"11", "22"}}, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - res := UniqueSorted(tc.input) - require.Equal(t, res, tc.output) - }) - } -} +var _ = Describe("Str utils functionality", func() { + DescribeTable("IndexOf function", + + func(array []string, searchElement string, fromIndex int, expectedResult int) { + actual := IndexOf(array, searchElement, fromIndex) + Expect(actual).To(Equal(expectedResult)) + }, + + Entry("Emty array, Empty element, Expected: -1", []string{}, "", 0, -1), + Entry("Nil as array, Empty element, Expected: -1", nil, "", 0, -1), + Entry("Desired element is the first. Expected: 0", []string{"1", "2"}, "1", 0, 0), + Entry("Desired element is the latest one. Expected: 2", []string{"1", "2", "3"}, "3", 0, 2), + Entry("Desired element is absent. Expected: -1", []string{"1", "2", "3"}, "4", 0, -1), + Entry("There are more then 1 such elements but search should be started from the beginning. Expected: 0", []string{"4", "1", "6", "2", "3", "4"}, "4", 0, 0), + Entry("There are more then 1 such elements but search should be started from the index 1. Expected: 5", []string{"4", "1", "6", "2", "3", "4"}, "4", 1, 5), + Entry("There are more then 1 such elements but search should be started from the index 3. Expected: 5", []string{"4", "1", "6", "2", "3", "4"}, "4", 3, 5), + ) + + DescribeTable("Contains function", + + func(array []string, searchElement string, doesContain bool) { + Expect(Contains(array, searchElement)).To(Equal(doesContain)) + }, + Entry("Emty array, Empty element, Expected: false", []string{}, "", false), + Entry("Nil as array, Empty element, Expected: false", nil, "", false), + Entry("Desired element exists at the position 1. Expected: true", []string{"1", "2"}, "1", true), + Entry("Desired element exists at the position 2. Expected: true", []string{"1", "2", "3"}, "2", true), + Entry("Desired element exists at the position 3. Expected: true", []string{"1", "2", "3"}, "3", true), + Entry("Desired element is absent. Expected: false", []string{"1", "2", "3"}, "123", false), + + ) + + DescribeTable("Substract function", + + func(first []string, second []string, expected []string) { + actual := Subtract(first, second) + // We can't compare arrays directly cause result of `subtract` is not deterministic + sort.Strings(actual) + Expect(expected).To(Equal(actual)) + }, + Entry("Empty first and empty second. Expected empty list", []string{}, []string{}, []string{}), + Entry("nil as the first and the empty second. Expected empty list", nil, []string{}, []string{}), + Entry("nil as the first and nil as the second. Expected empty list", nil, nil, []string{}), + Entry("The same lists. Expected empty list", []string{"1", "2"}, []string{"1", "2"}, []string{}), + Entry("Substract with empty list. Exected: first array", []string{"1", "2", "3"}, []string{}, []string{"1", "2", "3"}), + Entry("Substract with nil as the second. Exected: first array", []string{"1", "2", "3"}, nil, []string{"1", "2", "3"}), + Entry("Substract with totally different list. Expected: first array", []string{"1", "2", "3"}, []string{"4", "5", "6"}, []string{"1", "2", "3"}), + Entry("Substract. General case. Expected: [1, 2]", []string{"1", "2", "3"}, []string{"1", "5", "2"}, []string{"3"}), + Entry("Substract. General case. Expected: [3, 4, 6]", []string{"4", "1", "6", "2", "3"}, []string{"1", "5", "2"}, []string{"3", "4", "6"}), + ) + + DescribeTable("Unique function", + + func(array []string, expected []string) { + actual := Unique(array) + // We can't compare arrays directly cause result of `unique` is not deterministic + sort.Strings(actual) + Expect(expected).To(Equal(actual)) + }, + Entry("Empty array. Expected empty list", []string{}, []string{}), + Entry("nil as array. Expected empty list", nil, []string{}), + Entry("Unique array. Expected the same array", []string{"1", "2"}, []string{"1", "2"}), + Entry("Unique array with length 3. Expected the same array", []string{"1", "3", "2"}, []string{"1", "2", "3"}), + Entry("General case. Expeceted array with unique elements", []string{"4", "1", "6", "2", "3", "1", "3", "1"}, []string{"1", "2", "3", "4", "6"}), + ) + + DescribeTable("ReplaceInList function", + + func(list []string, oldVal string, newVal string, expected []string) { + ReplaceInSlice(list, "2", "3") + Expect(expected).To(Equal(list)) + }, + Entry("Replace 2 with 3", []string{"1", "2", "3", "2"}, "2", "3", []string{"1", "3", "3", "3"}), + ) + + + DescribeTable("UniqueSorted function", + + func(input []string, expected []string) { + Expect(UniqueSorted(input)).To(Equal(expected)) + }, + Entry("General alphabet list", []string{"aa", "bb"}, []string{"aa", "bb"}), + Entry("General alphabet reverse list", []string{"bb", "aa"}, []string{"aa", "bb"}), + Entry("General number list", []string{"22", "11"}, []string{"11", "22"}), + ) + +}) From d2164214437c659d61ec554352b0f87ab4c38b66 Mon Sep 17 00:00:00 2001 From: drgomesp Date: Wed, 14 Sep 2022 11:56:03 -0300 Subject: [PATCH 11/76] Added test reporting (testing) --- .github/workflows/dispatch.yml | 20 ++++++++++---------- .github/workflows/test.yml | 33 ++++++++++++++++++++++++++++----- go.mod | 11 +++-------- go.sum | 31 ++++++++++++++++++++++--------- x/cheqd/utils/crypto_test.go | 5 +++-- 5 files changed, 66 insertions(+), 34 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 75e231fe5..853556039 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -11,21 +11,21 @@ jobs: # name: "Lint" # uses: ./.github/workflows/lint.yml - call-build: - name: "Build" - # needs: call-lint - uses: ./.github/workflows/build.yml - secrets: inherit - +# call-build: +# name: "Build" +# # needs: call-lint +# uses: ./.github/workflows/build.yml +# secrets: inherit + call-test: name: "Test" - needs: call-build +# needs: call-build uses: ./.github/workflows/test.yml call-release: name: "Release" - needs: [call-test, call-build] - # needs: call-build +# needs: [call-test, call-build] + needs: call-test if: ${{ github.ref_protected == true }} uses: ./.github/workflows/release.yml - secrets: inherit + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b00e17c7..2d8150b17 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,16 @@ name: "Test" on: + pull_request_target: + branches: + - main + - develop + types: + - opened + - reopened + - edited + - synchronize + - ready_for_review + - review_requested workflow_call: inputs: VERSION: @@ -11,8 +22,9 @@ defaults: env: NODE_CONFIGS_BASE: "/home/runner/work/cheqd-node/cheqd-node/docker/localnet/network-config" permissions: + id-token: write contents: write - packages: read + checks: write jobs: ginkgo-tests: @@ -31,11 +43,23 @@ jobs: run: | go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo go get github.com/onsi/gomega/... + go install github.com/jstemmer/go-junit-report/v2@latest - name: Run Ginkgo tests - run: ginkgo -r --race --randomize-all --randomize-suites -v + run: | + go test -v github.com/cheqd/cheqd-node/x/cheqd/utils 2>&1 | go-junit-report -parser gotest > report.xml +# + - uses: dorny/test-reporter@v1 + if: success() || failure() # run this step even if previous step failed + with: + name: JEST Tests # Name of the check run which will be created + path: report.xml # Path to test results (inside artifact .zip) + reporter: java-junit # Format of test results + max-annotations: '50' + fail-on-error: false - # test-new-node-setup: + + # test-new-node-setup: # name: "New node setup" # runs-on: ubuntu-latest # env: @@ -277,5 +301,4 @@ jobs: # - name: Check that node with Cosmovisor was upgraded # working-directory: ./tests/e2e-complex/upgrade/cosmovisor - # run: START_HEIGHT=${{ steps.initiate-upgrade.outputs.START_HEIGHT }} bash check_upgrade.sh - + # run: START_HEIGHT=${{ steps.initiate-upgrade.outputs.START_HEIGHT }} bash check_upgrade.sh \ No newline at end of file diff --git a/go.mod b/go.mod index 4aff31ac2..135f45a84 100644 --- a/go.mod +++ b/go.mod @@ -16,8 +16,8 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/lestrrat-go/jwx v1.2.25 github.com/multiformats/go-multibase v0.1.1 - github.com/onsi/ginkgo v1.16.4 - github.com/onsi/gomega v1.20.0 + github.com/onsi/ginkgo/v2 v2.1.6 + github.com/onsi/gomega v1.20.1 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.5.0 @@ -64,7 +64,6 @@ require ( github.com/go-kit/log v0.2.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect - github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/gateway v1.1.0 // indirect @@ -72,7 +71,6 @@ require ( github.com/google/btree v1.0.0 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/google/orderedcode v0.0.1 // indirect - github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect @@ -107,8 +105,7 @@ require ( github.com/mtibben/percent v0.2.1 // indirect github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect - github.com/nxadm/tail v1.4.8 // indirect - github.com/onsi/ginkgo/v2 v2.1.4 // indirect + github.com/onsi/ginkgo v1.16.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect @@ -138,10 +135,8 @@ require ( golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect - golang.org/x/tools v0.1.10 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.4 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect diff --git a/go.sum b/go.sum index 86db6d4ec..b635b4121 100644 --- a/go.sum +++ b/go.sum @@ -368,7 +368,6 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -468,9 +467,9 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -776,20 +775,22 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= +github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU= +github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= -github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q= -github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= +github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= +github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -1053,6 +1054,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -1124,6 +1127,7 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210915214749-c084706c2272/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= @@ -1171,6 +1175,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1230,6 +1236,7 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211208012354-db4efeb81f4b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -1239,6 +1246,7 @@ golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1273,6 +1281,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1368,6 +1377,7 @@ golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1376,10 +1386,13 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -1468,8 +1481,8 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/x/cheqd/utils/crypto_test.go b/x/cheqd/utils/crypto_test.go index d29055a26..7d9dd06fb 100644 --- a/x/cheqd/utils/crypto_test.go +++ b/x/cheqd/utils/crypto_test.go @@ -3,17 +3,18 @@ package utils_test import ( // "testing" - . "github.com/cheqd/cheqd-node/x/cheqd/utils" "github.com/multiformats/go-multibase" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + + . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) var _ = Describe("Crypto", func() { Describe("ValidateEd25519PubKey", func() { Context("Valid: General Ed25519 public key", func() { It("should return no error", func() { - _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX") + _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWXforcingwrong") err := ValidateEd25519PubKey(keyBytes) Expect(err).To(BeNil()) }) From 4b0dce97fb18277175d58a02dfdd2695a6b78ffe Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 5 Oct 2022 17:04:22 +0300 Subject: [PATCH 12/76] Finish tests for utils Signed-off-by: Andrew Nikitin --- x/cheqd/utils/crypto_test.go | 74 +++++++++++------------------------- x/cheqd/utils/uri_test.go | 43 +++++++++------------ x/cheqd/utils/uuid_test.go | 47 ++++++++++------------- 3 files changed, 61 insertions(+), 103 deletions(-) diff --git a/x/cheqd/utils/crypto_test.go b/x/cheqd/utils/crypto_test.go index 7d9dd06fb..6cc5eb869 100644 --- a/x/cheqd/utils/crypto_test.go +++ b/x/cheqd/utils/crypto_test.go @@ -1,7 +1,6 @@ package utils_test import ( - // "testing" "github.com/multiformats/go-multibase" . "github.com/onsi/ginkgo/v2" @@ -14,7 +13,7 @@ var _ = Describe("Crypto", func() { Describe("ValidateEd25519PubKey", func() { Context("Valid: General Ed25519 public key", func() { It("should return no error", func() { - _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWXforcingwrong") + _, keyBytes, _ := multibase.Decode("zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX") err := ValidateEd25519PubKey(keyBytes) Expect(err).To(BeNil()) }) @@ -29,56 +28,27 @@ var _ = Describe("Crypto", func() { }) }) }) -}) - -// func TestValidateEd25519PubKey(t *testing.T) { -// cases := []struct { -// name string -// key string -// valid bool -// errorMsg string -// }{ -// {"Valid: General Ed25519 public key", "zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX", true, ""}, -// {"Valid: General Ed25519 public key", "zF1hVGXXK9rmx5HhMTpGnGQJiab9qr1111111111111", false, "ed25519: bad public key length: 31"}, -// } - -// for _, tc := range cases { -// t.Run(tc.name, func(t *testing.T) { -// _, keyBytes, _ := multibase.Decode(tc.key) -// err := ValidateEd25519PubKey(keyBytes) -// if tc.valid { -// require.NoError(t, err) -// } else { -// require.Error(t, err) -// require.Contains(t, err.Error(), tc.errorMsg) -// } -// }) -// } -// } - -// func TestValidateJwk(t *testing.T) { -// cases := []struct { -// name string -// key string -// valid bool -// errorMsg string -// }{ -// {"positive ed25519", "{\"crv\":\"Ed25519\",\"kty\":\"OKP\",\"x\":\"9Ov80OqMlNrILAUG8DBBlYQ1rUhp7wDomr2I5muzpTc\"}", true, ""}, -// {"positive ecdsa", "{\"crv\":\"P-256\",\"kty\":\"EC\",\"x\":\"tcEgxIPyYMiyR2_Vh_YMYG6Grg7axhK2N8JjWta5C0g\",\"y\":\"imiXD9ahVA_MKY066TrNA9r6l35lRrerP6JRey5SryQ\"}", true, ""}, -// {"positive rsa", "{\"e\":\"AQAB\",\"kty\":\"RSA\",\"n\":\"skKXRn44WN2DpXDwm4Ip25kIAGRA8y3iXlaoAhPmFiuSDkx97lXcJYrjxX0wSfehgCiSoZOBv6mFzgSVv0_pXQ6zI35xi2dsbexrc87m7Q24q2chpG33ttnVwQkoXrrm0zDzSX32EVxYQyTu9aWp-zxUdAWcrWUarT24RmgjU78v8JmUzkLmwbzsEImnIZ8Hce2ruisAmuAQBVVA4bWwQm_x1KPoQW-TP5_UR3gGugvf0XrQfMJaVpcxcJ9tduMUw6ffZOsqgbvAiZYnrezxSIjnd5lFTFBIEYdGR6ZgjYZoWvQB7U72o_TJoka-zfSODOUbxNBvxvFhA3uhoo3ZKw\"}", true, ""}, -// } + Describe("ValidateJWKKey", func() { + Context("Positive ed25519", func() { + It("should return no error", func() { + err := ValidateJWK("{\"crv\":\"Ed25519\",\"kty\":\"OKP\",\"x\":\"9Ov80OqMlNrILAUG8DBBlYQ1rUhp7wDomr2I5muzpTc\"}") + Expect(err).To(BeNil()) + }) + }) -// for _, tc := range cases { -// t.Run(tc.name, func(t *testing.T) { -// err := ValidateJWK(tc.key) + Context("Positive ecdsa", func() { + It("should return no error", func() { + err := ValidateJWK("{\"crv\":\"P-256\",\"kty\":\"EC\",\"x\":\"tcEgxIPyYMiyR2_Vh_YMYG6Grg7axhK2N8JjWta5C0g\",\"y\":\"imiXD9ahVA_MKY066TrNA9r6l35lRrerP6JRey5SryQ\"}") + Expect(err).To(BeNil()) + }) + }) -// if tc.valid { -// require.NoError(t, err) -// } else { -// require.Error(t, err) -// require.Contains(t, err.Error(), tc.errorMsg) -// } -// }) -// } -// } + Context("Positive rsa", func() { + It("should return no error", func() { + err := ValidateJWK("{\"e\":\"AQAB\",\"kty\":\"RSA\",\"n\":\"skKXRn44WN2DpXDwm4Ip25kIAGRA8y3iXlaoAhPmFiuSDkx97lXcJYrjxX0wSfehgCiSoZOBv6mFzgSVv0_pXQ6zI35xi2dsbexrc87m7Q24q2chpG33ttnVwQkoXrrm0zDzSX32EVxYQyTu9aWp-zxUdAWcrWUarT24RmgjU78v8JmUzkLmwbzsEImnIZ8Hce2ruisAmuAQBVVA4bWwQm_x1KPoQW-TP5_UR3gGugvf0XrQfMJaVpcxcJ9tduMUw6ffZOsqgbvAiZYnrezxSIjnd5lFTFBIEYdGR6ZgjYZoWvQB7U72o_TJoka-zfSODOUbxNBvxvFhA3uhoo3ZKw\"}") + Expect(err).To(BeNil()) + }) + }) + }) +}) diff --git a/x/cheqd/utils/uri_test.go b/x/cheqd/utils/uri_test.go index 9e7de26bc..ad6db5a1a 100644 --- a/x/cheqd/utils/uri_test.go +++ b/x/cheqd/utils/uri_test.go @@ -1,32 +1,25 @@ -package utils +package utils_test import ( - "testing" - - "github.com/stretchr/testify/require" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) -func TestValidateURI(t *testing.T) { - cases := []struct { - name string - valid bool - URI string - }{ - // Path: all the possible symbols - {"Valid: General http URI path", true, "http://a.com/a/b/c/d/?query=123#fragment=another_part"}, - {"Valid: General https URI path", true, "https://a.com/a/b/c/d/?query=123#fragment=another_part"}, - {"Valid: only alphabet symbols", true, "SomeAnotherPath"}, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err_ := ValidateURI(tc.URI) +var _ = Describe("URI validation", func() { + DescribeTable("ValidateURI", - if tc.valid { - require.NoError(t, err_) + func(isValid bool, uri string) { + err_ := ValidateURI(uri) + if isValid { + Expect(err_).To(BeNil()) } else { - require.Error(t, err_) + Expect(err_).ToNot(BeNil()) } - }) - } -} + }, + + Entry("Valid: General http URI path", true, "http://a.com/a/b/c/d/?query=123#fragment=another_part"), + Entry("Valid: General https URI path", true, "https://a.com/a/b/c/d/?query=123#fragment=another_part"), + Entry("Valid: only alphabet symbols", true, "SomeAnotherPath"), + ) +}) diff --git a/x/cheqd/utils/uuid_test.go b/x/cheqd/utils/uuid_test.go index 0b7ff983f..5e14c1100 100644 --- a/x/cheqd/utils/uuid_test.go +++ b/x/cheqd/utils/uuid_test.go @@ -1,33 +1,28 @@ -package utils +package utils_test import ( - "testing" - - "github.com/stretchr/testify/require" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) -func TestValidateUUID(t *testing.T) { - cases := []struct { - uuid string - valid bool - }{ - {"42d9c704-ecb0-11ec-8ea0-0242ac120002", true}, - {"not uuid", false}, - {"e1cdbc10-858c-4d7d-8a4b-5d45e90a81b3", true}, - {"{42d9c704-ecb0-11ec-8ea0-0242ac120002}", false}, - {"urn:uuid:42d9c704-ecb0-11ec-8ea0-0242ac120002", false}, - {"42d9c704ecb011ec8ea00242ac120002", false}, - } - - for _, tc := range cases { - t.Run(tc.uuid, func(t *testing.T) { - err_ := ValidateUUID(tc.uuid) +var _ = Describe("UUID validation", func() { + DescribeTable("ValidateUUID", - if tc.valid { - require.NoError(t, err_) + func(uri string, isValid bool) { + err_ := ValidateUUID(uri) + if isValid { + Expect(err_).To(BeNil()) } else { - require.Error(t, err_) + Expect(err_).ToNot(BeNil()) } - }) - } -} + }, + + Entry("Valid: General UUID", "42d9c704-ecb0-11ec-8ea0-0242ac120002", true), + Entry("Not Valid: wrong format", "not uuid", false), + Entry("Valid: Another general UUID", "e1cdbc10-858c-4d7d-8a4b-5d45e90a81b3", true), + Entry("Not Valid: Unsupported symbol {", "{42d9c704-ecb0-11ec-8ea0-0242ac120002}", false), + Entry("Not Valid: Unexpeced prefix", "urn:uuid:42d9c704-ecb0-11ec-8ea0-0242ac120002", false), + Entry("Not Valid: Wrong format", "42d9c704ecb011ec8ea00242ac120002", false), + ) +}) From fd500cefee13da2d46d9bbb52df998e1cc11f9e5 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 6 Oct 2022 11:57:48 +0300 Subject: [PATCH 13/76] Move signature verification tests Signed-off-by: Andrew Nikitin --- x/cheqd/tests/signature_verification_test.go | 209 +++++++++---------- 1 file changed, 99 insertions(+), 110 deletions(-) diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go index 88a8c9bea..ab371ac7c 100644 --- a/x/cheqd/tests/signature_verification_test.go +++ b/x/cheqd/tests/signature_verification_test.go @@ -5,138 +5,127 @@ import ( "crypto/rand" "fmt" "reflect" - "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/stretchr/testify/require" ) -func TestDIDDocControllerChanged(t *testing.T) { - setup := Setup() - - // Init did - aliceKeys, aliceDid, _ := setup.InitDid(AliceDID) - bobKeys, _, _ := setup.InitDid(BobDID) - - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) - receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - - // check - require.NotEqual(t, aliceDid.Controller, receivedDid.Controller) - require.NotEqual(t, []string{AliceDID, BobDID}, receivedDid.Controller) - require.Equal(t, []string{BobDID}, receivedDid.Controller) -} - -func TestDIDDocVerificationMethodChangedWithoutOldSignature(t *testing.T) { - setup := Setup() - - // Init did - _, aliceDid, _ := setup.InitDid(AliceDID) - bobKeys, _, _ := setup.InitDid(BobDID) - - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod[0].Type = Ed25519VerificationKey2020 - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) +var _ = Describe("Signature Verification", func() { + var setup TestSetup + var aliceKeys, bobKeys map[string]ed25519.PrivateKey + var aliceDid *types.MsgCreateDidPayload + BeforeEach(func() { + setup = Setup() + aliceKeys, aliceDid, _ = setup.InitDid(AliceDID) + bobKeys, _, _ = setup.InitDid(BobDID) + }) - // check - require.Error(t, err) - require.Equal(t, fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID), err.Error()) -} + It("should has changed DIDDoc controller", func() { + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) + receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) -func TestDIDDocVerificationMethodControllerChangedWithoutOldSignature(t *testing.T) { - setup := Setup() + Expect(aliceDid.Controller).To(Not(Equal(receivedDid.Controller))) + Expect([]string{AliceDID, BobDID}).To(Not(Equal(receivedDid.Controller))) + Expect([]string{BobDID}, receivedDid.Controller) + }) - // Init did - _, aliceDid, _ := setup.InitDid(AliceDID) - bobKeys, _, _ := setup.InitDid(BobDID) + It("should fails cause we need old signature for changing verification method", func() { + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.VerificationMethod[0].Type = Ed25519VerificationKey2020 + _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod[0].Controller = BobDID - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + // check + Expect(err).To(Not(BeNil())) + Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) + }) - // check - require.Error(t, err) - require.Equal(t, fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID), err.Error()) -} + It("should fails cause we need old signature for changing verification method controller", func() { + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.VerificationMethod[0].Controller = BobDID + _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) -func TestDIDDocControllerChangedWithoutOldSignature(t *testing.T) { - setup := Setup() + // check + Expect(err).To(Not(BeNil())) + Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) + }) - // Init did - _, aliceDid, _ := setup.InitDid(AliceDID) - bobKeys, _, _ := setup.InitDid(BobDID) + It("should fails cause we need old signature for changing DIDDoc controller", func() { + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) + _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + // check + Expect(err).To(Not(BeNil())) + Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) + }) +}) + +var _ = Describe("Signature Verification. Remove signature/VM", func() { + var setup TestSetup + var ApubKey, BpubKey ed25519.PublicKey + var AprivKey, BprivKey ed25519.PrivateKey + var aliceDid, bobDid *types.MsgCreateDidPayload + var aliceKeys, bobKeys map[string]ed25519.PrivateKey + + BeforeEach(func() { + setup = Setup() + // Generate keys + ApubKey, AprivKey, _ = ed25519.GenerateKey(rand.Reader) + BpubKey, BprivKey, _ = ed25519.GenerateKey(rand.Reader) + + // Create dids + aliceDid = setup.CreateDid(ApubKey, AliceDID) + bobDid = setup.CreateDid(BpubKey, BobDID) + + // Collect private keys + aliceKeys = map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} + bobKeys = map[string]ed25519.PrivateKey{BobKey1: BprivKey} + + // Add verification method + aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ + Id: AliceKey2, + Controller: BobDID, + Type: Ed25519VerificationKey2020, + PublicKeyMultibase: "z" + base58.Encode(BpubKey), + }) - // check - require.Error(t, err) - require.Equal(t, fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID), err.Error()) -} + }) -func TestDIDDocVerificationMethodDeletedWithoutOldSignature(t *testing.T) { - setup := Setup() + It("should fails cause old signature is required for removing this signature", func() { - // Init did + // Send dids + _, _ = setup.SendCreateDid(bobDid, bobKeys) + _, _ = setup.SendCreateDid(aliceDid, aliceKeys) - ApubKey, AprivKey, _ := ed25519.GenerateKey(rand.Reader) - BpubKey, BprivKey, _ := ed25519.GenerateKey(rand.Reader) - aliceDid := setup.CreateDid(ApubKey, AliceDID) - bobDid := setup.CreateDid(BpubKey, BobDID) + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} + updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} + _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ - Id: AliceKey2, - Controller: BobDID, - Type: Ed25519VerificationKey2020, - PublicKeyMultibase: "z" + base58.Encode(BpubKey), + // check + Expect(err).To(Not(BeNil())) + Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) }) - aliceKeys := map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} - bobKeys := map[string]ed25519.PrivateKey{BobKey1: BprivKey} - _, _ = setup.SendCreateDid(bobDid, bobKeys) - _, _ = setup.SendCreateDid(aliceDid, aliceKeys) - - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} - updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + It("should not fails while removing the whole verification method", func() { + aliceDid.Authentication = append(aliceDid.Authentication, AliceKey2) - // check - require.Error(t, err) - require.Equal(t, fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID), err.Error()) -} + // Send dids + _, _ = setup.SendCreateDid(bobDid, bobKeys) + _, _ = setup.SendCreateDid(aliceDid, aliceKeys) -func TestDIDDocVerificationMethodDeleted(t *testing.T) { - setup := Setup() + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} + updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} + receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - ApubKey, AprivKey, _ := ed25519.GenerateKey(rand.Reader) - BpubKey, BprivKey, _ := ed25519.GenerateKey(rand.Reader) + // check + Expect(len(aliceDid.VerificationMethod)).To(Not(Equal(len(receivedDid.VerificationMethod)))) + Expect(reflect.DeepEqual(aliceDid.VerificationMethod[0], receivedDid.VerificationMethod[0])).To(BeTrue()) - aliceDid := setup.CreateDid(ApubKey, AliceDID) - bobDid := setup.CreateDid(BpubKey, BobDID) - - aliceDid.Authentication = append(aliceDid.Authentication, AliceKey2) - aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ - Id: AliceKey2, - Controller: BobDID, - Type: Ed25519VerificationKey2020, - PublicKeyMultibase: "z" + base58.Encode(BpubKey), }) - - aliceKeys := map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} - bobKeys := map[string]ed25519.PrivateKey{BobKey1: BprivKey} - _, _ = setup.SendCreateDid(bobDid, bobKeys) - _, _ = setup.SendCreateDid(aliceDid, aliceKeys) - - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} - updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} - receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - - // check - require.NotEqual(t, len(aliceDid.VerificationMethod), len(receivedDid.VerificationMethod)) - require.True(t, reflect.DeepEqual(aliceDid.VerificationMethod[0], receivedDid.VerificationMethod[0])) -} +}) From 5dba69deee662d63a265646bf4d02349abc89da1 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 6 Oct 2022 20:28:38 +0300 Subject: [PATCH 14/76] Add Signature verification and Create DID tests Signed-off-by: Andrew Nikitin --- x/cheqd/tests/create_did_test.go | 740 ++++++++++--------- x/cheqd/tests/signature_verification_test.go | 3 +- x/cheqd/tests/utils.go | 8 +- 3 files changed, 383 insertions(+), 368 deletions(-) diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index 32b510d17..bf7c5a383 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -1,403 +1,419 @@ -package tests +package tests_test import ( "crypto/ed25519" "fmt" - "testing" + // "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/cheqd/cheqd-node/x/cheqd/tests" "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/multiformats/go-multibase" - "github.com/stretchr/testify/require" + // "github.com/stretchr/testify/require" ) -func TestCreateDID(t *testing.T) { +var _ = Describe("Create DID tests", func() { + // params for cases + var valid bool + var keys map[string]KeyPair + var signers []string + var msg *types.MsgCreateDidPayload + var errMsg = "" + + var setup TestSetup var err error - keys := GenerateTestKeys() - cases := []struct { - valid bool - name string - keys map[string]KeyPair - signers []string - msg *types.MsgCreateDidPayload - errMsg string - }{ - { - valid: true, - name: "Valid: Works", - keys: map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - }, - signers: []string{ImposterKey1}, - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Authentication: []string{ImposterKey1}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - }, + var mainKeys = GenerateTestKeys() + + BeforeEach(func() { + // setup + valid = false + keys = map[string]KeyPair{} + signers = []string{} + msg = &types.MsgCreateDidPayload{} + errMsg = "" + }) + + AfterEach(func() { + + setup = InitEnv(mainKeys) + + for _, vm := range msg.VerificationMethod { + if vm.PublicKeyMultibase == "" { + vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].PublicKey) + } + Expect(err).To(BeNil()) + } + + signerKeys := map[string]ed25519.PrivateKey{} + for _, signer := range signers { + signerKeys[signer] = keys[signer].PrivateKey + } + + did, err := setup.SendCreateDid(msg, signerKeys) + + if valid { + Expect(err).To(BeNil()) + Expect(msg.Id).To(Equal(did.Id)) + Expect(msg.Controller).To(Equal(did.Controller)) + Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) + Expect(msg.Authentication).To(Equal(did.Authentication)) + Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) + Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) + Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) + Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) + Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) + Expect(msg.Service).To(Equal(did.Service)) + Expect(msg.Context).To(Equal(did.Context)) + } else { + Expect(err).To(HaveOccurred()) + Expect(errMsg).To(Equal(err.Error())) + } + }) + + It("Valid: Works", func() { + valid = true + keys = map[string]KeyPair{ + ImposterKey1: GenerateKeyPair(), + } + signers = []string{ImposterKey1} + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Authentication: []string{ImposterKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, }, }, - }, - { - valid: true, - name: "Valid: Works with Key Agreement", - keys: map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: keys[AliceKey1], - }, - signers: []string{ImposterKey1, AliceKey1}, - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - KeyAgreement: []string{ImposterKey1}, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - }, + } + }) + + It("Valid: Works with Key Agreement", func() { + valid = true + keys = map[string]KeyPair{ + ImposterKey1: GenerateKeyPair(), + AliceKey1: mainKeys[AliceKey1], + } + signers = []string{ImposterKey1, AliceKey1} + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + KeyAgreement: []string{ImposterKey1}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, }, }, - }, - { - valid: true, - name: "Valid: Works with Assertion Method", - keys: map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: keys[AliceKey1], - }, - signers: []string{AliceKey1, ImposterKey1}, - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - AssertionMethod: []string{ImposterKey1}, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - }, + } + }) + + It("Valid: Works with Assertion Method", func() { + valid = true + keys = map[string]KeyPair{ + ImposterKey1: GenerateKeyPair(), + AliceKey1: mainKeys[AliceKey1], + } + signers = []string{AliceKey1, ImposterKey1} + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + AssertionMethod: []string{ImposterKey1}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, }, }, - }, - { - valid: true, - name: "Valid: Works with Capability Delegation", - keys: map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: keys[AliceKey1], - }, - signers: []string{AliceKey1, ImposterKey1}, - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - CapabilityDelegation: []string{ImposterKey1}, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - }, + } + }) + + It("Valid: Works with Capability Delegation", func() { + valid = true + keys = map[string]KeyPair{ + ImposterKey1: GenerateKeyPair(), + AliceKey1: mainKeys[AliceKey1], + } + signers = []string{AliceKey1, ImposterKey1} + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + CapabilityDelegation: []string{ImposterKey1}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, }, }, - }, - { - valid: true, - name: "Valid: Works with Capability Invocation", - keys: map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: keys[AliceKey1], - }, - signers: []string{AliceKey1, ImposterKey1}, - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - CapabilityInvocation: []string{ImposterKey1}, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - }, + } + }) + + It("Valid: Works with Capability Invocation", func() { + valid = true + keys = map[string]KeyPair{ + ImposterKey1: GenerateKeyPair(), + AliceKey1: mainKeys[AliceKey1], + } + signers = []string{AliceKey1, ImposterKey1} + msg= &types.MsgCreateDidPayload{ + Id: ImposterDID, + CapabilityInvocation: []string{ImposterKey1}, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, }, }, - }, - { - valid: true, - name: "Valid: With controller works", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, BobDID}, - }, - signers: []string{AliceKey1, BobKey3}, - keys: map[string]KeyPair{ - AliceKey1: keys[AliceKey1], - BobKey3: keys[BobKey3], - }, - }, - { - valid: true, - name: "Valid: Full message works", - keys: map[string]KeyPair{ - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-2": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-3": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-4": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5": GenerateKeyPair(), - AliceKey1: keys[AliceKey1], - BobKey1: keys[BobKey1], - BobKey2: keys[BobKey2], - BobKey3: keys[BobKey3], - CharlieKey1: keys[CharlieKey1], - CharlieKey2: keys[CharlieKey2], - CharlieKey3: keys[CharlieKey3], - }, - signers: []string{ + } + }) + + It("Valid: With controller works", func() { + valid = true + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Controller: []string{AliceDID, BobDID}, + } + signers = []string{AliceKey1, BobKey3} + keys = map[string]KeyPair{ + AliceKey1: mainKeys[AliceKey1], + BobKey3: mainKeys[BobKey3], + } + }) + + It("Valid: Full message works", func() { + valid = true + keys = map[string]KeyPair{ + "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1": GenerateKeyPair(), + "did:cheqd:test:yyyyyyyyyyyyyyyy#key-2": GenerateKeyPair(), + "did:cheqd:test:yyyyyyyyyyyyyyyy#key-3": GenerateKeyPair(), + "did:cheqd:test:yyyyyyyyyyyyyyyy#key-4": GenerateKeyPair(), + "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5": GenerateKeyPair(), + AliceKey1: mainKeys[AliceKey1], + BobKey1: mainKeys[BobKey1], + BobKey2: mainKeys[BobKey2], + BobKey3: mainKeys[BobKey3], + CharlieKey1: mainKeys[CharlieKey1], + CharlieKey2: mainKeys[CharlieKey2], + CharlieKey3: mainKeys[CharlieKey3], + } + signers = []string{ + "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", + "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", + AliceKey1, + BobKey1, + BobKey2, + BobKey3, + CharlieKey1, + CharlieKey2, + CharlieKey3, + } + msg = &types.MsgCreateDidPayload{ + Id: "did:cheqd:test:yyyyyyyyyyyyyyyy", + Authentication: []string{ "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", - AliceKey1, - BobKey1, - BobKey2, - BobKey3, - CharlieKey1, - CharlieKey2, - CharlieKey3, }, - msg: &types.MsgCreateDidPayload{ - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy", - Authentication: []string{ - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", - }, - Context: []string{"abc", "de"}, - CapabilityInvocation: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-2"}, - CapabilityDelegation: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-3"}, - KeyAgreement: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-4"}, - AlsoKnownAs: []string{"SomeUri"}, - Service: []*types.Service{ - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#service-1", - Type: "DIDCommMessaging", - ServiceEndpoint: "ServiceEndpoint", - }, + Context: []string{"abc", "de"}, + CapabilityInvocation: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-2"}, + CapabilityDelegation: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-3"}, + KeyAgreement: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-4"}, + AlsoKnownAs: []string{"SomeUri"}, + Service: []*types.Service{ + { + Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#service-1", + Type: "DIDCommMessaging", + ServiceEndpoint: "ServiceEndpoint", }, - Controller: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy", AliceDID, BobDID, CharlieDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", - Type: Ed25519VerificationKey2020, - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-2", - Type: Ed25519VerificationKey2020, - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-3", - Type: Ed25519VerificationKey2020, - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-4", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - }, - }, - }, - { - valid: false, - name: "Not Valid: Second controller did not sign request", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, BobDID}, - }, - signers: []string{AliceKey1}, - keys: map[string]KeyPair{ - AliceKey1: keys[AliceKey1], }, - errMsg: fmt.Sprintf("signer: %s: signature is required but not found", BobDID), - }, - { - valid: false, - name: "Not Valid: No signature", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, BobDID}, - }, - errMsg: fmt.Sprintf("signer: %s: signature is required but not found", AliceDID), - }, - { - valid: false, - name: "Not Valid: Controller not found", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, NotFounDID}, - }, - signers: []string{AliceKey1, ImposterKey1}, - keys: map[string]KeyPair{ - AliceKey1: keys[AliceKey1], - ImposterKey1: GenerateKeyPair(), - }, - errMsg: fmt.Sprintf("%s: DID Doc not found", NotFounDID), - }, - { - valid: false, - name: "Not Valid: Wrong signature", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID}, - }, - signers: []string{AliceKey1}, - keys: map[string]KeyPair{ - AliceKey1: keys[BobKey1], - }, - errMsg: fmt.Sprintf("method id: %s: invalid signature detected", AliceKey1), - }, - { - valid: false, - name: "Not Valid: DID signed by wrong controller", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Authentication: []string{ImposterKey1}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(keys[ImposterKey1].PublicKey), - }, + Controller: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy", AliceDID, BobDID, CharlieDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", + Type: Ed25519VerificationKey2020, + Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", }, - }, - signers: []string{AliceKey1}, - keys: map[string]KeyPair{ - AliceKey1: keys[AliceKey1], - }, - errMsg: fmt.Sprintf("signer: %s: signature is required but not found", ImposterDID), - }, - { - valid: false, - name: "Not Valid: DID self-signed by not existing verification method", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Authentication: []string{ImposterKey1}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(keys[ImposterKey1].PublicKey), - }, + { + Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-2", + Type: Ed25519VerificationKey2020, + Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", }, - }, - signers: []string{ImposterKey2}, - keys: map[string]KeyPair{ - ImposterKey2: GenerateKeyPair(), - }, - errMsg: fmt.Sprintf("%s: verification method not found", ImposterKey2), - }, - { - valid: false, - name: "Not Valid: Self-signature not found", - msg: &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, ImposterDID}, - Authentication: []string{ImposterKey1}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(keys[ImposterKey1].PublicKey), - }, + { + Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-3", + Type: Ed25519VerificationKey2020, + Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", }, - }, - signers: []string{AliceKey1, ImposterKey2}, - keys: map[string]KeyPair{ - AliceKey1: keys[AliceKey1], - ImposterKey2: GenerateKeyPair(), - }, - errMsg: fmt.Sprintf("%s: verification method not found", ImposterKey2), - }, - { - valid: false, - name: "Not Valid: DID Doc already exists", - keys: map[string]KeyPair{ - CharlieKey1: GenerateKeyPair(), - }, - signers: []string{CharlieKey1}, - msg: &types.MsgCreateDidPayload{ - Id: CharlieDID, - Authentication: []string{CharlieKey1}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: CharlieKey1, - Type: Ed25519VerificationKey2020, - Controller: CharlieDID, - }, + { + Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-4", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", + }, + { + Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", }, }, - errMsg: fmt.Sprintf("%s: DID Doc exists", CharlieDID), - }, - } + } + }) - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - msg := tc.msg - setup := InitEnv(t, keys) +// ************************** +// ***** Negative cases ***** +// ************************** - for _, vm := range msg.VerificationMethod { - if vm.PublicKeyMultibase == "" { - vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, tc.keys[vm.Id].PublicKey) - } - require.NoError(t, err) - } + It("Not Valid: Second controller did not sign request", func() { + valid = false + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Controller: []string{AliceDID, BobDID}, + } + signers = []string{AliceKey1} + keys = map[string]KeyPair{ + AliceKey1: mainKeys[AliceKey1], + } + errMsg = fmt.Sprintf("signer: %s: signature is required but not found", BobDID) + }) - signerKeys := map[string]ed25519.PrivateKey{} - for _, signer := range tc.signers { - signerKeys[signer] = tc.keys[signer].PrivateKey - } + It("Not Valid: No signature", func(){ + valid = false + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Controller: []string{AliceDID, BobDID}, + } + errMsg = fmt.Sprintf("signer: %s: signature is required but not found", AliceDID) + }) + + It("Not Valid: Controller not found", func(){ + valid = false + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Controller: []string{AliceDID, NotFounDID}, + } + signers = []string{AliceKey1, ImposterKey1} + keys = map[string]KeyPair{ + AliceKey1: mainKeys[AliceKey1], + ImposterKey1: GenerateKeyPair(), + } + errMsg = fmt.Sprintf("%s: DID Doc not found", NotFounDID) + }) - did, err := setup.SendCreateDid(msg, signerKeys) + It("Not Valid: Wrong signature", func(){ + valid = false + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Controller: []string{AliceDID}, + } + signers = []string{AliceKey1} + keys = map[string]KeyPair{ + AliceKey1: mainKeys[BobKey1], + } + errMsg = fmt.Sprintf("method id: %s: invalid signature detected", AliceKey1) + }) - if tc.valid { - require.Nil(t, err) - require.Equal(t, tc.msg.Id, did.Id) - require.Equal(t, tc.msg.Controller, did.Controller) - require.Equal(t, tc.msg.VerificationMethod, did.VerificationMethod) - require.Equal(t, tc.msg.Authentication, did.Authentication) - require.Equal(t, tc.msg.AssertionMethod, did.AssertionMethod) - require.Equal(t, tc.msg.CapabilityInvocation, did.CapabilityInvocation) - require.Equal(t, tc.msg.CapabilityDelegation, did.CapabilityDelegation) - require.Equal(t, tc.msg.KeyAgreement, did.KeyAgreement) - require.Equal(t, tc.msg.AlsoKnownAs, did.AlsoKnownAs) - require.Equal(t, tc.msg.Service, did.Service) - require.Equal(t, tc.msg.Context, did.Context) - } else { - require.Error(t, err) - require.Equal(t, tc.errMsg, err.Error()) - } - }) - } -} + It("Not Valid: DID signed by wrong controller", func(){ + valid =false + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Authentication: []string{ImposterKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, + PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].PublicKey), + }, + }, + } + signers = []string{AliceKey1} + keys = map[string]KeyPair{ + AliceKey1: mainKeys[AliceKey1], + } + errMsg = fmt.Sprintf("signer: %s: signature is required but not found", ImposterDID) + }) + + It("Not Valid: DID self-signed by not existing verification method", func(){ + valid = false + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Authentication: []string{ImposterKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, + PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].PublicKey), + }, + }, + } + signers = []string{ImposterKey2} + keys = map[string]KeyPair{ + ImposterKey2: GenerateKeyPair(), + } + errMsg = fmt.Sprintf("%s: verification method not found", ImposterKey2) + }) + + It("Not Valid: Self-signature not found", func(){ + valid = false + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Controller: []string{AliceDID, ImposterDID}, + Authentication: []string{ImposterKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, + PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].PublicKey), + }, + }, + } + signers = []string{AliceKey1, ImposterKey2} + keys = map[string]KeyPair{ + AliceKey1: mainKeys[AliceKey1], + ImposterKey2: GenerateKeyPair(), + } + errMsg = fmt.Sprintf("%s: verification method not found", ImposterKey2) + }) + + It("Not Valid: DID Doc already exists", func(){ + valid = false + keys = map[string]KeyPair{ + CharlieKey1: GenerateKeyPair(), + } + signers = []string{CharlieKey1} + msg = &types.MsgCreateDidPayload{ + Id: CharlieDID, + Authentication: []string{CharlieKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: CharlieKey1, + Type: Ed25519VerificationKey2020, + Controller: CharlieDID, + }, + }, + } + errMsg = fmt.Sprintf("%s: DID Doc exists", CharlieDID) + }) +}) -func TestHandler_DidDocAlreadyExists(t *testing.T) { - setup := Setup() +var _ = Describe("TestHandler", func() { + It("Fails cause DIDDoc is already exists", func() { + setup := Setup() - _, _, _ = setup.InitDid(AliceDID) - _, _, err := setup.InitDid(AliceDID) + _, _, _ = setup.InitDid(AliceDID) + _, _, err := setup.InitDid(AliceDID) - require.Error(t, err) - require.Equal(t, fmt.Sprintf("%s: DID Doc exists", AliceDID), err.Error()) -} + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(fmt.Sprintf("%s: DID Doc exists", AliceDID))) + }) +}) diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go index ab371ac7c..9a8b53804 100644 --- a/x/cheqd/tests/signature_verification_test.go +++ b/x/cheqd/tests/signature_verification_test.go @@ -1,4 +1,4 @@ -package tests +package tests_test import ( "crypto/ed25519" @@ -8,6 +8,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + . "github.com/cheqd/cheqd-node/x/cheqd/tests" "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" diff --git a/x/cheqd/tests/utils.go b/x/cheqd/tests/utils.go index 5ba9b0b97..ac0a3ef88 100644 --- a/x/cheqd/tests/utils.go +++ b/x/cheqd/tests/utils.go @@ -2,9 +2,7 @@ package tests import ( "math/rand" - "testing" - - "github.com/stretchr/testify/require" + . "github.com/onsi/gomega" ) var letters = []rune("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") @@ -40,9 +38,9 @@ func GenerateTestKeys() map[string]KeyPair { } } -func InitEnv(t *testing.T, keys map[string]KeyPair) TestSetup { +func InitEnv(keys map[string]KeyPair) TestSetup { setup := Setup() err := setup.CreateTestDIDs(keys) - require.NoError(t, err) + Expect(err).To(BeNil()) return setup } From c4a0762ef7ac5b2f4007b9242e64739976e370fe Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Fri, 7 Oct 2022 11:44:11 +0300 Subject: [PATCH 15/76] Add tests for UpdateDid --- x/cheqd/tests/create_did_test.go | 6 +- x/cheqd/tests/signature_verification_test.go | 3 +- x/cheqd/tests/tests_suite_test.go | 14 + x/cheqd/tests/update_did_test.go | 863 ++++++++++--------- 4 files changed, 451 insertions(+), 435 deletions(-) create mode 100644 x/cheqd/tests/tests_suite_test.go diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index bf7c5a383..f4484fd6d 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -1,20 +1,16 @@ -package tests_test +package tests import ( "crypto/ed25519" "fmt" - // "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/cheqd/cheqd-node/x/cheqd/tests" "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/multiformats/go-multibase" - - // "github.com/stretchr/testify/require" ) var _ = Describe("Create DID tests", func() { diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go index 9a8b53804..ab371ac7c 100644 --- a/x/cheqd/tests/signature_verification_test.go +++ b/x/cheqd/tests/signature_verification_test.go @@ -1,4 +1,4 @@ -package tests_test +package tests import ( "crypto/ed25519" @@ -8,7 +8,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/cheqd/cheqd-node/x/cheqd/tests" "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" diff --git a/x/cheqd/tests/tests_suite_test.go b/x/cheqd/tests/tests_suite_test.go new file mode 100644 index 000000000..cd8579e57 --- /dev/null +++ b/x/cheqd/tests/tests_suite_test.go @@ -0,0 +1,14 @@ +package tests_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "testing" +) + +func TestTestsGeneral(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "General Tests Suite") +} + diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index e4371f6c7..7ff264203 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -2,482 +2,489 @@ package tests import ( "fmt" - "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/multiformats/go-multibase" - "github.com/stretchr/testify/require" ) -func TestUpdateDid(t *testing.T) { +var _ = Describe("Update DID tests", func() { + // params for cases + var valid bool + var signers []string + var signerKeys []SignerKey + var msg *types.MsgUpdateDidPayload + var errMsg = "" + + var setup TestSetup var err error - keys := map[string]KeyPair{ - AliceKey1: GenerateKeyPair(), - AliceKey2: GenerateKeyPair(), - BobKey1: GenerateKeyPair(), - BobKey2: GenerateKeyPair(), - BobKey3: GenerateKeyPair(), - BobKey4: GenerateKeyPair(), - CharlieKey1: GenerateKeyPair(), - CharlieKey2: GenerateKeyPair(), - CharlieKey3: GenerateKeyPair(), - CharlieKey4: GenerateKeyPair(), - ImposterKey1: GenerateKeyPair(), - } - - cases := []struct { - valid bool - name string - signerKeys []SignerKey - signers []string - msg *types.MsgUpdateDidPayload - errMsg string - }{ - { - valid: true, - name: "Valid: Key rotation works", - signerKeys: []SignerKey{ + var mainKeys = map[string]KeyPair{ + AliceKey1: GenerateKeyPair(), + AliceKey2: GenerateKeyPair(), + BobKey1: GenerateKeyPair(), + BobKey2: GenerateKeyPair(), + BobKey3: GenerateKeyPair(), + BobKey4: GenerateKeyPair(), + CharlieKey1: GenerateKeyPair(), + CharlieKey2: GenerateKeyPair(), + CharlieKey3: GenerateKeyPair(), + CharlieKey4: GenerateKeyPair(), + ImposterKey1: GenerateKeyPair(), + } + + BeforeEach(func() { + // setup + valid = false + signers = []string{} + signerKeys = []SignerKey{} + msg = &types.MsgUpdateDidPayload{} + errMsg = "" + }) + + AfterEach(func() { + + setup = InitEnv(mainKeys) + + for _, vm := range msg.VerificationMethod { + if vm.PublicKeyMultibase == "" { + vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, mainKeys[vm.Id].PublicKey) + } + Expect(err).To(BeNil()) + } + + compiledKeys := []SignerKey{} + if len(signerKeys) > 0 { + compiledKeys = signerKeys + } else { + for _, signer := range signers { + compiledKeys = append(compiledKeys, SignerKey{ + signer: signer, + key: mainKeys[signer].PrivateKey, + }) + } + } + + did, err := setup.SendUpdateDid(msg, compiledKeys) + + if valid { + Expect(err).To(BeNil()) + Expect(msg.Id).To(Equal(did.Id)) + Expect(msg.Controller).To(Equal(did.Controller)) + Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) + Expect(msg.Authentication).To(Equal(did.Authentication)) + Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) + Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) + Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) + Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) + Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) + Expect(msg.Service).To(Equal(did.Service)) + Expect(msg.Context).To(Equal(did.Context)) + } else { + Expect(err).To(HaveOccurred()) + Expect(errMsg).To(Equal(err.Error())) + } + }) + + It("Valid: Key rotation works", func() { + valid = true + signerKeys = []SignerKey{ + { + signer: AliceKey1, + key: mainKeys[AliceKey1].PrivateKey, + }, + { + signer: AliceKey1, + key: mainKeys[AliceKey2].PrivateKey, + }, + } + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + VerificationMethod: []*types.VerificationMethod{ { - signer: AliceKey1, - key: keys[AliceKey1].PrivateKey, + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, + PublicKeyMultibase: "z" + base58.Encode(mainKeys[AliceKey2].PublicKey), }, + }, + } + }) + + It("Not Valid: replacing controller and Verification method ID does not work without new sign", func() { + valid = false + signers = []string{AliceKey2, BobKey1, AliceKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{CharlieDID}, + VerificationMethod: []*types.VerificationMethod{ { - signer: AliceKey1, - key: keys[AliceKey2].PrivateKey, + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - PublicKeyMultibase: "z" + base58.Encode(keys[AliceKey2].PublicKey), - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", CharlieDID) + }) + + It("Valid: replacing controller and Verification method ID works with all signatures", func() { + valid = true + signers = []string{AliceKey1, CharlieKey1, AliceKey2} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{CharlieDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - }, - // VM and Controller replacing tests - { - valid: false, - name: "Not Valid: replacing controller and Verification method ID does not work without new sign", - signers: []string{AliceKey2, BobKey1, AliceKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{CharlieDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", CharlieDID) + }) + + // Verification method's tests + // cases: + // - replacing VM controller works + // - replacing VM controller does not work without new signature + // - replacing VM controller does not work without old signature ?????? + // - replacing VM doesn't work without new signature + // - replacing VM doesn't work without old signature + // - replacing VM works with all signatures + // --- adding new VM works + // --- adding new VM without new signature + // --- adding new VM without old signature + + + It("Valid: Replacing VM controller works with one signature", func() { + valid = true + signers = []string{AliceKey1, BobKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: BobDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", CharlieDID), - }, - { - valid: true, - name: "Valid: replacing controller and Verification method ID works with all signatures", - signers: []string{AliceKey1, CharlieKey1, AliceKey2}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{CharlieDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + }) + + It("Not Valid: Replacing VM controller does not work without new signature", func() { + valid =false + signers = []string{AliceKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: BobDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", CharlieDID), - }, - // Verification method's tests - // cases: - // - replacing VM controller works - // - replacing VM controller does not work without new signature - // - replacing VM controller does not work without old signature ?????? - // - replacing VM doesn't work without new signature - // - replacing VM doesn't work without old signature - // - replacing VM works with all signatures - // --- adding new VM works - // --- adding new VM without new signature - // --- adding new VM without old signature - { - valid: true, - name: "Valid: Replacing VM controller works with one signature", - signers: []string{AliceKey1, BobKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) + }) + + It("Not Valid: Replacing VM does not work without new signature", func() { + valid = false + signers = []string{AliceKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - }, - { - valid: false, - name: "Not Valid: Replacing VM controller does not work without new signature", - signers: []string{AliceKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", AliceDID) + }) + It("Not Valid: Replacing VM does not work without old signature", func() { + valid =false + signers = []string{AliceKey2} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID), - }, - { - valid: false, - name: "Not Valid: Replacing VM does not work without new signature", - signers: []string{AliceKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) + }) + + It("Not Valid: Replacing VM works with all signatures", func() { + valid = true + signers = []string{AliceKey1, AliceKey2} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - errMsg: fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", AliceDID), - }, - { - valid: false, - name: "Not Valid: Replacing VM does not work without old signature", - signers: []string{AliceKey2}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + }) + + // Adding VM + + It("Valid: Adding another verification method", func() { + valid = true + signers = []string{AliceKey1, BobKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, - }, - errMsg: fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID), - }, - { - valid: true, - name: "Not Valid: Replacing VM works with all signatures", - signers: []string{AliceKey1, AliceKey2}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: BobDID, }, }, - }, - // Adding VM - { - valid: true, - name: "Valid: Adding another verification method", - signers: []string{AliceKey1, BobKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, + } + }) + + It("Not Valid: Adding another verification method without new sign", func() { + valid = false + signers = []string{AliceKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, - }, - }, - { - valid: false, - name: "Not Valid: Adding another verification method without new sign", - signers: []string{AliceKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: BobDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID), - }, - { - valid: false, - name: "Not Valid: Adding another verification method without old sign", - signers: []string{AliceKey2}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) + }) + + It("Not Valid: Adding another verification method without old sign", func() { + valid = false + signers = []string{AliceKey2} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, - }, - errMsg: fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID), - }, - - // Controller's tests - // cases: - // - replacing Controller works with all signatures - // - replacing Controller doesn't work without old signature - // - replacing Controller doesn't work without new signature - // --- adding Controller works with all signatures - // --- adding Controller doesn't work without old signature - // --- adding Controller doesn't work without new signature - { - valid: true, - name: "Valid: Replace controller works with all signatures", - signers: []string{BobKey1, AliceKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - }, - { - valid: false, - name: "Not Valid: Replace controller doesn't work without old signatures", - signers: []string{BobKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) + }) + + // Controller's tests + // cases: + // - replacing Controller works with all signatures + // - replacing Controller doesn't work without old signature + // - replacing Controller doesn't work without new signature + // --- adding Controller works with all signatures + // --- adding Controller doesn't work without old signature + // --- adding Controller doesn't work without new signature + + It("Valid: Replace controller works with all signatures", func() { + valid = true + signers = []string{BobKey1, AliceKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{BobDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID), - }, - { - valid: false, - name: "Not Valid: Replace controller doesn't work without new signatures", - signers: []string{AliceKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + }) + + It("Not Valid: Replace controller doesn't work without old signatures", func() { + valid = false + signers = []string{BobKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{BobDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID), - }, - // add Controller - { - valid: true, - name: "Valid: Adding second controller works", - signers: []string{AliceKey1, CharlieKey3}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID, CharlieDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) + }) + + It("Not Valid: Replace controller doesn't work without new signatures", func() { + valid = false + signers = []string{AliceKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{BobDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - }, - { - valid: false, - name: "Not Valid: Adding controller without old signature", - signers: []string{BobKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID, BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) + }) + + // add controller + + It("Valid: Adding second controller works", func() { + valid = true + signers = []string{AliceKey1, CharlieKey3} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{AliceDID, CharlieDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID), - }, - { - valid: false, - name: "Not Valid: Add controller without new signature doesn't work", - signers: []string{AliceKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID, BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + }) + + It("Not Valid: Adding controller without old signature", func() { + valid = false + signers = []string{BobKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{AliceDID, BobDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID), - }, - - { - valid: true, - name: "Valid: Adding verification method with the same controller works", - signers: []string{AliceKey1, AliceKey2}, - msg: &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) + }) + + It("Not Valid: Add controller without new signature doesn't work", func() { + valid = false + signers = []string{AliceKey1} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{AliceDID, BobDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - }, - { - valid: true, - name: "Valid: Keeping VM with controller different then subject untouched during update should not require Bob signature", - signers: []string{CharlieKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: CharlieDID, - Authentication: []string{ - CharlieKey1, - CharlieKey2, - CharlieKey3, - }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) + }) - VerificationMethod: []*types.VerificationMethod{ - { - Id: CharlieKey1, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey2, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey3, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey4, - Type: Ed25519VerificationKey2020, - Controller: CharlieDID, - }, + It("Valid: Adding verification method with the same controller works", func() { + valid = true + signers = []string{AliceKey1, AliceKey2} + msg = &types.MsgUpdateDidPayload{ + Id: AliceDID, + Controller: []string{AliceDID}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: AliceKey2, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, - }, - }, - { - valid: true, - name: "Valid: Removing verification method is possible with any kind of valid Bob's key", - signers: []string{BobKey1}, - msg: &types.MsgUpdateDidPayload{ - Id: BobDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: BobKey1, - Type: Ed25519VerificationKey2020, - Controller: BobDID, - }, + { + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, }, }, - errMsg: fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", BobDID), - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - setup := InitEnv(t, keys) - msg := tc.msg - - for _, vm := range msg.VerificationMethod { - if vm.PublicKeyMultibase == "" { - vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].PublicKey) - } - require.NoError(t, err) - } + } + }) - signerKeys := []SignerKey{} - if tc.signerKeys != nil { - signerKeys = tc.signerKeys - } else { - for _, signer := range tc.signers { - signerKeys = append(signerKeys, SignerKey{ - signer: signer, - key: keys[signer].PrivateKey, - }) - } - } + It("Valid: Keeping VM with controller different then subject untouched during update should not require Bob signature", func() { + valid = true + signers = []string{CharlieKey1} + msg = &types.MsgUpdateDidPayload{ + Id: CharlieDID, + Authentication: []string{ + CharlieKey1, + CharlieKey2, + CharlieKey3, + }, - did, err := setup.SendUpdateDid(msg, signerKeys) - - if tc.valid { - require.Nil(t, err) - require.Equal(t, tc.msg.Id, did.Id) - require.Equal(t, tc.msg.Controller, did.Controller) - require.Equal(t, tc.msg.VerificationMethod, did.VerificationMethod) - require.Equal(t, tc.msg.Authentication, did.Authentication) - require.Equal(t, tc.msg.AssertionMethod, did.AssertionMethod) - require.Equal(t, tc.msg.CapabilityInvocation, did.CapabilityInvocation) - require.Equal(t, tc.msg.CapabilityDelegation, did.CapabilityDelegation) - require.Equal(t, tc.msg.KeyAgreement, did.KeyAgreement) - require.Equal(t, tc.msg.AlsoKnownAs, did.AlsoKnownAs) - require.Equal(t, tc.msg.Service, did.Service) - require.Equal(t, tc.msg.Context, did.Context) - } else { - require.Error(t, err) - require.Equal(t, tc.errMsg, err.Error()) - } - }) - } -} + VerificationMethod: []*types.VerificationMethod{ + { + Id: CharlieKey1, + Type: Ed25519VerificationKey2020, + Controller: BobDID, + }, + { + Id: CharlieKey2, + Type: Ed25519VerificationKey2020, + Controller: BobDID, + }, + { + Id: CharlieKey3, + Type: Ed25519VerificationKey2020, + Controller: BobDID, + }, + { + Id: CharlieKey4, + Type: Ed25519VerificationKey2020, + Controller: CharlieDID, + }, + }, + } + }) + + It("Valid: Removing verification method is possible with any kind of valid Bob's key", func() { + valid = true + signers = []string{BobKey1} + msg = &types.MsgUpdateDidPayload{ + Id: BobDID, + VerificationMethod: []*types.VerificationMethod{ + { + Id: BobKey1, + Type: Ed25519VerificationKey2020, + Controller: BobDID, + }, + }, + } + errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", BobDID) + }) +}) From 82feaf758abc609a359f380eb4f62c7209382f97 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Fri, 7 Oct 2022 17:50:50 +0300 Subject: [PATCH 16/76] Add tests for DID and Service validation --- x/cheqd/types/constant_test.go | 51 ++++ x/cheqd/types/did_did_test.go | 406 +++++++++++++++--------------- x/cheqd/types/did_service_test.go | 118 ++++----- x/cheqd/types/types_test.go | 12 + 4 files changed, 325 insertions(+), 262 deletions(-) create mode 100644 x/cheqd/types/constant_test.go create mode 100644 x/cheqd/types/types_test.go diff --git a/x/cheqd/types/constant_test.go b/x/cheqd/types/constant_test.go new file mode 100644 index 000000000..66aa6ec66 --- /dev/null +++ b/x/cheqd/types/constant_test.go @@ -0,0 +1,51 @@ +package types_test +import ( + "encoding/json" + . "github.com/cheqd/cheqd-node/x/cheqd/types" + +) + +var ( + ValidTestDID = "did:cheqd:testnet:123456789abcdefg" + ValidTestDID2 = "did:cheqd:testnet:gfedcba987654321" + InvalidTestDID = "badDid" + ValidEd25519PubKey = "zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX" + NotValidEd25519PubKey = "zF1hVGXXK9rmx5HhMTpGnGQJi" +) + +type TestJWKKey struct { + Kty string `json:"kty"` + N string `json:"n"` + Use string `json:"use"` + Alg string `json:"alg"` + E string `json:"e"` + Kid string `json:"kid"` +} + +var ValidJWKKey = TestJWKKey{ + Kty: "RSA", + N: "o76AudS2rsCvlz_3D47sFkpuz3NJxgLbXr1cHdmbo9xOMttPMJI97f0rHiSl9stltMi87KIOEEVQWUgMLaWQNaIZThgI1seWDAGRw59AO5sctgM1wPVZYt40fj2Qw4KT7m4RLMsZV1M5NYyXSd1lAAywM4FT25N0RLhkm3u8Hehw2Szj_2lm-rmcbDXzvjeXkodOUszFiOqzqBIS0Bv3c2zj2sytnozaG7aXa14OiUMSwJb4gmBC7I0BjPv5T85CH88VOcFDV51sO9zPJaBQnNBRUWNLh1vQUbkmspIANTzj2sN62cTSoxRhSdnjZQ9E_jraKYEW5oizE9Dtow4EvQ", + Use: "sig", + Alg: "RS256", + E: "AQAB", + Kid: "6a8ba5652a7044121d4fedac8f14d14c54e4895b", +} + +var NotValidJWKKey = TestJWKKey{ + Kty: "SomeOtherKeyType", + N: "o76AudS2rsCvlz_3D47sFkpuz3NJxgLbXr1cHdmbo9xOMttPMJI97f0rHiSl9stltMi87KIOEEVQWUgMLaWQNaIZThgI1seWDAGRw59AO5sctgM1wPVZYt40fj2Qw4KT7m4RLMsZV1M5NYyXSd1lAAywM4FT25N0RLhkm3u8Hehw2Szj_2lm-rmcbDXzvjeXkodOUszFiOqzqBIS0Bv3c2zj2sytnozaG7aXa14OiUMSwJb4gmBC7I0BjPv5T85CH88VOcFDV51sO9zPJaBQnNBRUWNLh1vQUbkmspIANTzj2sN62cTSoxRhSdnjZQ9E_jraKYEW5oizE9Dtow4EvQ", + Use: "sig", + Alg: "RS256", + E: "AQAB", + Kid: "6a8ba5652a7044121d4fedac8f14d14c54e4895b", +} + +var ( + ValidJWKByte, _ = json.Marshal(ValidJWKKey) + NotValidJWKByte, _ = json.Marshal(NotValidJWKKey) +) + +var ( + ValidPublicKeyJWK = JSONToPubKeyJWK(string(ValidJWKByte)) + NotValidPublicKeyJWK = JSONToPubKeyJWK(string(NotValidJWKByte)) +) \ No newline at end of file diff --git a/x/cheqd/types/did_did_test.go b/x/cheqd/types/did_did_test.go index ad6ebbfde..eda878553 100644 --- a/x/cheqd/types/did_did_test.go +++ b/x/cheqd/types/did_did_test.go @@ -1,234 +1,230 @@ -package types +package types_test import ( "fmt" - "testing" - "github.com/stretchr/testify/require" -) + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" -var ( - ValidTestDID = "did:cheqd:testnet:123456789abcdefg" - ValidTestDID2 = "did:cheqd:testnet:gfedcba987654321" - InvalidTestDID = "badDid" - ValidEd25519PubKey = "zF1hVGXXK9rmx5HhMTpGnGQJiab9qrFJbQXBRhSmYjQWX" - NotValidEd25519PubKey = "zF1hVGXXK9rmx5HhMTpGnGQJi" + . "github.com/cheqd/cheqd-node/x/cheqd/types" ) -func TestDidValidation(t *testing.T) { - cases := []struct { - name string - struct_ *Did - allowedNamespaces []string - isValid bool - errorMsg string - }{ - { - name: "Valid: Id: allowed DID", - struct_: &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, - }, +var _ = Describe("DID Validation tests", func() { + + var struct_ *Did + var allowedNamespaces []string + var isValid bool + var errorMsg string + + BeforeEach(func() { + struct_ = &Did{} + allowedNamespaces = []string{} + isValid = false + errorMsg = "" + }) + + AfterEach(func() { + err := struct_.Validate(allowedNamespaces) + + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } + }) + + It("Valid: Id: allowed DID", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - isValid: true, - errorMsg: "", - }, - { - name: "Not valid: Id: not allowed DID", - struct_: &Did{ - Id: InvalidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, - }, + } + isValid = true + errorMsg = "" + }) + + It("Not valid: Id: not allowed DID", func() { + struct_ = &Did{ + Id: InvalidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - isValid: false, - errorMsg: "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).).", - }, - { - name: "Valid: Verification Method: all is fine with type Ed25519VerificationKey2020", - struct_: &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, - }, + } + isValid = false + errorMsg = "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).)." + }) + + It("Valid: Verification Method: all is fine with type Ed25519VerificationKey2020", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - isValid: true, - errorMsg: "", - }, - { - name: "Valid: Verification Method: all is fine with type jwk", - struct_: &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "JsonWebKey2020", - Controller: ValidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, + } + isValid = true + errorMsg = "" + }) + + It("Valid: Verification Method: all is fine with type jwk", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "JsonWebKey2020", + Controller: ValidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", }, }, - isValid: true, - errorMsg: "", - }, - { - name: "Not valid: Verification Method: Wrong id", - struct_: &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: InvalidTestDID, - Type: "JsonWebKey2020", - Controller: ValidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, + } + isValid = true + errorMsg = "" + }) + + It("Not valid: Verification Method: Wrong id", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: InvalidTestDID, + Type: "JsonWebKey2020", + Controller: ValidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", }, }, - isValid: false, - errorMsg: "verification_method: (0: (id: unable to split did into method, namespace and id.).).", - }, - { - name: "Not valid: Verification Method: Wrong controller", - struct_: &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "JsonWebKey2020", - Controller: InvalidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, + } + isValid = false + errorMsg = "verification_method: (0: (id: unable to split did into method, namespace and id.).)." + }) + + It("Not valid: Verification Method: Wrong controller", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "JsonWebKey2020", + Controller: InvalidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", }, }, - isValid: false, - errorMsg: "verification_method: (0: (controller: unable to split did into method, namespace and id.).).", - }, - { - name: "Valid: Controller: List of DIDs allowed", - struct_: &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID, ValidTestDID2}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, - }, + } + isValid = false + errorMsg = "verification_method: (0: (controller: unable to split did into method, namespace and id.).)." + }) + + It("Valid: Controller: List of DIDs allowed", func() { + struct_ = &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID, ValidTestDID2}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - isValid: true, - errorMsg: "", - }, - { - name: "Not valid: Controller: List of DIDs is not allowed", - struct_: &Did{ - Context: nil, - Id: ValidTestDID, - Controller: []string{ValidTestDID, InvalidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, - }, + } + isValid = true + errorMsg = "" + }) + + It("Not valid: Controller: List of DIDs is not allowed", func() { + struct_ = &Did{ + Context: nil, + Id: ValidTestDID, + Controller: []string{ValidTestDID, InvalidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - isValid: false, - errorMsg: "controller: (1: unable to split did into method, namespace and id.).", - }, - { - name: "Allowed namespaces: Negative", - struct_: &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, - }, + } + isValid = false + errorMsg = "controller: (1: unable to split did into method, namespace and id.)." + }) + + It("Allowed namespaces: Negative", func() { + struct_ = &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - allowedNamespaces: []string{"mainnet"}, - isValid: false, - errorMsg: "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).).", - }, - { - name: "Controller duplicated: negative", - struct_: &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID, ValidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, - }, + } + allowedNamespaces = []string{"mainnet"} + isValid = false + errorMsg = "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).)." + }) + + It("Controller duplicated: negative", func() { + struct_ = &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID, ValidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - isValid: false, - errorMsg: "controller: there should be no duplicates.", - }, - { - name: "VM duplicated: negative", - struct_: &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, - }, - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, - }, + } + isValid = false + errorMsg = "controller: there should be no duplicates." + }) + + It("VM duplicated: negative", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, }, }, - isValid: false, - errorMsg: "verification_method: there are verification method duplicates.", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := tc.struct_.Validate(tc.allowedNamespaces) - - if tc.isValid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Contains(t, err.Error(), tc.errorMsg) - } - }) - } -} + } + isValid = false + errorMsg = "verification_method: there are verification method duplicates." + }) +}) diff --git a/x/cheqd/types/did_service_test.go b/x/cheqd/types/did_service_test.go index a7475e471..ce854a72d 100644 --- a/x/cheqd/types/did_service_test.go +++ b/x/cheqd/types/did_service_test.go @@ -1,66 +1,70 @@ -package types +package types_test import ( - "testing" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" - "github.com/stretchr/testify/require" + . "github.com/cheqd/cheqd-node/x/cheqd/types" ) -func TestServiceValidation(t *testing.T) { - cases := []struct { - name string - struct_ Service - baseDid string - allowedNamespaces []string - isValid bool - errorMsg string - }{ - { - name: "positive", - struct_: Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - }, - baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", - allowedNamespaces: []string{""}, - isValid: true, - errorMsg: "", - }, - { - name: "negative: namespace", - struct_: Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - }, - allowedNamespaces: []string{"mainnet"}, - isValid: false, - errorMsg: "id: did namespace must be one of: mainnet.", - }, - { - name: "negative: base did", - struct_: Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - }, - baseDid: "did:cheqd:baaaaaaaaaaaaaab", - isValid: false, - errorMsg: "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab.", - }, - } +var _ = Describe("DID Validation tests", func() { - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := tc.struct_.Validate(tc.baseDid, tc.allowedNamespaces) + var struct_ Service + var baseDid string + var allowedNamespaces []string + var isValid bool + var errorMsg string - if tc.isValid { - require.NoError(t, err) + BeforeEach(func() { + struct_ = Service{} + baseDid = "" + allowedNamespaces = []string{} + isValid = false + errorMsg = "" + }) + + AfterEach(func() { + err := struct_.Validate(baseDid, allowedNamespaces) + + if isValid { + Expect(err).To(BeNil()) } else { - require.Error(t, err) - require.Equal(t, err.Error(), tc.errorMsg) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) } - }) - } -} + }) + + It("Positive case", func() { + struct_ = Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + } + baseDid = "did:cheqd:aaaaaaaaaaaaaaaa" + allowedNamespaces = []string{""} + isValid = true + errorMsg = "" + }) + + It("Negative: namespace", func() { + struct_ = Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + } + allowedNamespaces = []string{"mainnet"} + isValid = false + errorMsg = "id: did namespace must be one of: mainnet." + }) + + It("Negative: Base did", func() { + struct_ = Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + } + baseDid = "did:cheqd:baaaaaaaaaaaaaab" + isValid = false + errorMsg = "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab." + }) +}) diff --git a/x/cheqd/types/types_test.go b/x/cheqd/types/types_test.go new file mode 100644 index 000000000..550174758 --- /dev/null +++ b/x/cheqd/types/types_test.go @@ -0,0 +1,12 @@ +package types_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "testing" +) + +func TestUtils(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Types Tests Suite") +} From 10fef06dcc65979d85dea03625affd2da1bc7e4e Mon Sep 17 00:00:00 2001 From: Tasos <50984242+Eengineer1@users.noreply.github.com> Date: Fri, 7 Oct 2022 22:05:18 +0300 Subject: [PATCH 17/76] Switched `x/resource` tests to Ginkgo suite --- go.mod | 3 + go.sum | 3 + x/cheqd/tests/create_did_test.go | 33 ++- x/cheqd/tests/signature_verification_test.go | 7 +- x/cheqd/tests/tests_suite_test.go | 5 +- x/cheqd/tests/update_did_test.go | 38 ++- x/cheqd/tests/utils.go | 1 + x/cheqd/utils/crypto_test.go | 1 - x/cheqd/utils/did_test.go | 19 +- x/cheqd/utils/encoding_test.go | 27 +- x/cheqd/utils/proto_test.go | 2 +- x/cheqd/utils/str_test.go | 6 +- x/cheqd/utils/utils_suite_test.go | 4 +- .../keeper/msg_server_create_resource.go | 4 +- x/resource/tests/constants.go | 4 +- x/resource/tests/create_resource_test.go | 244 +++++++++--------- .../tests/query_all_resource_versions_test.go | 168 ++++++------ .../tests/query_collection_resources_test.go | 119 +++++---- x/resource/tests/query_resource_test.go | 153 +++++------ x/resource/tests/setup.go | 8 +- x/resource/tests/tests_suite_test.go | 13 + .../tx_msg_create_resource_payload_test.go | 79 +++--- x/resource/types/types_suite_test.go | 13 + x/resource/utils/media_type_test.go | 48 ++-- x/resource/utils/testdata/resource.png | Bin 0 -> 98198 bytes x/resource/utils/utils_suite_test.go | 13 + 26 files changed, 521 insertions(+), 494 deletions(-) create mode 100644 x/resource/tests/tests_suite_test.go create mode 100644 x/resource/types/types_suite_test.go create mode 100644 x/resource/utils/testdata/resource.png create mode 100644 x/resource/utils/utils_suite_test.go diff --git a/go.mod b/go.mod index 135f45a84..e42355e07 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( github.com/go-kit/log v0.2.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/gateway v1.1.0 // indirect @@ -71,6 +72,7 @@ require ( github.com/google/btree v1.0.0 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/google/orderedcode v0.0.1 // indirect + github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect @@ -135,6 +137,7 @@ require ( golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect + golang.org/x/tools v0.1.12 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.4 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index b635b4121..a3a58eaa0 100644 --- a/go.sum +++ b/go.sum @@ -368,6 +368,7 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -470,6 +471,7 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -1482,6 +1484,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index f4484fd6d..3c60d01cb 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -19,11 +19,11 @@ var _ = Describe("Create DID tests", func() { var keys map[string]KeyPair var signers []string var msg *types.MsgCreateDidPayload - var errMsg = "" + errMsg := "" var setup TestSetup var err error - var mainKeys = GenerateTestKeys() + mainKeys := GenerateTestKeys() BeforeEach(func() { // setup @@ -35,7 +35,6 @@ var _ = Describe("Create DID tests", func() { }) AfterEach(func() { - setup = InitEnv(mainKeys) for _, vm := range msg.VerificationMethod { @@ -160,7 +159,7 @@ var _ = Describe("Create DID tests", func() { AliceKey1: mainKeys[AliceKey1], } signers = []string{AliceKey1, ImposterKey1} - msg= &types.MsgCreateDidPayload{ + msg = &types.MsgCreateDidPayload{ Id: ImposterDID, CapabilityInvocation: []string{ImposterKey1}, Controller: []string{AliceDID}, @@ -263,9 +262,9 @@ var _ = Describe("Create DID tests", func() { } }) -// ************************** -// ***** Negative cases ***** -// ************************** + // ************************** + // ***** Negative cases ***** + // ************************** It("Not Valid: Second controller did not sign request", func() { valid = false @@ -280,7 +279,7 @@ var _ = Describe("Create DID tests", func() { errMsg = fmt.Sprintf("signer: %s: signature is required but not found", BobDID) }) - It("Not Valid: No signature", func(){ + It("Not Valid: No signature", func() { valid = false msg = &types.MsgCreateDidPayload{ Id: ImposterDID, @@ -288,8 +287,8 @@ var _ = Describe("Create DID tests", func() { } errMsg = fmt.Sprintf("signer: %s: signature is required but not found", AliceDID) }) - - It("Not Valid: Controller not found", func(){ + + It("Not Valid: Controller not found", func() { valid = false msg = &types.MsgCreateDidPayload{ Id: ImposterDID, @@ -300,10 +299,10 @@ var _ = Describe("Create DID tests", func() { AliceKey1: mainKeys[AliceKey1], ImposterKey1: GenerateKeyPair(), } - errMsg = fmt.Sprintf("%s: DID Doc not found", NotFounDID) + errMsg = fmt.Sprintf("%s: DID Doc not found", NotFounDID) }) - It("Not Valid: Wrong signature", func(){ + It("Not Valid: Wrong signature", func() { valid = false msg = &types.MsgCreateDidPayload{ Id: ImposterDID, @@ -316,8 +315,8 @@ var _ = Describe("Create DID tests", func() { errMsg = fmt.Sprintf("method id: %s: invalid signature detected", AliceKey1) }) - It("Not Valid: DID signed by wrong controller", func(){ - valid =false + It("Not Valid: DID signed by wrong controller", func() { + valid = false msg = &types.MsgCreateDidPayload{ Id: ImposterDID, Authentication: []string{ImposterKey1}, @@ -337,7 +336,7 @@ var _ = Describe("Create DID tests", func() { errMsg = fmt.Sprintf("signer: %s: signature is required but not found", ImposterDID) }) - It("Not Valid: DID self-signed by not existing verification method", func(){ + It("Not Valid: DID self-signed by not existing verification method", func() { valid = false msg = &types.MsgCreateDidPayload{ Id: ImposterDID, @@ -358,7 +357,7 @@ var _ = Describe("Create DID tests", func() { errMsg = fmt.Sprintf("%s: verification method not found", ImposterKey2) }) - It("Not Valid: Self-signature not found", func(){ + It("Not Valid: Self-signature not found", func() { valid = false msg = &types.MsgCreateDidPayload{ Id: ImposterDID, @@ -381,7 +380,7 @@ var _ = Describe("Create DID tests", func() { errMsg = fmt.Sprintf("%s: verification method not found", ImposterKey2) }) - It("Not Valid: DID Doc already exists", func(){ + It("Not Valid: DID Doc already exists", func() { valid = false keys = map[string]KeyPair{ CharlieKey1: GenerateKeyPair(), diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go index ab371ac7c..32b43dfcb 100644 --- a/x/cheqd/tests/signature_verification_test.go +++ b/x/cheqd/tests/signature_verification_test.go @@ -80,7 +80,7 @@ var _ = Describe("Signature Verification. Remove signature/VM", func() { // Create dids aliceDid = setup.CreateDid(ApubKey, AliceDID) bobDid = setup.CreateDid(BpubKey, BobDID) - + // Collect private keys aliceKeys = map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} bobKeys = map[string]ed25519.PrivateKey{BobKey1: BprivKey} @@ -92,11 +92,9 @@ var _ = Describe("Signature Verification. Remove signature/VM", func() { Type: Ed25519VerificationKey2020, PublicKeyMultibase: "z" + base58.Encode(BpubKey), }) - }) It("should fails cause old signature is required for removing this signature", func() { - // Send dids _, _ = setup.SendCreateDid(bobDid, bobKeys) _, _ = setup.SendCreateDid(aliceDid, aliceKeys) @@ -123,9 +121,8 @@ var _ = Describe("Signature Verification. Remove signature/VM", func() { updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - // check + // check Expect(len(aliceDid.VerificationMethod)).To(Not(Equal(len(receivedDid.VerificationMethod)))) Expect(reflect.DeepEqual(aliceDid.VerificationMethod[0], receivedDid.VerificationMethod[0])).To(BeTrue()) - }) }) diff --git a/x/cheqd/tests/tests_suite_test.go b/x/cheqd/tests/tests_suite_test.go index cd8579e57..bd60da49f 100644 --- a/x/cheqd/tests/tests_suite_test.go +++ b/x/cheqd/tests/tests_suite_test.go @@ -1,14 +1,13 @@ package tests_test import ( + "testing" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) func TestTestsGeneral(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "General Tests Suite") } - diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index 7ff264203..4917283a2 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -17,23 +17,23 @@ var _ = Describe("Update DID tests", func() { var signers []string var signerKeys []SignerKey var msg *types.MsgUpdateDidPayload - var errMsg = "" + errMsg := "" var setup TestSetup var err error - var mainKeys = map[string]KeyPair{ - AliceKey1: GenerateKeyPair(), - AliceKey2: GenerateKeyPair(), - BobKey1: GenerateKeyPair(), - BobKey2: GenerateKeyPair(), - BobKey3: GenerateKeyPair(), - BobKey4: GenerateKeyPair(), - CharlieKey1: GenerateKeyPair(), - CharlieKey2: GenerateKeyPair(), - CharlieKey3: GenerateKeyPair(), - CharlieKey4: GenerateKeyPair(), - ImposterKey1: GenerateKeyPair(), - } + mainKeys := map[string]KeyPair{ + AliceKey1: GenerateKeyPair(), + AliceKey2: GenerateKeyPair(), + BobKey1: GenerateKeyPair(), + BobKey2: GenerateKeyPair(), + BobKey3: GenerateKeyPair(), + BobKey4: GenerateKeyPair(), + CharlieKey1: GenerateKeyPair(), + CharlieKey2: GenerateKeyPair(), + CharlieKey3: GenerateKeyPair(), + CharlieKey4: GenerateKeyPair(), + ImposterKey1: GenerateKeyPair(), + } BeforeEach(func() { // setup @@ -45,9 +45,8 @@ var _ = Describe("Update DID tests", func() { }) AfterEach(func() { - setup = InitEnv(mainKeys) - + for _, vm := range msg.VerificationMethod { if vm.PublicKeyMultibase == "" { vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, mainKeys[vm.Id].PublicKey) @@ -159,7 +158,6 @@ var _ = Describe("Update DID tests", func() { // --- adding new VM without new signature // --- adding new VM without old signature - It("Valid: Replacing VM controller works with one signature", func() { valid = true signers = []string{AliceKey1, BobKey1} @@ -176,7 +174,7 @@ var _ = Describe("Update DID tests", func() { }) It("Not Valid: Replacing VM controller does not work without new signature", func() { - valid =false + valid = false signers = []string{AliceKey1} msg = &types.MsgUpdateDidPayload{ Id: AliceDID, @@ -207,7 +205,7 @@ var _ = Describe("Update DID tests", func() { errMsg = fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", AliceDID) }) It("Not Valid: Replacing VM does not work without old signature", func() { - valid =false + valid = false signers = []string{AliceKey2} msg = &types.MsgUpdateDidPayload{ Id: AliceDID, @@ -469,7 +467,7 @@ var _ = Describe("Update DID tests", func() { Controller: CharlieDID, }, }, - } + } }) It("Valid: Removing verification method is possible with any kind of valid Bob's key", func() { diff --git a/x/cheqd/tests/utils.go b/x/cheqd/tests/utils.go index ac0a3ef88..f6a79c69c 100644 --- a/x/cheqd/tests/utils.go +++ b/x/cheqd/tests/utils.go @@ -2,6 +2,7 @@ package tests import ( "math/rand" + . "github.com/onsi/gomega" ) diff --git a/x/cheqd/utils/crypto_test.go b/x/cheqd/utils/crypto_test.go index 6cc5eb869..ee1ec8502 100644 --- a/x/cheqd/utils/crypto_test.go +++ b/x/cheqd/utils/crypto_test.go @@ -1,7 +1,6 @@ package utils_test import ( - "github.com/multiformats/go-multibase" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/x/cheqd/utils/did_test.go b/x/cheqd/utils/did_test.go index 13186fd49..90ce24cb9 100644 --- a/x/cheqd/utils/did_test.go +++ b/x/cheqd/utils/did_test.go @@ -1,16 +1,16 @@ package utils_test import ( + . "github.com/cheqd/cheqd-node/x/cheqd/utils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/cheqd/cheqd-node/x/cheqd/utils" ) var _ = Describe("DID checks", func() { DescribeTable("Check is valid ID (for example did:cheqD:testnet:123456789abcdefg and ID is 123456789abcdefg)", func(expected bool, did string) { - Expect(IsValidID(did)).To(Equal(expected)) + Expect(IsValidID(did)).To(Equal(expected)) }, Entry("Valid base58, 16 symbols", true, "123456789abcdefg"), Entry("Valid base58, 32 symbols", true, "123456789abcdefg123456789abcdefg"), @@ -24,7 +24,7 @@ var _ = Describe("DID checks", func() { DescribeTable("DID validation", func(expected bool, did string, method string, allowedNamespaces []string) { - Expect(IsValidDID(did, method, allowedNamespaces)).To(Equal(expected)) + Expect(IsValidDID(did, method, allowedNamespaces)).To(Equal(expected)) }, Entry("Valid: Inputs: Method and namespace are set", true, "did:cheqd:testnet:123456789abcdefg", "cheqd", []string{"testnet"}), @@ -66,7 +66,6 @@ var _ = Describe("DID checks", func() { // The next test will check more functionality aspects. This one is for testing corner cases Describe("Check splitting functionality", func() { - Context("Valid DID", func() { It("should return expected method, namespace and DID", func() { method, namespace, id := MustSplitDID("did:cheqd:mainnet:qqqqqqqqqqqqqqqq") @@ -79,19 +78,19 @@ var _ = Describe("DID checks", func() { Context("Not valid DID string at all", func() { It("should panic", func() { panicDID := "Not " - Expect(func (){ + Expect(func() { MustSplitDID(panicDID) - }).To(Panic()) + }).To(Panic()) }) }) }) DescribeTable("Check DID splitting and joining", - func(did string) { - method, namespace, id := MustSplitDID(did) - Expect(did).To(Equal(JoinDID(method, namespace, id))) - }, + func(did string) { + method, namespace, id := MustSplitDID(did) + Expect(did).To(Equal(JoinDID(method, namespace, id))) + }, Entry("Full DID", "did:cheqd:testnet:123456789abcdefg"), Entry("Without namespace", "did:cheqd:123456789abcdefg"), Entry("Not cheqd method", "did:NOTcheqd:123456789abcdefg"), diff --git a/x/cheqd/utils/encoding_test.go b/x/cheqd/utils/encoding_test.go index f6ec66f15..30edbd93b 100644 --- a/x/cheqd/utils/encoding_test.go +++ b/x/cheqd/utils/encoding_test.go @@ -2,6 +2,7 @@ package utils_test import ( "encoding/json" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -51,7 +52,7 @@ var _ = Describe("Encoding checks", func() { } }, - Entry("Valid: General pmbkey", "zABCDEFG123456789", true), + Entry("Valid: General pmbkey", "zABCDEFG123456789", true), Entry("Not Valid: cannot be empty", "", false), Entry("Not Valid: without z but base58", "ABCDEFG123456789", false), Entry("Not Valid: without z and not base58", "OIl0ABCDEFG123456789", false), @@ -66,7 +67,7 @@ var _ = Describe("Encoding checks", func() { Ω(_err).ShouldNot(HaveOccurred()) } else { Ω(_err).Should(HaveOccurred()) - } + } }, Entry("Valid: General pmbkey", "ABCDEFG123456789", true), @@ -76,16 +77,16 @@ var _ = Describe("Encoding checks", func() { DescribeTable("Validate JWK", - func(data string, isValid bool) { - _err := ValidateJWK(data) - if isValid { - Ω(_err).ShouldNot(HaveOccurred()) - } else { - Ω(_err).Should(HaveOccurred()) - } - }, + func(data string, isValid bool) { + _err := ValidateJWK(data) + if isValid { + Ω(_err).ShouldNot(HaveOccurred()) + } else { + Ω(_err).Should(HaveOccurred()) + } + }, - Entry("Valid: General jwk", string(ValidJWKByte), true), - Entry("Not Valid: Bad jwk", string(NotValidJWKByte), false), -) + Entry("Valid: General jwk", string(ValidJWKByte), true), + Entry("Not Valid: Bad jwk", string(NotValidJWKByte), false), + ) }) diff --git a/x/cheqd/utils/proto_test.go b/x/cheqd/utils/proto_test.go index 11d4f7a02..18ff21994 100644 --- a/x/cheqd/utils/proto_test.go +++ b/x/cheqd/utils/proto_test.go @@ -10,7 +10,7 @@ import ( var _ = Describe("Proto", func() { Describe("Check that DenomUnit from bank type has expected value", func() { - Context("Denom Unit from cosmos-sdk" ,func () { + Context("Denom Unit from cosmos-sdk", func() { It("should return expected value", func() { Expect(MsgTypeURL(&bank_types.DenomUnit{})).To(Equal("/cosmos.bank.v1beta1.DenomUnit")) }) diff --git a/x/cheqd/utils/str_test.go b/x/cheqd/utils/str_test.go index cb3b5d64e..0e77e86ff 100644 --- a/x/cheqd/utils/str_test.go +++ b/x/cheqd/utils/str_test.go @@ -1,10 +1,11 @@ package utils_test import ( + "sort" + . "github.com/cheqd/cheqd-node/x/cheqd/utils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "sort" ) var _ = Describe("Str utils functionality", func() { @@ -36,7 +37,6 @@ var _ = Describe("Str utils functionality", func() { Entry("Desired element exists at the position 2. Expected: true", []string{"1", "2", "3"}, "2", true), Entry("Desired element exists at the position 3. Expected: true", []string{"1", "2", "3"}, "3", true), Entry("Desired element is absent. Expected: false", []string{"1", "2", "3"}, "123", false), - ) DescribeTable("Substract function", @@ -82,7 +82,6 @@ var _ = Describe("Str utils functionality", func() { Entry("Replace 2 with 3", []string{"1", "2", "3", "2"}, "2", "3", []string{"1", "3", "3", "3"}), ) - DescribeTable("UniqueSorted function", func(input []string, expected []string) { @@ -92,5 +91,4 @@ var _ = Describe("Str utils functionality", func() { Entry("General alphabet reverse list", []string{"bb", "aa"}, []string{"aa", "bb"}), Entry("General number list", []string{"22", "11"}, []string{"11", "22"}), ) - }) diff --git a/x/cheqd/utils/utils_suite_test.go b/x/cheqd/utils/utils_suite_test.go index feade1121..9ca82ff0d 100644 --- a/x/cheqd/utils/utils_suite_test.go +++ b/x/cheqd/utils/utils_suite_test.go @@ -1,10 +1,10 @@ package utils_test import ( + "testing" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - "testing" ) func TestUtils(t *testing.T) { diff --git a/x/resource/keeper/msg_server_create_resource.go b/x/resource/keeper/msg_server_create_resource.go index 3fdefe82e..14a3d1bad 100644 --- a/x/resource/keeper/msg_server_create_resource.go +++ b/x/resource/keeper/msg_server_create_resource.go @@ -46,8 +46,8 @@ func (k msgServer) CreateResource(goCtx context.Context, msg *types.MsgCreateRes // Build Resource resource := msg.Payload.ToResource() - - resource.Header.Checksum = sha256.New().Sum(resource.Data) + checksum := sha256.Sum256([]byte(resource.Data)) + resource.Header.Checksum = checksum[:] resource.Header.Created = ctx.BlockTime().Format(time.RFC3339) resource.Header.MediaType = utils.DetectMediaType(resource.Data) diff --git a/x/resource/tests/constants.go b/x/resource/tests/constants.go index 6f2befe27..4571fe208 100644 --- a/x/resource/tests/constants.go +++ b/x/resource/tests/constants.go @@ -23,7 +23,7 @@ const ( func ExistingResource() types.Resource { data := []byte(SchemaData) - checksum := sha256.New().Sum(data) + checksum := sha256.Sum256(data) return types.Resource{ Header: &types.ResourceHeader{ CollectionId: ExistingDIDIdentifier, @@ -31,7 +31,7 @@ func ExistingResource() types.Resource { Name: "Existing Resource Name", ResourceType: CLSchemaType, MediaType: JsonResourceType, - Checksum: checksum, + Checksum: checksum[:], }, Data: data, } diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index ce4b95b9d..6156e48bf 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -1,133 +1,133 @@ -package tests +package tests_test import ( "crypto/ed25519" "crypto/sha256" "fmt" - "testing" - "github.com/cheqd/cheqd-node/x/cheqd/utils" + cheqdutils "github.com/cheqd/cheqd-node/x/cheqd/utils" + resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" + resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" - // "crypto/sha256" - - "github.com/cheqd/cheqd-node/x/resource/types" - - "github.com/stretchr/testify/require" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) -func TestCreateResource(t *testing.T) { - keys := GenerateTestKeys() - cases := []struct { - valid bool - name string - signerKeys map[string]ed25519.PrivateKey - msg *types.MsgCreateResourcePayload - mediaType string - previousVersionId string - errMsg string - }{ - { - valid: true, - name: "Valid: Works", - signerKeys: map[string]ed25519.PrivateKey{ - ExistingDIDKey: keys[ExistingDIDKey].PrivateKey, - }, - msg: &types.MsgCreateResourcePayload{ - CollectionId: ExistingDIDIdentifier, - Id: ResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - mediaType: JsonResourceType, - previousVersionId: "", - }, - { - valid: true, - name: "Valid: Add new resource version", - signerKeys: map[string]ed25519.PrivateKey{ - ExistingDIDKey: keys[ExistingDIDKey].PrivateKey, - }, - msg: &types.MsgCreateResourcePayload{ - CollectionId: ExistingResource().Header.CollectionId, - Id: ResourceId, - Name: ExistingResource().Header.Name, - ResourceType: ExistingResource().Header.ResourceType, - Data: ExistingResource().Data, - }, - mediaType: ExistingResource().Header.MediaType, - previousVersionId: ExistingResource().Header.Id, - }, - { - valid: false, - name: "Not Valid: No signature", - signerKeys: map[string]ed25519.PrivateKey{}, - msg: &types.MsgCreateResourcePayload{ - CollectionId: ExistingDIDIdentifier, - Id: ResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - mediaType: JsonResourceType, - errMsg: fmt.Sprintf("signer: %s: signature is required but not found", ExistingDID), - }, - { - valid: false, - name: "Not Valid: Invalid Resource Id", - signerKeys: map[string]ed25519.PrivateKey{}, - msg: &types.MsgCreateResourcePayload{ - CollectionId: ExistingDIDIdentifier, - Id: IncorrectResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - mediaType: JsonResourceType, - errMsg: fmt.Sprintf("signer: %s: signature is required but not found", ExistingDID), - }, - { - valid: false, - name: "Not Valid: DID Doc is not found", - signerKeys: map[string]ed25519.PrivateKey{}, - msg: &types.MsgCreateResourcePayload{ - CollectionId: NotFoundDIDIdentifier, - Id: IncorrectResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - mediaType: JsonResourceType, - errMsg: fmt.Sprintf("did:cheqd:test:%s: not found", NotFoundDIDIdentifier), - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - msg := tc.msg - resourceSetup := InitEnv(t, keys[ExistingDIDKey].PublicKey, keys[ExistingDIDKey].PrivateKey) - - resource, err := resourceSetup.SendCreateResource(msg, tc.signerKeys) - if tc.valid { - require.Nil(t, err) +var _ = Describe("CreateResource", func() { + Describe("Validate", func() { + var setup resourcetests.TestSetup + var err error + keys := resourcetests.GenerateTestKeys() + BeforeEach(func() { + setup = resourcetests.Setup() + didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) + _, err = setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) + resourcePayload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) + _, err = setup.SendCreateResource(resourcePayload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) + }) + DescribeTable("Validate MsgCreateResource", + func( + valid bool, + signerKeys map[string]ed25519.PrivateKey, + msg *resourcetypes.MsgCreateResourcePayload, + mediaType string, + previousVersionId string, + errMsg string, + ) { + resource, err := setup.SendCreateResource(msg, signerKeys) + if valid { + Expect(err).To(BeNil()) - did := utils.JoinDID("cheqd", "test", resource.Header.CollectionId) - didStateValue, err := resourceSetup.Keeper.GetDid(&resourceSetup.Ctx, did) - require.Nil(t, err) - require.Contains(t, didStateValue.Metadata.Resources, resource.Header.Id) + did := cheqdutils.JoinDID("cheqd", "test", resource.Header.CollectionId) + didStateValue, err := setup.Keeper.GetDid(&setup.Ctx, did) + Expect(err).To(BeNil()) + Expect(didStateValue.Metadata.Resources).Should(ContainElement(resource.Header.Id)) - require.Equal(t, tc.msg.CollectionId, resource.Header.CollectionId) - require.Equal(t, tc.msg.Id, resource.Header.Id) - require.Equal(t, tc.mediaType, resource.Header.MediaType) - require.Equal(t, tc.msg.ResourceType, resource.Header.ResourceType) - require.Equal(t, tc.msg.Data, resource.Data) - require.Equal(t, tc.msg.Name, resource.Header.Name) - require.Equal(t, sha256.New().Sum(resource.Data), resource.Header.Checksum) - require.Equal(t, tc.previousVersionId, resource.Header.PreviousVersionId) - } else { - require.Error(t, err) - require.Equal(t, tc.errMsg, err.Error()) - } - }) - } -} + Expect(resource.Header.CollectionId).To(Equal(msg.CollectionId)) + Expect(resource.Header.Id).To(Equal(msg.Id)) + Expect(resource.Header.Name).To(Equal(msg.Name)) + Expect(resource.Header.ResourceType).To(Equal(msg.ResourceType)) + Expect(resource.Header.MediaType).To(Equal(mediaType)) + Expect(resource.Header.PreviousVersionId).To(Equal(previousVersionId)) + expectedChecksum := sha256.Sum256(msg.Data) + Expect(resource.Header.Checksum).To(Equal(expectedChecksum[:])) + } else { + Expect(err).ToNot(BeNil()) + Expect(err.Error()).To(Equal(errMsg)) + } + }, + Entry("Valid: Works", + true, + map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + &resourcetypes.MsgCreateResourcePayload{ + CollectionId: resourcetests.ExistingDIDIdentifier, + Id: resourcetests.ResourceId, + Name: "Test Resource Name", + ResourceType: resourcetests.CLSchemaType, + Data: []byte(resourcetests.SchemaData), + }, + resourcetests.JsonResourceType, + "", + "", + ), + Entry("Valid: Add new resource version", + true, + map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + &resourcetypes.MsgCreateResourcePayload{ + CollectionId: resourcetests.ExistingResource().Header.CollectionId, + Id: resourcetests.ResourceId, + Name: resourcetests.ExistingResource().Header.Name, + ResourceType: resourcetests.ExistingResource().Header.ResourceType, + Data: resourcetests.ExistingResource().Data, + }, + resourcetests.ExistingResource().Header.MediaType, + resourcetests.ExistingResource().Header.Id, + "", + ), + Entry("Invalid: No signature", + false, + map[string]ed25519.PrivateKey{}, + &resourcetypes.MsgCreateResourcePayload{ + CollectionId: resourcetests.ExistingDIDIdentifier, + Id: resourcetests.ResourceId, + Name: "Test Resource Name", + ResourceType: resourcetests.CLSchemaType, + Data: []byte(resourcetests.SchemaData), + }, + resourcetests.JsonResourceType, + "", + fmt.Errorf("signer: %s: signature is required but not found", resourcetests.ExistingDID).Error(), + ), + Entry("Invalid: Resource Id is not an acceptable format", + false, + map[string]ed25519.PrivateKey{}, + &resourcetypes.MsgCreateResourcePayload{ + CollectionId: resourcetests.ExistingDIDIdentifier, + Id: resourcetests.IncorrectResourceId, + Name: "Test Resource Name", + ResourceType: resourcetests.CLSchemaType, + Data: []byte(resourcetests.SchemaData), + }, + resourcetests.JsonResourceType, + "", + fmt.Errorf("signer: %s: signature is required but not found", resourcetests.ExistingDID).Error(), + ), + Entry("Invalid: DidDoc not found", + false, + map[string]ed25519.PrivateKey{}, + &resourcetypes.MsgCreateResourcePayload{ + CollectionId: resourcetests.NotFoundDIDIdentifier, + Id: resourcetests.IncorrectResourceId, + Name: "Test Resource Name", + ResourceType: resourcetests.CLSchemaType, + Data: []byte(resourcetests.SchemaData), + }, + resourcetests.JsonResourceType, + "", + fmt.Errorf("did:cheqd:test:%s: not found", resourcetests.NotFoundDIDIdentifier).Error(), + ), + ) + }) +}) diff --git a/x/resource/tests/query_all_resource_versions_test.go b/x/resource/tests/query_all_resource_versions_test.go index fd90c72da..e70307963 100644 --- a/x/resource/tests/query_all_resource_versions_test.go +++ b/x/resource/tests/query_all_resource_versions_test.go @@ -1,99 +1,99 @@ -package tests +package tests_test import ( "crypto/ed25519" "fmt" - "testing" - cheqdtests "github.com/cheqd/cheqd-node/x/cheqd/tests" + resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" "github.com/cheqd/cheqd-node/x/resource/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" -) - -func SendAnotherResourceVersion(t require.TestingT, resourceSetup TestSetup, keys map[string]cheqdtests.KeyPair) types.Resource { - newResourcePayload := GenerateCreateResourcePayload(ExistingResource()) - newResourcePayload.Id = AnotherResourceId - didKey := map[string]ed25519.PrivateKey{ - ExistingDIDKey: keys[ExistingDIDKey].PrivateKey, - } - newResourcePayload.Name = "AnotherResourceVersion" - createdResource, err := resourceSetup.SendCreateResource(newResourcePayload, didKey) - require.Nil(t, err) - return *createdResource -} + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) -func TestQueryGetAllResourceVersions(t *testing.T) { - keys := GenerateTestKeys() - existingResource := ExistingResource() - cases := []struct { - valid bool - name string - msg *types.QueryGetAllResourceVersionsRequest - response *types.QueryGetAllResourceVersionsResponse - errMsg string - }{ - { - valid: true, - name: "Valid: Works", - msg: &types.QueryGetAllResourceVersionsRequest{ - CollectionId: ExistingDIDIdentifier, - Name: existingResource.Header.Name, - }, - response: &types.QueryGetAllResourceVersionsResponse{ - Resources: []*types.ResourceHeader{existingResource.Header}, - }, - errMsg: "", - }, - { - valid: false, - name: "Not Valid: DID Doc is not found", - msg: &types.QueryGetAllResourceVersionsRequest{ - CollectionId: NotFoundDIDIdentifier, - Name: existingResource.Header.Name, - }, - response: nil, - errMsg: fmt.Sprintf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier), - }, - } +var _ = Describe("QueryAllResourceVersions", func() { + Describe("Validate", func() { + var setup resourcetests.TestSetup + keys := resourcetests.GenerateTestKeys() + BeforeEach(func() { + setup = resourcetests.Setup() + didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) + _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) + payload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) + _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) + }) + DescribeTable("Validate QueryGetAllResourceVersionsRequest", + func( + valid bool, + signerKeys map[string]ed25519.PrivateKey, + msg *types.QueryGetAllResourceVersionsRequest, + response *types.QueryGetAllResourceVersionsResponse, + errMsg string, + ) { + existingResource := resourcetests.ExistingResource() - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - msg := tc.msg - resourceSetup := InitEnv(t, keys[ExistingDIDKey].PublicKey, keys[ExistingDIDKey].PrivateKey) + payload := resourcetests.GenerateCreateResourcePayload(existingResource) + payload.Id = resourcetests.ResourceId - newResourcePayload := GenerateCreateResourcePayload(ExistingResource()) - newResourcePayload.Id = ResourceId - didKey := map[string]ed25519.PrivateKey{ - ExistingDIDKey: keys[ExistingDIDKey].PrivateKey, - } - // Resource with the same version but another Id - createdResource, err := resourceSetup.SendCreateResource(newResourcePayload, didKey) - require.Nil(t, err) + nextVersionResource, err := setup.SendCreateResource(payload, signerKeys) + Expect(err).To(BeNil()) + Expect(nextVersionResource).ToNot(Equal(existingResource)) - // Send another Resource but with another Name (should affect the version choosing) - SendAnotherResourceVersion(t, resourceSetup, keys) + payload = resourcetests.GenerateCreateResourcePayload(existingResource) + payload.Id = resourcetests.AnotherResourceId + payload.Name = "AnotherResourceVersion" + differentResource, err := setup.SendCreateResource(payload, signerKeys) + Expect(err).To(BeNil()) + Expect(differentResource).ToNot(Equal(existingResource)) + Expect(differentResource).ToNot(Equal(nextVersionResource)) - queryResponse, err := resourceSetup.QueryServer.AllResourceVersions(sdk.WrapSDKContext(resourceSetup.Ctx), msg) + queryResponse, err := setup.QueryServer.AllResourceVersions(sdk.WrapSDKContext(setup.Ctx), msg) - if tc.valid { - resources := queryResponse.Resources - existingResource.Header.NextVersionId = createdResource.Header.Id - expectedResources := map[string]types.Resource{ - existingResource.Header.Id: existingResource, - createdResource.Header.Id: *createdResource, - } - require.Nil(t, err) - require.Equal(t, len(expectedResources), len(resources)) - for _, r := range resources { - r.Created = expectedResources[r.Id].Header.Created - require.Equal(t, r, expectedResources[r.Id].Header) + if valid { + resources := queryResponse.Resources + existingResource.Header.NextVersionId = nextVersionResource.Header.Id + expectedResources := map[string]types.Resource{ + existingResource.Header.Id: existingResource, + nextVersionResource.Header.Id: *nextVersionResource, + } + Expect(err).To(BeNil()) + Expect(len(resources)).To(Equal(len(expectedResources))) + for _, r := range resources { + r.Created = expectedResources[r.Id].Header.Created + Expect(r).To(Equal(expectedResources[r.Id].Header)) + } + } else { + Expect(err).ToNot(BeNil()) + Expect(err.Error()).To(Equal(errMsg)) } - } else { - require.Error(t, err) - require.Equal(t, tc.errMsg, err.Error()) - } - }) - } -} + }, + Entry("Valid: should return all resources", + true, + map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + &types.QueryGetAllResourceVersionsRequest{ + CollectionId: resourcetests.ExistingDIDIdentifier, + Name: resourcetests.ExistingResource().Header.Name, + }, + &types.QueryGetAllResourceVersionsResponse{ + Resources: []*types.ResourceHeader{ + resourcetests.ExistingResource().Header, + }, + }, + "", + ), + Entry("Invalid: should return an error if the collection id is invalid", + false, + map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + &types.QueryGetAllResourceVersionsRequest{ + CollectionId: resourcetests.NotFoundDIDIdentifier, + Name: resourcetests.ExistingResource().Header.Name, + }, + nil, + fmt.Errorf("did:cheqd:test:%s: DID Doc not found", resourcetests.NotFoundDIDIdentifier).Error(), + ), + ) + }) +}) diff --git a/x/resource/tests/query_collection_resources_test.go b/x/resource/tests/query_collection_resources_test.go index a8f643f0c..abd7d6bff 100644 --- a/x/resource/tests/query_collection_resources_test.go +++ b/x/resource/tests/query_collection_resources_test.go @@ -1,66 +1,71 @@ -package tests +package tests_test import ( + "crypto/ed25519" "fmt" - "testing" - "github.com/cheqd/cheqd-node/x/resource/types" + resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" + resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" -) - -func TestQueryGetCollectionResources(t *testing.T) { - keys := GenerateTestKeys() - existingResource := ExistingResource() - cases := []struct { - valid bool - name string - msg *types.QueryGetCollectionResourcesRequest - response *types.QueryGetCollectionResourcesResponse - errMsg string - }{ - { - valid: true, - name: "Valid: Works", - msg: &types.QueryGetCollectionResourcesRequest{ - CollectionId: ExistingDIDIdentifier, - }, - response: &types.QueryGetCollectionResourcesResponse{ - Resources: []*types.ResourceHeader{existingResource.Header}, - }, - errMsg: "", - }, - { - valid: false, - name: "Not Valid: DID Doc is not found", - msg: &types.QueryGetCollectionResourcesRequest{ - CollectionId: NotFoundDIDIdentifier, - }, - response: nil, - errMsg: fmt.Sprintf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier), - }, - } - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - msg := tc.msg - resourceSetup := InitEnv(t, keys[ExistingDIDKey].PublicKey, keys[ExistingDIDKey].PrivateKey) + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) - queryResponse, err := resourceSetup.QueryServer.CollectionResources(sdk.WrapSDKContext(resourceSetup.Ctx), msg) +var _ = Describe("QueryCollectionResources", func() { + Describe("Validate", func() { + var setup resourcetests.TestSetup + keys := resourcetests.GenerateTestKeys() + BeforeEach(func() { + setup = resourcetests.Setup() + didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) + _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) + payload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) + _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) + }) + DescribeTable("Validate QueryCollectionResources", + func( + valid bool, + msg *resourcetypes.QueryGetCollectionResourcesRequest, + response *resourcetypes.QueryGetCollectionResourcesResponse, + errMsg string, + ) { + queryResponse, err := setup.QueryServer.CollectionResources(sdk.WrapSDKContext(setup.Ctx), msg) - if tc.valid { - resources := queryResponse.Resources - expectedResources := tc.response.Resources - require.Nil(t, err) - require.Equal(t, len(expectedResources), len(resources)) - for i, r := range resources { - r.Created = expectedResources[i].Created - require.Equal(t, expectedResources[i], r) + if valid { + resources := queryResponse.Resources + expectedResources := response.Resources + Expect(err).To(BeNil()) + Expect(len(expectedResources)).To(Equal(len(resources))) + for i, r := range resources { + r.Created = expectedResources[i].Created + Expect(expectedResources[i]).To(Equal(r)) + } + } else { + Expect(err).To(HaveOccurred()) + Expect(errMsg).To(Equal(err.Error())) } - } else { - require.Error(t, err) - require.Equal(t, tc.errMsg, err.Error()) - } - }) - } -} + }, + Entry("Valid: Works", + true, + &resourcetypes.QueryGetCollectionResourcesRequest{ + CollectionId: resourcetests.ExistingDIDIdentifier, + }, + &resourcetypes.QueryGetCollectionResourcesResponse{ + Resources: []*resourcetypes.ResourceHeader{resourcetests.ExistingResource().Header}, + }, + "", + ), + Entry("Invalid: DID Doc is not found", + false, + &resourcetypes.QueryGetCollectionResourcesRequest{ + CollectionId: resourcetests.NotFoundDIDIdentifier, + }, + nil, + fmt.Errorf("did:cheqd:test:%s: DID Doc not found", resourcetests.NotFoundDIDIdentifier).Error(), + ), + ) + }) +}) diff --git a/x/resource/tests/query_resource_test.go b/x/resource/tests/query_resource_test.go index 1cfd044f4..0abe65791 100644 --- a/x/resource/tests/query_resource_test.go +++ b/x/resource/tests/query_resource_test.go @@ -1,84 +1,87 @@ -package tests +package tests_test import ( - - // "crypto/sha256" + "crypto/ed25519" "crypto/sha256" "fmt" - "testing" - "github.com/cheqd/cheqd-node/x/resource/types" + resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" + resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) -func TestQueryGetResource(t *testing.T) { - keys := GenerateTestKeys() - existingResource := ExistingResource() - cases := []struct { - valid bool - name string - msg *types.QueryGetResourceRequest - response *types.QueryGetResourceResponse - errMsg string - }{ - { - valid: true, - name: "Valid: Works", - msg: &types.QueryGetResourceRequest{ - CollectionId: ExistingDIDIdentifier, - Id: existingResource.Header.Id, - }, - response: &types.QueryGetResourceResponse{ - Resource: &existingResource, - }, - errMsg: "", - }, - { - valid: false, - name: "Not Valid: Resource is not found", - msg: &types.QueryGetResourceRequest{ - CollectionId: ExistingDIDIdentifier, - Id: ResourceId, - }, - response: nil, - errMsg: fmt.Sprintf("resource %s:%s: not found", ExistingDIDIdentifier, ResourceId), - }, - { - valid: false, - name: "Not Valid: DID Doc is not found", - msg: &types.QueryGetResourceRequest{ - CollectionId: NotFoundDIDIdentifier, - Id: existingResource.Header.Id, - }, - response: nil, - errMsg: fmt.Sprintf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier), - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - msg := tc.msg - resourceSetup := InitEnv(t, keys[ExistingDIDKey].PublicKey, keys[ExistingDIDKey].PrivateKey) - - queryResponse, err := resourceSetup.QueryServer.Resource(sdk.WrapSDKContext(resourceSetup.Ctx), msg) - - if tc.valid { - resource := queryResponse.Resource - require.Nil(t, err) - require.Equal(t, tc.response.Resource.Header.CollectionId, resource.Header.CollectionId) - require.Equal(t, tc.response.Resource.Header.Id, resource.Header.Id) - require.Equal(t, tc.response.Resource.Header.MediaType, resource.Header.MediaType) - require.Equal(t, tc.response.Resource.Header.ResourceType, resource.Header.ResourceType) - require.Equal(t, tc.response.Resource.Data, resource.Data) - require.Equal(t, tc.response.Resource.Header.Name, resource.Header.Name) - require.Equal(t, sha256.New().Sum(tc.response.Resource.Data), resource.Header.Checksum) - require.Equal(t, tc.response.Resource.Header.PreviousVersionId, resource.Header.PreviousVersionId) - require.Equal(t, tc.response.Resource.Header.NextVersionId, resource.Header.NextVersionId) - } else { - require.Error(t, err) - require.Equal(t, tc.errMsg, err.Error()) - } +var _ = Describe("QueryGetResource", func() { + Describe("Validate", func() { + var setup resourcetests.TestSetup + keys := resourcetests.GenerateTestKeys() + existingResource := resourcetests.ExistingResource() + BeforeEach(func() { + setup = resourcetests.Setup() + didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) + _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) + payload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) + _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + Expect(err).To(BeNil()) }) - } -} + DescribeTable("Validate QueryGetResourceRequest", + func( + valid bool, + msg *resourcetypes.QueryGetResourceRequest, + response *resourcetypes.QueryGetResourceResponse, + errMsg string, + ) { + queryResponse, err := setup.QueryServer.Resource(sdk.WrapSDKContext(setup.Ctx), msg) + + if valid { + resource := queryResponse.Resource + Expect(err).To(BeNil()) + Expect(response.Resource.Header.CollectionId).To(Equal(resource.Header.CollectionId)) + Expect(response.Resource.Header.Id).To(Equal(resource.Header.Id)) + Expect(response.Resource.Header.MediaType).To(Equal(resource.Header.MediaType)) + Expect(response.Resource.Header.ResourceType).To(Equal(resource.Header.ResourceType)) + Expect(response.Resource.Data).To(Equal(resource.Data)) + Expect(response.Resource.Header.Name).To(Equal(resource.Header.Name)) + checksum := sha256.Sum256(response.Resource.Data) + Expect(checksum[:]).To(Equal(resource.Header.Checksum)) + Expect(response.Resource.Header.PreviousVersionId).To(Equal(resource.Header.PreviousVersionId)) + Expect(response.Resource.Header.NextVersionId).To(Equal(resource.Header.NextVersionId)) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal(errMsg)) + } + }, + Entry("Valid: Works", + true, + &resourcetypes.QueryGetResourceRequest{ + CollectionId: resourcetests.ExistingDIDIdentifier, + Id: existingResource.Header.Id, + }, + &resourcetypes.QueryGetResourceResponse{ + Resource: &existingResource, + }, + "", + ), + Entry("Invalid: Resource not found", + false, + &resourcetypes.QueryGetResourceRequest{ + CollectionId: resourcetests.ExistingDIDIdentifier, + Id: resourcetests.AnotherResourceId, + }, + nil, + fmt.Errorf("resource %s:%s: not found", resourcetests.ExistingDIDIdentifier, resourcetests.AnotherResourceId).Error(), + ), + Entry("Invalid: DIDDoc not found", + false, + &resourcetypes.QueryGetResourceRequest{ + CollectionId: resourcetests.NotFoundDIDIdentifier, + Id: existingResource.Header.Id, + }, + nil, + fmt.Errorf("did:cheqd:test:%s: DID Doc not found", resourcetests.NotFoundDIDIdentifier).Error(), + ), + ) + }) +}) diff --git a/x/resource/tests/setup.go b/x/resource/tests/setup.go index 1709e37f2..e7259e0ef 100644 --- a/x/resource/tests/setup.go +++ b/x/resource/tests/setup.go @@ -4,7 +4,7 @@ import ( "crypto/ed25519" "crypto/rand" "encoding/base64" - "testing" + // "testing" "time" "github.com/cheqd/cheqd-node/x/cheqd" @@ -15,7 +15,7 @@ import ( "github.com/cheqd/cheqd-node/x/resource" "github.com/cheqd/cheqd-node/x/resource/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/stretchr/testify/require" + // "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" @@ -127,7 +127,7 @@ func (s *TestSetup) SendCreateResource(msg *types.MsgCreateResourcePayload, keys return &created, nil } -func InitEnv(t *testing.T, publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey) TestSetup { +/* func InitEnv(t *testing.T, publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey) TestSetup { resourceSetup := Setup() didDoc := resourceSetup.CreateDid(publicKey, ExistingDID) @@ -139,7 +139,7 @@ func InitEnv(t *testing.T, publicKey ed25519.PublicKey, privateKey ed25519.Priva require.NoError(t, err) return resourceSetup -} +} */ func GenerateTestKeys() map[string]cheqdtests.KeyPair { return map[string]cheqdtests.KeyPair{ diff --git a/x/resource/tests/tests_suite_test.go b/x/resource/tests/tests_suite_test.go new file mode 100644 index 000000000..3b0acded2 --- /dev/null +++ b/x/resource/tests/tests_suite_test.go @@ -0,0 +1,13 @@ +package tests_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestTests(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Tests Suite") +} diff --git a/x/resource/types/tx_msg_create_resource_payload_test.go b/x/resource/types/tx_msg_create_resource_payload_test.go index 26fb75ab6..53c82a40b 100644 --- a/x/resource/types/tx_msg_create_resource_payload_test.go +++ b/x/resource/types/tx_msg_create_resource_payload_test.go @@ -1,53 +1,38 @@ -package types +package types_test import ( - "testing" - - "github.com/stretchr/testify/require" + resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) -func TestMsgCreateResourcePayloadValidation(t *testing.T) { - cases := []struct { - name string - struct_ *MsgCreateResourcePayload - isValid bool - errorMsg string - }{ - { - name: "positive", - struct_: &MsgCreateResourcePayload{ - CollectionId: "123456789abcdefg", - Id: "ba62c728-cb15-498b-8e9e-9259cc242186", - Name: "Test Resource", - ResourceType: "CL-Schema", - Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - }, - isValid: true, - }, - { - name: "negative resource type", - struct_: &MsgCreateResourcePayload{ - CollectionId: "123456789abcdefg", - Id: "ba62c728-cb15-498b-8e9e-9259cc242186", - Name: "Test Resource", - ResourceType: "", - Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - }, - isValid: false, - errorMsg: "resource_type: cannot be blank.", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := tc.struct_.Validate() +var _ = Describe("TxMsgCreateResourcePayload", func() { + var msg *resourcetypes.MsgCreateResourcePayload + Describe("Validate", func() { + Context("Valid: MsgCreateResourcePayload", func() { + It("should return nil if the message is valid", func() { + msg = &resourcetypes.MsgCreateResourcePayload{ + CollectionId: "123456789abcdefg", + Id: "ba62c728-cb15-498b-8e9e-9259cc242186", + Name: "Test Resource", + ResourceType: "CL-Schema", + Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + } + Expect(msg.Validate()).To(BeNil()) + }) + }) - if tc.isValid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Equal(t, err.Error(), tc.errorMsg) - } + Context("Invalid: MsgCreateResourcePayload", func() { + It("should return error if the resource type is empty", func() { + msg = &resourcetypes.MsgCreateResourcePayload{ + CollectionId: "123456789abcdefg", + Id: "ba62c728-cb15-498b-8e9e-9259cc242186", + Name: "Test Resource", + ResourceType: "", + Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + } + Expect(msg.Validate().Error()).To(Equal("resource_type: cannot be blank.")) + }) }) - } -} + }) +}) diff --git a/x/resource/types/types_suite_test.go b/x/resource/types/types_suite_test.go new file mode 100644 index 000000000..b1cf86cdb --- /dev/null +++ b/x/resource/types/types_suite_test.go @@ -0,0 +1,13 @@ +package types_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestTypes(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Resource Types Suite") +} diff --git a/x/resource/utils/media_type_test.go b/x/resource/utils/media_type_test.go index becbc3578..41f3519e7 100644 --- a/x/resource/utils/media_type_test.go +++ b/x/resource/utils/media_type_test.go @@ -1,32 +1,30 @@ -package utils +package utils_test import ( "os" - "testing" - "github.com/stretchr/testify/require" -) - -func TestValidateMediaType(t *testing.T) { - cases := []struct { - path string - mt string - }{ - {"testdata/resource.txt", "text/plain; charset=utf-8"}, - {"testdata/resource.csv", "text/csv"}, - {"testdata/resource.dat", "application/octet-stream"}, - {"testdata/resource.json", "application/json"}, - {"testdata/resource.pdf", "application/pdf"}, - } + resourceutils "github.com/cheqd/cheqd-node/x/resource/utils" - for _, tc := range cases { - t.Run(tc.mt, func(t *testing.T) { - data, err := os.ReadFile(tc.path) - require.NoError(t, err) + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) - detected := DetectMediaType(data) +var _ = Describe("MediaType", func() { + Describe("GetMediaType", func() { + DescribeTable("Validate MIME type for different source files", + func(path string, mt string) { + data, err := os.ReadFile(path) + Expect(err).To(BeNil()) - require.Equal(t, tc.mt, detected) - }) - } -} + detected := resourceutils.DetectMediaType(data) + Expect(detected).To(Equal(mt)) + }, + Entry("text file", "testdata/resource.txt", "text/plain; charset=utf-8"), + Entry("csv file", "testdata/resource.csv", "text/csv"), + Entry("dat file", "testdata/resource.dat", "application/octet-stream"), + Entry("json file", "testdata/resource.json", "application/json"), + Entry("pdf file", "testdata/resource.pdf", "application/pdf"), + Entry("png file", "testdata/resource.png", "image/png"), + ) + }) +}) diff --git a/x/resource/utils/testdata/resource.png b/x/resource/utils/testdata/resource.png new file mode 100644 index 0000000000000000000000000000000000000000..eca57ae580fe933f9e54cea3156074f6c39fd5aa GIT binary patch literal 98198 zcmZsD1wb54vn?9jgM{Gj?w;UIa0n6z?(XhRf;$8a?(QBSI4r>l?!LIZA^E=l{_nmA z3p+E+Y*%+xojz67O}LVRBnl!vA_N2kinNrNG6V#)DFg(RAN(ue3Z6H_0q_Rts4V#& zqGF6-4>(CO)|57pmxrJOj^QC-Au%DKUv2@uAt3P~VE-ILK*&J8{m-#7Br60Ia2*5q z(GE3-fcfVhE8zX*km2RmzwhsiYz>V`q^%81jg^fJjNF00LFYjJPa8Q<|2_|Gngjjs zF_a&0AB3e{%^2{8U?-*J2m!%F{_+FqRv_#GbcoqpRntjRUXJgxtu>RuOCwBf)^;yX zK?u0<0f*McP6i}y)>bx-d~Skdf9~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m=_#ICa0tR3ae*DVnogTl3jX__Gfat|OzyEpPL8Zh46T9N;8vtJ7CD<=oT&^`Og{GW7A~);UOmQcm#m2&jG1|& z1Juzbd=||)L8k#Gio8*k)knkuI!PeoQTT!W?=B5a#_dgs_Uv7Jq)I4Hm1K!eAToMr z8^m?xrIMDxpf&x4>*|3dc26w4p2%_@?)gWQV4w2j_wVKKO{@)l-Y?nR-NJYI>5QQX z3sqdhcC6I?04;>Hae#~=8FhY;jcYR+os0un)*gVVv~ ztthD>TuAZdD^=E|m(o;igxerk`013XK<{5WJ64l9h`bjz`2u`zb+@ybP(RCmNkKGO z9ZT?kA7*eeo_4(7;KFuUrXl}>sPN+=Fm5B-GO>v&(pe; Date: Fri, 7 Oct 2022 22:16:27 +0300 Subject: [PATCH 18/76] Removed bloat --- x/resource/tests/setup.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/x/resource/tests/setup.go b/x/resource/tests/setup.go index e7259e0ef..b0944ff4f 100644 --- a/x/resource/tests/setup.go +++ b/x/resource/tests/setup.go @@ -4,7 +4,6 @@ import ( "crypto/ed25519" "crypto/rand" "encoding/base64" - // "testing" "time" "github.com/cheqd/cheqd-node/x/cheqd" @@ -15,7 +14,6 @@ import ( "github.com/cheqd/cheqd-node/x/resource" "github.com/cheqd/cheqd-node/x/resource/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - // "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" @@ -127,20 +125,6 @@ func (s *TestSetup) SendCreateResource(msg *types.MsgCreateResourcePayload, keys return &created, nil } -/* func InitEnv(t *testing.T, publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey) TestSetup { - resourceSetup := Setup() - - didDoc := resourceSetup.CreateDid(publicKey, ExistingDID) - _, err := resourceSetup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: privateKey}) - require.NoError(t, err) - - resourcePayload := GenerateCreateResourcePayload(ExistingResource()) - _, err = resourceSetup.SendCreateResource(resourcePayload, map[string]ed25519.PrivateKey{ExistingDIDKey: privateKey}) - require.NoError(t, err) - - return resourceSetup -} */ - func GenerateTestKeys() map[string]cheqdtests.KeyPair { return map[string]cheqdtests.KeyPair{ ExistingDIDKey: cheqdtests.GenerateKeyPair(), From 6de20fa2f9009fd33296915e007065e2f43ab6e7 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Mon, 10 Oct 2022 14:31:56 +0300 Subject: [PATCH 19/76] Add tests for type module --- x/cheqd/types/did_did_test.go | 347 ++++++------ x/cheqd/types/did_service_test.go | 41 +- x/cheqd/types/did_verification_method_test.go | 499 ++++++++++-------- x/cheqd/types/stateValue_test.go | 147 +++--- x/cheqd/types/tx_msg_create_did_test.go | 79 +-- x/cheqd/types/tx_msg_update_did_test.go | 96 ++-- x/cheqd/types/tx_sign_ingo_test.go | 189 ++++--- 7 files changed, 750 insertions(+), 648 deletions(-) diff --git a/x/cheqd/types/did_did_test.go b/x/cheqd/types/did_did_test.go index eda878553..aff9bf21f 100644 --- a/x/cheqd/types/did_did_test.go +++ b/x/cheqd/types/did_did_test.go @@ -34,197 +34,220 @@ var _ = Describe("DID Validation tests", func() { } }) - It("Valid: Id: allowed DID", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, + When("DID is allowed", func() { + It("is valid", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - }, - } - isValid = true - errorMsg = "" + } + isValid = true + errorMsg = "" + }) }) - It("Not valid: Id: not allowed DID", func() { - struct_ = &Did{ - Id: InvalidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, + When("DID is not allowed", func() { + It("should fail with error", func() { + struct_ = &Did{ + Id: InvalidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - }, - } - isValid = false - errorMsg = "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).)." + } + isValid = false + errorMsg = "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).)." + }) }) - It("Valid: Verification Method: all is fine with type Ed25519VerificationKey2020", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, + When("Verification method is Ed25519VerificationKey2020", func() { + It("is valid", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - }, - } - isValid = true - errorMsg = "" + } + isValid = true + errorMsg = "" + }) }) - It("Valid: Verification Method: all is fine with type jwk", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "JsonWebKey2020", - Controller: ValidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", + When("Verification method is jwk", func() { + It("is valid", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "JsonWebKey2020", + Controller: ValidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, }, - }, - } - isValid = true - errorMsg = "" + } + isValid = true + errorMsg = "" + }) }) - It("Not valid: Verification Method: Wrong id", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: InvalidTestDID, - Type: "JsonWebKey2020", - Controller: ValidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", + When("verification method has wrong id", func() { + It("should fail with corresponding error", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: InvalidTestDID, + Type: "JsonWebKey2020", + Controller: ValidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, }, - }, - } - isValid = false - errorMsg = "verification_method: (0: (id: unable to split did into method, namespace and id.).)." + } + isValid = false + errorMsg = "verification_method: (0: (id: unable to split did into method, namespace and id.).)." + }) }) - - It("Not valid: Verification Method: Wrong controller", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "JsonWebKey2020", - Controller: InvalidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", + When("verification method has wrong controller", func() { + It("should fail with corresponding error", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "JsonWebKey2020", + Controller: InvalidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, }, - }, - } - isValid = false - errorMsg = "verification_method: (0: (controller: unable to split did into method, namespace and id.).)." + } + isValid = false + errorMsg = "verification_method: (0: (controller: unable to split did into method, namespace and id.).)." + }) }) - It("Valid: Controller: List of DIDs allowed", func() { - struct_ = &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID, ValidTestDID2}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + When("list of DIDs in cotroller is allowed", func() { + It("s valid", func() { + struct_ = &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID, ValidTestDID2}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - }, - } - isValid = true - errorMsg = "" + } + isValid = true + errorMsg = "" + }) }) - It("Not valid: Controller: List of DIDs is not allowed", func() { - struct_ = &Did{ - Context: nil, - Id: ValidTestDID, - Controller: []string{ValidTestDID, InvalidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + When("list of DIDs in cotroller is not allowed", func() { + It("should fail with corresponding error", func() { + struct_ = &Did{ + Context: nil, + Id: ValidTestDID, + Controller: []string{ValidTestDID, InvalidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - }, - } - isValid = false - errorMsg = "controller: (1: unable to split did into method, namespace and id.)." + } + isValid = false + errorMsg = "controller: (1: unable to split did into method, namespace and id.)." + }) }) - It("Allowed namespaces: Negative", func() { - struct_ = &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + When("namespace in controleer is not in list of allowed", func() { + It("should fail", func() { + struct_ = &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - }, - } - allowedNamespaces = []string{"mainnet"} - isValid = false - errorMsg = "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).)." + } + allowedNamespaces = []string{"mainnet"} + isValid = false + errorMsg = "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).)." + }) }) - It("Controller duplicated: negative", func() { - struct_ = &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID, ValidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + When("controller is duplicated", func() { + + It("should fail", func() { + struct_ = &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID, ValidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - }, - } - isValid = false - errorMsg = "controller: there should be no duplicates." + } + isValid = false + errorMsg = "controller: there should be no duplicates." + }) }) - It("VM duplicated: negative", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + When("verification method is duplicated", func() { + + It("should fail", func() { + struct_ = &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, - }, - }, - } - isValid = false - errorMsg = "verification_method: there are verification method duplicates." + } + isValid = false + errorMsg = "verification_method: there are verification method duplicates." + }) }) }) diff --git a/x/cheqd/types/did_service_test.go b/x/cheqd/types/did_service_test.go index ce854a72d..d15928a36 100644 --- a/x/cheqd/types/did_service_test.go +++ b/x/cheqd/types/did_service_test.go @@ -46,25 +46,30 @@ var _ = Describe("DID Validation tests", func() { errorMsg = "" }) - It("Negative: namespace", func() { - struct_ = Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - } - allowedNamespaces = []string{"mainnet"} - isValid = false - errorMsg = "id: did namespace must be one of: mainnet." + When("Namespace is not allowed", func() { + + It("should fail", func() { + struct_ = Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + } + allowedNamespaces = []string{"mainnet"} + isValid = false + errorMsg = "id: did namespace must be one of: mainnet." + }) }) - It("Negative: Base did", func() { - struct_ = Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - } - baseDid = "did:cheqd:baaaaaaaaaaaaaab" - isValid = false - errorMsg = "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab." + When("base DID is not the same as in id", func() { + It("should fail", func() { + struct_ = Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + } + baseDid = "did:cheqd:baaaaaaaaaaaaaab" + isValid = false + errorMsg = "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab." + }) }) }) diff --git a/x/cheqd/types/did_verification_method_test.go b/x/cheqd/types/did_verification_method_test.go index f2242d3ef..067d886e2 100644 --- a/x/cheqd/types/did_verification_method_test.go +++ b/x/cheqd/types/did_verification_method_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "crypto" @@ -6,292 +6,323 @@ import ( "crypto/ed25519" "crypto/elliptic" "crypto/rand" + "crypto/rsa" "encoding/json" - "testing" + . "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/lestrrat-go/jwx/jwk" "github.com/multiformats/go-multibase" - "github.com/stretchr/testify/require" -) - -type TestJWKKey struct { - Kty string `json:"kty"` - N string `json:"n"` - Use string `json:"use"` - Alg string `json:"alg"` - E string `json:"e"` - Kid string `json:"kid"` -} - -var ValidJWKKey = TestJWKKey{ - Kty: "RSA", - N: "o76AudS2rsCvlz_3D47sFkpuz3NJxgLbXr1cHdmbo9xOMttPMJI97f0rHiSl9stltMi87KIOEEVQWUgMLaWQNaIZThgI1seWDAGRw59AO5sctgM1wPVZYt40fj2Qw4KT7m4RLMsZV1M5NYyXSd1lAAywM4FT25N0RLhkm3u8Hehw2Szj_2lm-rmcbDXzvjeXkodOUszFiOqzqBIS0Bv3c2zj2sytnozaG7aXa14OiUMSwJb4gmBC7I0BjPv5T85CH88VOcFDV51sO9zPJaBQnNBRUWNLh1vQUbkmspIANTzj2sN62cTSoxRhSdnjZQ9E_jraKYEW5oizE9Dtow4EvQ", - Use: "sig", - Alg: "RS256", - E: "AQAB", - Kid: "6a8ba5652a7044121d4fedac8f14d14c54e4895b", -} - -var NotValidJWKKey = TestJWKKey{ - Kty: "SomeOtherKeyType", - N: "o76AudS2rsCvlz_3D47sFkpuz3NJxgLbXr1cHdmbo9xOMttPMJI97f0rHiSl9stltMi87KIOEEVQWUgMLaWQNaIZThgI1seWDAGRw59AO5sctgM1wPVZYt40fj2Qw4KT7m4RLMsZV1M5NYyXSd1lAAywM4FT25N0RLhkm3u8Hehw2Szj_2lm-rmcbDXzvjeXkodOUszFiOqzqBIS0Bv3c2zj2sytnozaG7aXa14OiUMSwJb4gmBC7I0BjPv5T85CH88VOcFDV51sO9zPJaBQnNBRUWNLh1vQUbkmspIANTzj2sN62cTSoxRhSdnjZQ9E_jraKYEW5oizE9Dtow4EvQ", - Use: "sig", - Alg: "RS256", - E: "AQAB", - Kid: "6a8ba5652a7044121d4fedac8f14d14c54e4895b", -} - -var ( - ValidJWKByte, _ = json.Marshal(ValidJWKKey) - NotValidJWKByte, _ = json.Marshal(NotValidJWKKey) + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) -var ( - ValidPublicKeyJWK = JSONToPubKeyJWK(string(ValidJWKByte)) - NotValidPublicKeyJWK = JSONToPubKeyJWK(string(NotValidJWKByte)) -) - -func TestVerificationMethodValidation(t *testing.T) { - cases := []struct { - name string - struct_ VerificationMethod - baseDid string - allowedNamespaces []string - isValid bool - errorMsg string - }{ - { - name: "valid method with multibase key", - struct_: VerificationMethod{ +var _ = Describe("Verification Method Validation tests", func() { + + var struct_ VerificationMethod + var baseDid string + var allowedNamespaces []string + var isValid bool + var errorMsg string + + BeforeEach(func() { + struct_ = VerificationMethod{} + baseDid = "" + allowedNamespaces = []string{} + isValid = false + errorMsg = "" + }) + + AfterEach(func() { + err := struct_.Validate(baseDid, allowedNamespaces) + + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } + }) + When("verification method with expected multibase key", func() { + + It("is valid", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "Ed25519VerificationKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: nil, PublicKeyMultibase: ValidEd25519PubKey, - }, - isValid: true, - errorMsg: "", - }, - { - name: "valid method with jwk key", - struct_: VerificationMethod{ + } + isValid = true + errorMsg = "" + }) + }) + + When("verification method with expected jwk key", func() { + + It("is valid", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - }, - isValid: true, - errorMsg: "", - }, - { - name: "base did: positive", - struct_: VerificationMethod{ + } + isValid = true + errorMsg = "" + }) + }) + + When("id has expected DID as a base", func() { + + It("is valid", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - }, - baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", - isValid: true, - errorMsg: "", - }, - { - name: "base did: negative", - struct_: VerificationMethod{ + } + baseDid = "did:cheqd:aaaaaaaaaaaaaaaa" + isValid = true + errorMsg = "" + }) + }) + + When("id does not have expected DID as a base", func() { + + It("should fail", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - }, - baseDid: "did:cheqd:bbbbbbbbbbbbbbbb", - isValid: false, - errorMsg: "id: must have prefix: did:cheqd:bbbbbbbbbbbbbbbb.", - }, - { - name: "allowed namespaces: positive", - struct_: VerificationMethod{ + } + baseDid = "did:cheqd:bbbbbbbbbbbbbbbb" + isValid = false + errorMsg = "id: must have prefix: did:cheqd:bbbbbbbbbbbbbbbb." + }) + }) + + When("namespace is allowed", func() { + + It("is valid", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - }, - allowedNamespaces: []string{"mainnet", ""}, - isValid: true, - }, - { - name: "allowed namespaces: positive", - struct_: VerificationMethod{ + } + allowedNamespaces = []string{"mainnet", ""} + isValid = true + }) + }) + + When("namespace is not allowed", func() { + + It("should fail", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - }, - allowedNamespaces: []string{"testnet"}, - isValid: false, - errorMsg: "controller: did namespace must be one of: testnet; id: did namespace must be one of: testnet.", - }, - { - name: "JWK: valid key", - struct_: VerificationMethod{ + } + allowedNamespaces = []string{"testnet"} + isValid = false + errorMsg = "controller: did namespace must be one of: testnet; id: did namespace must be one of: testnet." + }) + }) + + When("JWK key has expected format", func() { + + It("is valid", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - }, - isValid: true, - }, - { - name: "JWK: not valid key", - struct_: VerificationMethod{ + } + isValid = true + }) + }) + + When("JWK key has unexpected format", func() { + It("is not valid", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: NotValidPublicKeyJWK, PublicKeyMultibase: "", - }, - isValid: false, - errorMsg: "public_key_jwk: can't parse jwk: failed to parse key: invalid key type from JSON (SomeOtherKeyType).", - }, - { - name: "all keys and values are required in jwk", - struct_: VerificationMethod{ + } + isValid = false + errorMsg = "public_key_jwk: can't parse jwk: failed to parse key: invalid key type from JSON (SomeOtherKeyType)." + }) + }) + + When("not all keys and valuesin JWK have expected format", func() { + + It("should fail", func() { + struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: append(ValidPublicKeyJWK, &KeyValuePair{Key: "", Value: ""}), PublicKeyMultibase: "", - }, - isValid: false, - errorMsg: "public_key_jwk: (6: (key: cannot be blank; value: cannot be blank.).).", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := tc.struct_.Validate(tc.baseDid, tc.allowedNamespaces) - - if tc.isValid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Equal(t, err.Error(), tc.errorMsg) } + isValid = false + errorMsg = "public_key_jwk: (6: (key: cannot be blank; value: cannot be blank.).)." }) - } -} + }) +}) -func TestEd25519SignatureVerification(t *testing.T) { - message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + - "tempor incididunt ut labore et dolore magna aliqua." - msgBytes := []byte(message) - - pubKey, privKey, err := ed25519.GenerateKey(rand.Reader) - require.NoError(t, err) - signature := ed25519.Sign(privKey, msgBytes) - - pubKeyStr, err := multibase.Encode(multibase.Base58BTC, pubKey) - require.NoError(t, err) - - vm := VerificationMethod{ - Id: "", - Type: "Ed25519VerificationKey2020", - Controller: "", - PublicKeyJwk: nil, - PublicKeyMultibase: pubKeyStr, - } - - err = VerifySignature(vm, msgBytes, signature) - require.NoError(t, err) - - jwk_, err := jwk.New(pubKey) - require.NoError(t, err) - json_, err := json.MarshalIndent(jwk_, "", " ") - require.NoError(t, err) - pubKeyJwk := JSONToPubKeyJWK(string(json_)) - - vm2 := VerificationMethod{ - Id: "", - Type: "JsonWebKey2020", - Controller: "", - PublicKeyJwk: pubKeyJwk, - PublicKeyMultibase: "", - } - - err = VerifySignature(vm2, msgBytes, signature) - require.NoError(t, err) -} - -func TestECDSASignatureVerification(t *testing.T) { - message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + - "tempor incididunt ut labore et dolore magna aliqua." - msgBytes := []byte(message) - - hasher := crypto.SHA256.New() - hasher.Write(msgBytes) - msgDigest := hasher.Sum(nil) - - privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - require.NoError(t, err) - pubKey := privKey.PublicKey - - signature, err := ecdsa.SignASN1(rand.Reader, privKey, msgDigest) - require.NoError(t, err) - - jwk_, err := jwk.New(pubKey) - require.NoError(t, err) - json_, err := json.MarshalIndent(jwk_, "", " ") - require.NoError(t, err) - pubKeyJwk := JSONToPubKeyJWK(string(json_)) - - vm2 := VerificationMethod{ - Id: "", - Type: "JsonWebKey2020", - Controller: "", - PublicKeyJwk: pubKeyJwk, - PublicKeyMultibase: "", - } - - err = VerifySignature(vm2, msgBytes, signature) - require.NoError(t, err) -} - -func TestRSASignatureVerification(t *testing.T) { - message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + +var _ = Describe("Validation ed25519 Signature in verification method", func() { + + var pubKey ed25519.PublicKey + var privKey ed25519.PrivateKey + var err error + var message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua." - msgBytes := []byte(message) - - hasher := crypto.SHA256.New() - hasher.Write(msgBytes) - msgDigest := hasher.Sum(nil) - - privKey, err := rsa.GenerateKey(rand.Reader, 2048) - require.NoError(t, err) - pubKey := privKey.PublicKey - - signature, err := rsa.SignPSS(rand.Reader, privKey, crypto.SHA256, msgDigest, nil) - require.NoError(t, err) - - jwk_, err := jwk.New(pubKey) - require.NoError(t, err) - json_, err := json.MarshalIndent(jwk_, "", " ") - require.NoError(t, err) - pubKeyJwk := JSONToPubKeyJWK(string(json_)) - - vm2 := VerificationMethod{ - Id: "", - Type: "JsonWebKey2020", - Controller: "", - PublicKeyJwk: pubKeyJwk, - PublicKeyMultibase: "", - } - - err = VerifySignature(vm2, msgBytes, signature) - require.NoError(t, err) -} + var msgBytes = []byte(message) + var signature []byte + + pubKey, privKey, err = ed25519.GenerateKey(rand.Reader) + Expect(err).To(BeNil()) + + signature = ed25519.Sign(privKey, msgBytes) + + Context("when ed25519 key is placed", func() { + It("is valid", func() { + + pubKeyStr, err := multibase.Encode(multibase.Base58BTC, pubKey) + Expect(err).To(BeNil()) + + vm := VerificationMethod{ + Id: "", + Type: "Ed25519VerificationKey2020", + Controller: "", + PublicKeyJwk: nil, + PublicKeyMultibase: pubKeyStr, + } + + err = VerifySignature(vm, msgBytes, signature) + Expect(err).To(BeNil()) + }) + }) + + Context("when with the same env but JWK is placed", func() { + It("is valid", func() { + jwk_, err := jwk.New(pubKey) + Expect(err).To(BeNil()) + + json_, err := json.MarshalIndent(jwk_, "", " ") + Expect(err).To(BeNil()) + + pubKeyJwk := JSONToPubKeyJWK(string(json_)) + + vm2 := VerificationMethod{ + Id: "", + Type: "JsonWebKey2020", + Controller: "", + PublicKeyJwk: pubKeyJwk, + PublicKeyMultibase: "", + } + + err = VerifySignature(vm2, msgBytes, signature) + Expect(err).To(BeNil()) + }) + }) + +}) + +var _ = Describe("Validation ECDSA Signature in verification method", func() { + + Context("ECDSA signature preparations and verification", func() { + It("is positive case", func() { + message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + + "tempor incididunt ut labore et dolore magna aliqua." + + msgBytes := []byte(message) + + hasher := crypto.SHA256.New() + hasher.Write(msgBytes) + msgDigest := hasher.Sum(nil) + + privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + Expect(err).To(BeNil()) + + pubKey := privKey.PublicKey + + signature, err := ecdsa.SignASN1(rand.Reader, privKey, msgDigest) + Expect(err).To(BeNil()) + + jwk_, err := jwk.New(pubKey) + Expect(err).To(BeNil()) + + json_, err := json.MarshalIndent(jwk_, "", " ") + Expect(err).To(BeNil()) + + pubKeyJwk := JSONToPubKeyJWK(string(json_)) + + vm := VerificationMethod{ + Id: "", + Type: "JsonWebKey2020", + Controller: "", + PublicKeyJwk: pubKeyJwk, + PublicKeyMultibase: "", + } + + err = VerifySignature(vm, msgBytes, signature) + Expect(err).To(BeNil()) + }) + }) + +}) + + +var _ = Describe("Validation RSA Signature in verification method", func() { + + Context("RSA signature preparations and verification", func() { + It("is positive case", func() { + message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + + "tempor incididunt ut labore et dolore magna aliqua." + msgBytes := []byte(message) + + hasher := crypto.SHA256.New() + hasher.Write(msgBytes) + msgDigest := hasher.Sum(nil) + + privKey, err := rsa.GenerateKey(rand.Reader, 2048) + Expect(err).To(BeNil()) + + pubKey := privKey.PublicKey + + signature, err := rsa.SignPSS(rand.Reader, privKey, crypto.SHA256, msgDigest, nil) + Expect(err).To(BeNil()) + + jwk_, err := jwk.New(pubKey) + Expect(err).To(BeNil()) + + json_, err := json.MarshalIndent(jwk_, "", " ") + Expect(err).To(BeNil()) + + pubKeyJwk := JSONToPubKeyJWK(string(json_)) + + vm2 := VerificationMethod{ + Id: "", + Type: "JsonWebKey2020", + Controller: "", + PublicKeyJwk: pubKeyJwk, + PublicKeyMultibase: "", + } + + err = VerifySignature(vm2, msgBytes, signature) + Expect(err).To(BeNil()) + }) + }) + +}) diff --git a/x/cheqd/types/stateValue_test.go b/x/cheqd/types/stateValue_test.go index 40d208b81..1f28f189c 100644 --- a/x/cheqd/types/stateValue_test.go +++ b/x/cheqd/types/stateValue_test.go @@ -1,81 +1,92 @@ -package types +package types_test import ( - "testing" "time" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + . "github.com/cheqd/cheqd-node/x/cheqd/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cheqd/cheqd-node/x/cheqd/utils" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) -func Test_PackUnpackAny(t *testing.T) { - original := &Did{ - Id: "test", - } - - // Construct codec - registry := types.NewInterfaceRegistry() - RegisterInterfaces(registry) - cdc := codec.NewProtoCodec(registry) - - // Marshal - bz, err := cdc.MarshalInterface(original) - require.NoError(t, err) - - // Assert type url - var any types.Any - err = any.Unmarshal(bz) - assert.NoError(t, err) - assert.Equal(t, any.TypeUrl, utils.MsgTypeURL(&Did{})) - - // Unmarshal - var decoded StateValueData - err = cdc.UnmarshalInterface(bz, &decoded) - require.NoError(t, err) - require.IsType(t, &Did{}, decoded) - require.Equal(t, original, decoded) -} - -func Test_NewMetadataFromContext(t *testing.T) { - createdTime := time.Now() - ctx := sdk.NewContext(nil, tmproto.Header{ChainID: "test_chain_id", Time: createdTime}, true, nil) - ctx.WithTxBytes([]byte("test_tx")) - expectedMetadata := Metadata{ - Created: createdTime.UTC().Format(time.RFC3339), - Updated: "", - Deactivated: false, - VersionId: utils.GetTxHash(ctx.TxBytes()), - } - - metadata := NewMetadataFromContext(ctx) - - require.Equal(t, expectedMetadata, metadata) -} - -func Test_UpdateMetadata(t *testing.T) { - createdTime := time.Now() - updatedTime := createdTime.Add(time.Hour) - - ctx1 := NewContext(createdTime, []byte("test1_tx")) - ctx2 := NewContext(updatedTime, []byte("test1_tx")) - - expectedMetadata := Metadata{ - Created: createdTime.UTC().Format(time.RFC3339), - Updated: updatedTime.UTC().Format(time.RFC3339), - Deactivated: false, - VersionId: utils.GetTxHash(ctx2.TxBytes()), - } - - metadata := NewMetadataFromContext(ctx1) - metadata.Update(ctx2) - - require.Equal(t, expectedMetadata, metadata) -} +var _ = Describe(`StaeValue tests`, func() { + + Context("Pack/unpack functionality", func() { + It("should pack and unpack withour any errors", func() { + + original := &Did{ + Id: "test", + } + + // Construct codec + registry := types.NewInterfaceRegistry() + RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + + // Marshal + bz, err := cdc.MarshalInterface(original) + Expect(err).To(BeNil()) + + // Assert type url + var any types.Any + err = any.Unmarshal(bz) + Expect(err).To(BeNil()) + Expect(any.TypeUrl).To(Equal(utils.MsgTypeURL(&Did{}))) + + // Unmarshal + var decoded StateValueData + err = cdc.UnmarshalInterface(bz, &decoded) + Expect(err).To(BeNil()) + Expect(&Did{}).To(BeAssignableToTypeOf(decoded)) + Expect(original).To(Equal(decoded)) + }) + }) + + When("New metadata is created from context", func() { + It("should be the same as original", func() { + createdTime := time.Now() + ctx := sdk.NewContext(nil, tmproto.Header{ChainID: "test_chain_id", Time: createdTime}, true, nil) + ctx.WithTxBytes([]byte("test_tx")) + expectedMetadata := Metadata{ + Created: createdTime.UTC().Format(time.RFC3339), + Updated: "", + Deactivated: false, + VersionId: utils.GetTxHash(ctx.TxBytes()), + } + + metadata := NewMetadataFromContext(ctx) + Expect(expectedMetadata).To(Equal(metadata)) + }) + }) + + When("Metadata is updated", func() { + It("should has ", func() { + createdTime := time.Now() + updatedTime := createdTime.Add(time.Hour) + + ctx1 := NewContext(createdTime, []byte("test1_tx")) + ctx2 := NewContext(updatedTime, []byte("test1_tx")) + + expectedMetadata := Metadata{ + Created: createdTime.UTC().Format(time.RFC3339), + Updated: updatedTime.UTC().Format(time.RFC3339), + Deactivated: false, + VersionId: utils.GetTxHash(ctx2.TxBytes()), + } + + metadata := NewMetadataFromContext(ctx1) + metadata.Update(ctx2) + + Expect(expectedMetadata).To(Equal(metadata)) + }) + }) + +}) func NewContext(time time.Time, txBytes []byte) sdk.Context { ctx := sdk.NewContext(nil, tmproto.Header{ChainID: "test_chain_id", Time: time}, true, nil) diff --git a/x/cheqd/types/tx_msg_create_did_test.go b/x/cheqd/types/tx_msg_create_did_test.go index 43385c95d..47d2cc225 100644 --- a/x/cheqd/types/tx_msg_create_did_test.go +++ b/x/cheqd/types/tx_msg_create_did_test.go @@ -1,21 +1,38 @@ -package types +package types_test import ( - "testing" +. "github.com/onsi/ginkgo/v2" +. "github.com/onsi/gomega" - "github.com/stretchr/testify/require" +. "github.com/cheqd/cheqd-node/x/cheqd/types" ) -func TestMsgCreateDidValidation(t *testing.T) { - cases := []struct { - name string - struct_ *MsgCreateDid - isValid bool - errorMsg string - }{ - { - name: "positive", - struct_: &MsgCreateDid{ +var _ = Describe("Message for DID creation", func() { + + var struct_ *MsgCreateDid + var isValid bool + var errorMsg string + + BeforeEach(func() { + struct_ = &MsgCreateDid{} + isValid = false + errorMsg = "" + }) + + AfterEach(func() { + err := struct_.ValidateBasic() + + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } + }) + + When("all fields are set properly", func() { + It("Will pass", func() { + struct_ = &MsgCreateDid{ Payload: &MsgCreateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -29,12 +46,14 @@ func TestMsgCreateDidValidation(t *testing.T) { Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, }, Signatures: nil, - }, - isValid: true, - }, - { - name: "negative: relationship duplicates", - struct_: &MsgCreateDid{ + } + isValid = true + }) + }) + + When("IDs are duplicated", func() { + It("should fail the validation", func() { + struct_ = &MsgCreateDid{ Payload: &MsgCreateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -48,22 +67,10 @@ func TestMsgCreateDidValidation(t *testing.T) { Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#key1"}, }, Signatures: nil, - }, - isValid: false, - errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := tc.struct_.ValidateBasic() - - if tc.isValid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Equal(t, err.Error(), tc.errorMsg) } + isValid = false + errorMsg = "payload: (authentication: there should be no duplicates.).: basic validation failed" }) - } -} + + }) +}) diff --git a/x/cheqd/types/tx_msg_update_did_test.go b/x/cheqd/types/tx_msg_update_did_test.go index 1b9c84e06..dff424c46 100644 --- a/x/cheqd/types/tx_msg_update_did_test.go +++ b/x/cheqd/types/tx_msg_update_did_test.go @@ -1,21 +1,38 @@ -package types +package types_test import ( - "testing" +. "github.com/onsi/ginkgo/v2" +. "github.com/onsi/gomega" - "github.com/stretchr/testify/require" +. "github.com/cheqd/cheqd-node/x/cheqd/types" ) -func TestMsgUpdateDidValidation(t *testing.T) { - cases := []struct { - name string - struct_ *MsgUpdateDid - isValid bool - errorMsg string - }{ - { - name: "positive", - struct_: &MsgUpdateDid{ +var _ = Describe("Message for DID creation", func() { + + var struct_ *MsgUpdateDid + var isValid bool + var errorMsg string + + BeforeEach(func() { + struct_ = &MsgUpdateDid{} + isValid = false + errorMsg = "" + }) + + AfterEach(func() { + err := struct_.ValidateBasic() + + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } + }) + + When("all fields are set properly", func() { + It("Will pass", func() { + struct_ = &MsgUpdateDid{ Payload: &MsgUpdateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -30,12 +47,14 @@ func TestMsgUpdateDidValidation(t *testing.T) { VersionId: "version1", }, Signatures: nil, - }, - isValid: true, - }, - { - name: "negative: relationship duplicates", - struct_: &MsgUpdateDid{ + } + isValid = true + }) + }) + + When("IDs are duplicated", func() { + It("should fail the validation", func() { + struct_ = &MsgUpdateDid{ Payload: &MsgUpdateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -50,13 +69,17 @@ func TestMsgUpdateDidValidation(t *testing.T) { VersionId: "version1", }, Signatures: nil, - }, - isValid: false, - errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", - }, - { - name: "negative: version id is required", - struct_: &MsgUpdateDid{ + } + isValid = false + errorMsg = "payload: (authentication: there should be no duplicates.).: basic validation failed" + + + }) + }) + + When("VersionId is empty", func() { + It("should fail on validation", func() { + struct_ = &MsgUpdateDid{ Payload: &MsgUpdateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -70,22 +93,9 @@ func TestMsgUpdateDidValidation(t *testing.T) { Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, }, Signatures: nil, - }, - isValid: false, - errorMsg: "payload: (version_id: cannot be blank.).: basic validation failed", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := tc.struct_.ValidateBasic() - - if tc.isValid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Equal(t, err.Error(), tc.errorMsg) } + isValid = false + errorMsg = "payload: (version_id: cannot be blank.).: basic validation failed" }) - } -} + }) +}) diff --git a/x/cheqd/types/tx_sign_ingo_test.go b/x/cheqd/types/tx_sign_ingo_test.go index 582f342a3..3d3489ff9 100644 --- a/x/cheqd/types/tx_sign_ingo_test.go +++ b/x/cheqd/types/tx_sign_ingo_test.go @@ -1,72 +1,88 @@ -package types +package types_test import ( - "testing" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" - "github.com/stretchr/testify/require" + . "github.com/cheqd/cheqd-node/x/cheqd/types" ) -func TestSignInfoValidation(t *testing.T) { - cases := []struct { - name string - struct_ SignInfo - allowedNamespaces []string - isValid bool - errorMsg string - }{ - { - name: "positive", - struct_: SignInfo{ - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", - }, - isValid: true, - errorMsg: "", - }, - { - name: "negative: namespace", - struct_: SignInfo{ +var _ = Describe("SignInfo validation tests", func() { + + var struct_ SignInfo + var allowedNamespaces []string + var isValid bool + var errorMsg string + + BeforeEach(func() { + struct_ = SignInfo{} + allowedNamespaces = []string{} + isValid = false + errorMsg = "" + }) + + AfterEach(func() { + err := struct_.Validate(allowedNamespaces) + + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } + }) + + It("Positive case", func() { + struct_ = SignInfo{ + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + } + isValid = true + errorMsg = "" + }) + + When("namespace is not allowed", func() { + It("should fail", func() { + struct_ = SignInfo{ VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", Signature: "DIDCommMessaging", - }, - allowedNamespaces: []string{"mainnet"}, - isValid: false, - errorMsg: "verification_method_id: did namespace must be one of: mainnet.", - }, - { - name: "negative: signature", - struct_: SignInfo{ + } + allowedNamespaces = []string{"mainnet"} + isValid = false + errorMsg = "verification_method_id: did namespace must be one of: mainnet." + }) + }) + + When("signature is not valid base64 string", func() { + It("should fail", func() { + struct_ = SignInfo{ VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", Signature: "!@#", - }, - isValid: false, - errorMsg: "signature: must be encoded in Base64.", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - err := tc.struct_.Validate(tc.allowedNamespaces) - - if tc.isValid { - require.NoError(t, err) - } else { - require.Error(t, err) - require.Equal(t, err.Error(), tc.errorMsg) } + isValid = false + errorMsg = "signature: must be encoded in Base64." }) - } -} - -func TestFullSignInfoDublicateValidation(t *testing.T) { - cases := []struct { - name string - structs_ []*SignInfo - isValid bool - }{ - { - name: "positive", - structs_: []*SignInfo{ + }) + +}) + +var _ = Describe("Full SignInfo duplicates tests", func() { + var structs_ []*SignInfo + var isValid bool + + BeforeEach(func() { + structs_ = []*SignInfo{} + isValid = false + }) + + AfterEach(func() { + res_ := IsUniqueSignInfoList(structs_) + Expect(res_).To(Equal(isValid)) + }) + + When("signatures are different", func() { + It("should pass", func() { + structs_ = []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -75,12 +91,14 @@ func TestFullSignInfoDublicateValidation(t *testing.T) { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "bbb=", }, - }, - isValid: true, - }, - { - name: "positive with all different pieces", - structs_: []*SignInfo{ + } + isValid = true + }) + }) + + When("all fields are different", func() { + It("should pass", func() { + structs_ = []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -89,12 +107,14 @@ func TestFullSignInfoDublicateValidation(t *testing.T) { VerificationMethodId: "did:cheqd:bbbbbbbbbbbbbbbb#method1", Signature: "bbb=", }, - }, - isValid: true, - }, - { - name: "negative", - structs_: []*SignInfo{ + } + isValid = true + }) + }) + + When("all fields are the same", func() { + It("should fail", func() { + structs_ = []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -103,12 +123,14 @@ func TestFullSignInfoDublicateValidation(t *testing.T) { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", }, - }, - isValid: false, - }, - { - name: "negative with a lot of same elems", - structs_: []*SignInfo{ + } + isValid = false + }) + }) + + When("all fields are the same and more elments", func() { + It("should fail", func() { + structs_ = []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -121,15 +143,8 @@ func TestFullSignInfoDublicateValidation(t *testing.T) { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", }, - }, - isValid: false, - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - res_ := IsUniqueSignInfoList(tc.structs_) - require.Equal(t, res_, tc.isValid) + } + isValid = false }) - } -} + }) +}) From 425bb4488a7d12135fe2661e0c1dbeeb23164cb0 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Mon, 10 Oct 2022 14:35:12 +0300 Subject: [PATCH 20/76] Makes linter happy --- app/export.go | 3 ++- x/cheqd/types/constant_test.go | 5 ++-- x/cheqd/types/did_did_test.go | 23 +++++++--------- x/cheqd/types/did_service_test.go | 22 +++++++-------- x/cheqd/types/did_verification_method_test.go | 26 +++--------------- x/cheqd/types/stateValue_test.go | 14 +++++----- x/cheqd/types/tx_msg_create_did_test.go | 26 +++++++++--------- x/cheqd/types/tx_msg_update_did_test.go | 27 +++++++++---------- x/cheqd/types/tx_sign_ingo_test.go | 24 ++++++++--------- x/cheqd/types/types_test.go | 3 ++- x/cheqd/utils/str_test.go | 12 ++++----- 11 files changed, 78 insertions(+), 107 deletions(-) diff --git a/app/export.go b/app/export.go index 79f6c2c6b..b6d449ead 100644 --- a/app/export.go +++ b/app/export.go @@ -49,7 +49,8 @@ func (app *App) ExportAppStateAndValidators( // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated -// in favour of export at a block height +// +// in favour of export at a block height func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false diff --git a/x/cheqd/types/constant_test.go b/x/cheqd/types/constant_test.go index 66aa6ec66..96e1fa695 100644 --- a/x/cheqd/types/constant_test.go +++ b/x/cheqd/types/constant_test.go @@ -1,8 +1,9 @@ package types_test + import ( "encoding/json" + . "github.com/cheqd/cheqd-node/x/cheqd/types" - ) var ( @@ -48,4 +49,4 @@ var ( var ( ValidPublicKeyJWK = JSONToPubKeyJWK(string(ValidJWKByte)) NotValidPublicKeyJWK = JSONToPubKeyJWK(string(NotValidJWKByte)) -) \ No newline at end of file +) diff --git a/x/cheqd/types/did_did_test.go b/x/cheqd/types/did_did_test.go index aff9bf21f..53140c03a 100644 --- a/x/cheqd/types/did_did_test.go +++ b/x/cheqd/types/did_did_test.go @@ -10,11 +10,10 @@ import ( ) var _ = Describe("DID Validation tests", func() { - - var struct_ *Did + var struct_ *Did var allowedNamespaces []string - var isValid bool - var errorMsg string + var isValid bool + var errorMsg string BeforeEach(func() { struct_ = &Did{} @@ -26,12 +25,12 @@ var _ = Describe("DID Validation tests", func() { AfterEach(func() { err := struct_.Validate(allowedNamespaces) - if isValid { - Expect(err).To(BeNil()) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) - } + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } }) When("DID is allowed", func() { @@ -48,7 +47,7 @@ var _ = Describe("DID Validation tests", func() { }, }, } - isValid = true + isValid = true errorMsg = "" }) }) @@ -207,7 +206,6 @@ var _ = Describe("DID Validation tests", func() { }) When("controller is duplicated", func() { - It("should fail", func() { struct_ = &Did{ Id: ValidTestDID, @@ -227,7 +225,6 @@ var _ = Describe("DID Validation tests", func() { }) When("verification method is duplicated", func() { - It("should fail", func() { struct_ = &Did{ Id: ValidTestDID, diff --git a/x/cheqd/types/did_service_test.go b/x/cheqd/types/did_service_test.go index d15928a36..b2b47c9c2 100644 --- a/x/cheqd/types/did_service_test.go +++ b/x/cheqd/types/did_service_test.go @@ -8,12 +8,11 @@ import ( ) var _ = Describe("DID Validation tests", func() { - - var struct_ Service - var baseDid string + var struct_ Service + var baseDid string var allowedNamespaces []string - var isValid bool - var errorMsg string + var isValid bool + var errorMsg string BeforeEach(func() { struct_ = Service{} @@ -26,12 +25,12 @@ var _ = Describe("DID Validation tests", func() { AfterEach(func() { err := struct_.Validate(baseDid, allowedNamespaces) - if isValid { - Expect(err).To(BeNil()) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) - } + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } }) It("Positive case", func() { @@ -47,7 +46,6 @@ var _ = Describe("DID Validation tests", func() { }) When("Namespace is not allowed", func() { - It("should fail", func() { struct_ = Service{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", diff --git a/x/cheqd/types/did_verification_method_test.go b/x/cheqd/types/did_verification_method_test.go index 067d886e2..c1e4e7f09 100644 --- a/x/cheqd/types/did_verification_method_test.go +++ b/x/cheqd/types/did_verification_method_test.go @@ -6,7 +6,6 @@ import ( "crypto/ed25519" "crypto/elliptic" "crypto/rand" - "crypto/rsa" "encoding/json" @@ -18,7 +17,6 @@ import ( ) var _ = Describe("Verification Method Validation tests", func() { - var struct_ VerificationMethod var baseDid string var allowedNamespaces []string @@ -44,7 +42,6 @@ var _ = Describe("Verification Method Validation tests", func() { } }) When("verification method with expected multibase key", func() { - It("is valid", func() { struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", @@ -59,7 +56,6 @@ var _ = Describe("Verification Method Validation tests", func() { }) When("verification method with expected jwk key", func() { - It("is valid", func() { struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", @@ -74,7 +70,6 @@ var _ = Describe("Verification Method Validation tests", func() { }) When("id has expected DID as a base", func() { - It("is valid", func() { struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", @@ -90,7 +85,6 @@ var _ = Describe("Verification Method Validation tests", func() { }) When("id does not have expected DID as a base", func() { - It("should fail", func() { struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", @@ -106,7 +100,6 @@ var _ = Describe("Verification Method Validation tests", func() { }) When("namespace is allowed", func() { - It("is valid", func() { struct_ = VerificationMethod{ Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", @@ -121,7 +114,6 @@ var _ = Describe("Verification Method Validation tests", func() { }) When("namespace is not allowed", func() { - It("should fail", func() { struct_ = VerificationMethod{ Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", @@ -137,7 +129,6 @@ var _ = Describe("Verification Method Validation tests", func() { }) When("JWK key has expected format", func() { - It("is valid", func() { struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", @@ -165,7 +156,6 @@ var _ = Describe("Verification Method Validation tests", func() { }) When("not all keys and valuesin JWK have expected format", func() { - It("should fail", func() { struct_ = VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", @@ -181,13 +171,12 @@ var _ = Describe("Verification Method Validation tests", func() { }) var _ = Describe("Validation ed25519 Signature in verification method", func() { - var pubKey ed25519.PublicKey var privKey ed25519.PrivateKey var err error - var message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + + message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua." - var msgBytes = []byte(message) + msgBytes := []byte(message) var signature []byte pubKey, privKey, err = ed25519.GenerateKey(rand.Reader) @@ -197,7 +186,6 @@ var _ = Describe("Validation ed25519 Signature in verification method", func() { Context("when ed25519 key is placed", func() { It("is valid", func() { - pubKeyStr, err := multibase.Encode(multibase.Base58BTC, pubKey) Expect(err).To(BeNil()) @@ -235,14 +223,12 @@ var _ = Describe("Validation ed25519 Signature in verification method", func() { err = VerifySignature(vm2, msgBytes, signature) Expect(err).To(BeNil()) }) - }) - + }) }) var _ = Describe("Validation ECDSA Signature in verification method", func() { - Context("ECDSA signature preparations and verification", func() { - It("is positive case", func() { + It("is positive case", func() { message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua." @@ -280,12 +266,9 @@ var _ = Describe("Validation ECDSA Signature in verification method", func() { Expect(err).To(BeNil()) }) }) - }) - var _ = Describe("Validation RSA Signature in verification method", func() { - Context("RSA signature preparations and verification", func() { It("is positive case", func() { message := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + @@ -324,5 +307,4 @@ var _ = Describe("Validation RSA Signature in verification method", func() { Expect(err).To(BeNil()) }) }) - }) diff --git a/x/cheqd/types/stateValue_test.go b/x/cheqd/types/stateValue_test.go index 1f28f189c..eb2bbf477 100644 --- a/x/cheqd/types/stateValue_test.go +++ b/x/cheqd/types/stateValue_test.go @@ -2,6 +2,7 @@ package types_test import ( "time" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -15,14 +16,12 @@ import ( ) var _ = Describe(`StaeValue tests`, func() { - Context("Pack/unpack functionality", func() { It("should pack and unpack withour any errors", func() { - original := &Did{ Id: "test", } - + // Construct codec registry := types.NewInterfaceRegistry() RegisterInterfaces(registry) @@ -68,24 +67,23 @@ var _ = Describe(`StaeValue tests`, func() { It("should has ", func() { createdTime := time.Now() updatedTime := createdTime.Add(time.Hour) - + ctx1 := NewContext(createdTime, []byte("test1_tx")) ctx2 := NewContext(updatedTime, []byte("test1_tx")) - + expectedMetadata := Metadata{ Created: createdTime.UTC().Format(time.RFC3339), Updated: updatedTime.UTC().Format(time.RFC3339), Deactivated: false, VersionId: utils.GetTxHash(ctx2.TxBytes()), } - + metadata := NewMetadataFromContext(ctx1) metadata.Update(ctx2) - + Expect(expectedMetadata).To(Equal(metadata)) }) }) - }) func NewContext(time time.Time, txBytes []byte) sdk.Context { diff --git a/x/cheqd/types/tx_msg_create_did_test.go b/x/cheqd/types/tx_msg_create_did_test.go index 47d2cc225..d0d00c3f3 100644 --- a/x/cheqd/types/tx_msg_create_did_test.go +++ b/x/cheqd/types/tx_msg_create_did_test.go @@ -1,17 +1,16 @@ package types_test import ( -. "github.com/onsi/ginkgo/v2" -. "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" -. "github.com/cheqd/cheqd-node/x/cheqd/types" + . "github.com/cheqd/cheqd-node/x/cheqd/types" ) var _ = Describe("Message for DID creation", func() { - - var struct_ *MsgCreateDid - var isValid bool - var errorMsg string + var struct_ *MsgCreateDid + var isValid bool + var errorMsg string BeforeEach(func() { struct_ = &MsgCreateDid{} @@ -22,12 +21,12 @@ var _ = Describe("Message for DID creation", func() { AfterEach(func() { err := struct_.ValidateBasic() - if isValid { - Expect(err).To(BeNil()) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) - } + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } }) When("all fields are set properly", func() { @@ -71,6 +70,5 @@ var _ = Describe("Message for DID creation", func() { isValid = false errorMsg = "payload: (authentication: there should be no duplicates.).: basic validation failed" }) - }) }) diff --git a/x/cheqd/types/tx_msg_update_did_test.go b/x/cheqd/types/tx_msg_update_did_test.go index dff424c46..c29f35982 100644 --- a/x/cheqd/types/tx_msg_update_did_test.go +++ b/x/cheqd/types/tx_msg_update_did_test.go @@ -1,17 +1,16 @@ package types_test import ( -. "github.com/onsi/ginkgo/v2" -. "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" -. "github.com/cheqd/cheqd-node/x/cheqd/types" + . "github.com/cheqd/cheqd-node/x/cheqd/types" ) var _ = Describe("Message for DID creation", func() { - - var struct_ *MsgUpdateDid - var isValid bool - var errorMsg string + var struct_ *MsgUpdateDid + var isValid bool + var errorMsg string BeforeEach(func() { struct_ = &MsgUpdateDid{} @@ -22,12 +21,12 @@ var _ = Describe("Message for DID creation", func() { AfterEach(func() { err := struct_.ValidateBasic() - if isValid { - Expect(err).To(BeNil()) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) - } + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } }) When("all fields are set properly", func() { @@ -72,8 +71,6 @@ var _ = Describe("Message for DID creation", func() { } isValid = false errorMsg = "payload: (authentication: there should be no duplicates.).: basic validation failed" - - }) }) diff --git a/x/cheqd/types/tx_sign_ingo_test.go b/x/cheqd/types/tx_sign_ingo_test.go index 3d3489ff9..597e9616c 100644 --- a/x/cheqd/types/tx_sign_ingo_test.go +++ b/x/cheqd/types/tx_sign_ingo_test.go @@ -8,11 +8,10 @@ import ( ) var _ = Describe("SignInfo validation tests", func() { - - var struct_ SignInfo + var struct_ SignInfo var allowedNamespaces []string - var isValid bool - var errorMsg string + var isValid bool + var errorMsg string BeforeEach(func() { struct_ = SignInfo{} @@ -24,12 +23,12 @@ var _ = Describe("SignInfo validation tests", func() { AfterEach(func() { err := struct_.Validate(allowedNamespaces) - if isValid { - Expect(err).To(BeNil()) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) - } + if isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(errorMsg)) + } }) It("Positive case", func() { @@ -63,12 +62,11 @@ var _ = Describe("SignInfo validation tests", func() { errorMsg = "signature: must be encoded in Base64." }) }) - }) var _ = Describe("Full SignInfo duplicates tests", func() { var structs_ []*SignInfo - var isValid bool + var isValid bool BeforeEach(func() { structs_ = []*SignInfo{} @@ -92,7 +90,7 @@ var _ = Describe("Full SignInfo duplicates tests", func() { Signature: "bbb=", }, } - isValid = true + isValid = true }) }) diff --git a/x/cheqd/types/types_test.go b/x/cheqd/types/types_test.go index 550174758..d3c237d8d 100644 --- a/x/cheqd/types/types_test.go +++ b/x/cheqd/types/types_test.go @@ -1,9 +1,10 @@ package types_test import ( + "testing" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "testing" ) func TestUtils(t *testing.T) { diff --git a/x/cheqd/utils/str_test.go b/x/cheqd/utils/str_test.go index 0e77e86ff..68fa811cd 100644 --- a/x/cheqd/utils/str_test.go +++ b/x/cheqd/utils/str_test.go @@ -39,7 +39,7 @@ var _ = Describe("Str utils functionality", func() { Entry("Desired element is absent. Expected: false", []string{"1", "2", "3"}, "123", false), ) - DescribeTable("Substract function", + DescribeTable("Subtract function", func(first []string, second []string, expected []string) { actual := Subtract(first, second) @@ -51,11 +51,11 @@ var _ = Describe("Str utils functionality", func() { Entry("nil as the first and the empty second. Expected empty list", nil, []string{}, []string{}), Entry("nil as the first and nil as the second. Expected empty list", nil, nil, []string{}), Entry("The same lists. Expected empty list", []string{"1", "2"}, []string{"1", "2"}, []string{}), - Entry("Substract with empty list. Exected: first array", []string{"1", "2", "3"}, []string{}, []string{"1", "2", "3"}), - Entry("Substract with nil as the second. Exected: first array", []string{"1", "2", "3"}, nil, []string{"1", "2", "3"}), - Entry("Substract with totally different list. Expected: first array", []string{"1", "2", "3"}, []string{"4", "5", "6"}, []string{"1", "2", "3"}), - Entry("Substract. General case. Expected: [1, 2]", []string{"1", "2", "3"}, []string{"1", "5", "2"}, []string{"3"}), - Entry("Substract. General case. Expected: [3, 4, 6]", []string{"4", "1", "6", "2", "3"}, []string{"1", "5", "2"}, []string{"3", "4", "6"}), + Entry("Subtract with empty list. Exected: first array", []string{"1", "2", "3"}, []string{}, []string{"1", "2", "3"}), + Entry("Subtract with nil as the second. Exected: first array", []string{"1", "2", "3"}, nil, []string{"1", "2", "3"}), + Entry("Subtract with totally different list. Expected: first array", []string{"1", "2", "3"}, []string{"4", "5", "6"}, []string{"1", "2", "3"}), + Entry("Subtract. General case. Expected: [1, 2]", []string{"1", "2", "3"}, []string{"1", "5", "2"}, []string{"3"}), + Entry("Subtract. General case. Expected: [3, 4, 6]", []string{"4", "1", "6", "2", "3"}, []string{"1", "5", "2"}, []string{"3", "4", "6"}), ) DescribeTable("Unique function", From 697479a076fad276d969aca9957b32e70a4e8b4f Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Mon, 10 Oct 2022 14:38:30 +0300 Subject: [PATCH 21/76] Enable ginkgo tests --- .github/workflows/test.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2d8150b17..a45d1d014 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,17 +46,7 @@ jobs: go install github.com/jstemmer/go-junit-report/v2@latest - name: Run Ginkgo tests - run: | - go test -v github.com/cheqd/cheqd-node/x/cheqd/utils 2>&1 | go-junit-report -parser gotest > report.xml -# - - uses: dorny/test-reporter@v1 - if: success() || failure() # run this step even if previous step failed - with: - name: JEST Tests # Name of the check run which will be created - path: report.xml # Path to test results (inside artifact .zip) - reporter: java-junit # Format of test results - max-annotations: '50' - fail-on-error: false + run: ginkgo -r --race --randomize-all --randomize-suites -v # test-new-node-setup: From 80f811bdf1f93739535f73da600aa0d42ea530d3 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Mon, 10 Oct 2022 14:49:42 +0300 Subject: [PATCH 22/76] Show test results in junit format --- .github/workflows/test.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a45d1d014..4730ff418 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,7 +46,16 @@ jobs: go install github.com/jstemmer/go-junit-report/v2@latest - name: Run Ginkgo tests - run: ginkgo -r --race --randomize-all --randomize-suites -v + run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml + + - uses: dorny/test-reporter@v1 + if: success() || failure() # run this step even if previous step failed + with: + name: JEST Tests # Name of the check run which will be created + path: report.xml # Path to test results (inside artifact .zip) + reporter: java-junit # Format of test results + max-annotations: '50' + fail-on-error: false # test-new-node-setup: From 0feb00dd2aefadb601d40cf33714217f506aaf31 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Mon, 10 Oct 2022 14:58:38 +0300 Subject: [PATCH 23/76] Show test results in a pretty view --- .github/workflows/test.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4730ff418..d52fcb219 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,14 +48,10 @@ jobs: - name: Run Ginkgo tests run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml - - uses: dorny/test-reporter@v1 + - uses: mikepenz/action-junit-report@v3 if: success() || failure() # run this step even if previous step failed with: - name: JEST Tests # Name of the check run which will be created - path: report.xml # Path to test results (inside artifact .zip) - reporter: java-junit # Format of test results - max-annotations: '50' - fail-on-error: false + report_paths: 'report.xml' # test-new-node-setup: From 4075f4e09c913531d9c92de79d1721ca14b08e71 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Mon, 10 Oct 2022 16:52:15 +0300 Subject: [PATCH 24/76] small fixes --- app/encoding_test.go | 20 -------------------- x/cheqd/tests/signature_verification_test.go | 20 +++++++++++--------- x/cheqd/types/tx_msg_create_did_test.go | 2 +- 3 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 app/encoding_test.go diff --git a/app/encoding_test.go b/app/encoding_test.go deleted file mode 100644 index acd26ab32..000000000 --- a/app/encoding_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package app - -import ( - "testing" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/stretchr/testify/require" -) - -func Test_MsgCreateDidPayload_UnmarshalJSON(t *testing.T) { - cdc := MakeTestEncodingConfig() - - createPayloadJson := `{"id": "did:cheqd:alice"}` - - var createPayload types.MsgCreateDidPayload - err := cdc.Codec.UnmarshalJSON([]byte(createPayloadJson), &createPayload) - require.NoError(t, err) - - require.Equal(t, "did:cheqd:alice", createPayload.Id, "json unmarshal doesn't work") -} diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go index 32b43dfcb..e3c8bd531 100644 --- a/x/cheqd/tests/signature_verification_test.go +++ b/x/cheqd/tests/signature_verification_test.go @@ -13,7 +13,7 @@ import ( "github.com/cheqd/cheqd-node/x/cheqd/types" ) -var _ = Describe("Signature Verification", func() { +var _ = Describe("Signature Verification while updating DID", func() { var setup TestSetup var aliceKeys, bobKeys map[string]ed25519.PrivateKey var aliceDid *types.MsgCreateDidPayload @@ -23,7 +23,7 @@ var _ = Describe("Signature Verification", func() { bobKeys, _, _ = setup.InitDid(BobDID) }) - It("should has changed DIDDoc controller", func() { + It("should have changed DIDDoc controller", func() { updatedDidDoc := setup.CreateToUpdateDid(aliceDid) updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) @@ -33,14 +33,16 @@ var _ = Describe("Signature Verification", func() { Expect([]string{BobDID}, receivedDid.Controller) }) - It("should fails cause we need old signature for changing verification method", func() { - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod[0].Type = Ed25519VerificationKey2020 - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + When("Old signature in verification method is absent", func() { + It("should fail", func() { + updatedDidDoc := setup.CreateToUpdateDid(aliceDid) + updatedDidDoc.VerificationMethod[0].Type = Ed25519VerificationKey2020 + _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - // check - Expect(err).To(Not(BeNil())) - Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) + // check + Expect(err).To(Not(BeNil())) + Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) + }) }) It("should fails cause we need old signature for changing verification method controller", func() { diff --git a/x/cheqd/types/tx_msg_create_did_test.go b/x/cheqd/types/tx_msg_create_did_test.go index d0d00c3f3..714504135 100644 --- a/x/cheqd/types/tx_msg_create_did_test.go +++ b/x/cheqd/types/tx_msg_create_did_test.go @@ -30,7 +30,7 @@ var _ = Describe("Message for DID creation", func() { }) When("all fields are set properly", func() { - It("Will pass", func() { + It("should pass", func() { struct_ = &MsgCreateDid{ Payload: &MsgCreateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", From c76a086121d4ba2554622d7bb858e0b7c02df483 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 11 Oct 2022 09:11:13 +0300 Subject: [PATCH 25/76] Enable lint and build stages --- .github/workflows/dispatch.yml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 853556039..d1f5b075c 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -7,25 +7,24 @@ concurrency: jobs: - # call-lint: - # name: "Lint" - # uses: ./.github/workflows/lint.yml + call-lint: + name: "Lint" + uses: ./.github/workflows/lint.yml -# call-build: -# name: "Build" -# # needs: call-lint -# uses: ./.github/workflows/build.yml -# secrets: inherit + call-build: + name: "Build" + needs: call-lint + uses: ./.github/workflows/build.yml + secrets: inherit - call-test: + call-test: name: "Test" -# needs: call-build + needs: call-build uses: ./.github/workflows/test.yml - call-release: + call-release: name: "Release" -# needs: [call-test, call-build] - needs: call-test + needs: [call-test, call-build] if: ${{ github.ref_protected == true }} uses: ./.github/workflows/release.yml secrets: inherit \ No newline at end of file From 338b6019dc168b64d21c76c6d8343ba7bfc5fa73 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Tue, 11 Oct 2022 14:18:26 +0500 Subject: [PATCH 26/76] Cleaning up --- x/cheqd/tests/create_did_test.go | 10 +-- x/cheqd/tests/setup.go | 32 +++----- x/cheqd/tests/{constants.go => test_data.go} | 0 x/cheqd/tests/tests_suite_test.go | 4 +- x/cheqd/tests/types.go | 13 +++ x/cheqd/tests/update_did_test.go | 33 ++++---- x/cheqd/tests/utils.go | 8 +- x/cheqd/types/types_test.go | 2 +- x/cheqd/utils/utils_suite_test.go | 2 +- x/resource/tests/create_resource_test.go | 81 +++++++++---------- .../tests/query_all_resource_versions_test.go | 43 +++++----- .../tests/query_collection_resources_test.go | 25 +++--- x/resource/tests/query_resource_test.go | 31 ++++--- x/resource/tests/tests_suite_test.go | 4 +- x/resource/types/types_suite_test.go | 2 +- x/resource/utils/utils_suite_test.go | 2 +- 16 files changed, 146 insertions(+), 146 deletions(-) rename x/cheqd/tests/{constants.go => test_data.go} (100%) create mode 100644 x/cheqd/tests/types.go diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index 3c60d01cb..dddc534ab 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -39,14 +39,14 @@ var _ = Describe("Create DID tests", func() { for _, vm := range msg.VerificationMethod { if vm.PublicKeyMultibase == "" { - vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].PublicKey) + vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) } Expect(err).To(BeNil()) } signerKeys := map[string]ed25519.PrivateKey{} for _, signer := range signers { - signerKeys[signer] = keys[signer].PrivateKey + signerKeys[signer] = keys[signer].Private } did, err := setup.SendCreateDid(msg, signerKeys) @@ -325,7 +325,7 @@ var _ = Describe("Create DID tests", func() { Id: ImposterKey1, Type: Ed25519VerificationKey2020, Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].PublicKey), + PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].Public), }, }, } @@ -346,7 +346,7 @@ var _ = Describe("Create DID tests", func() { Id: ImposterKey1, Type: Ed25519VerificationKey2020, Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].PublicKey), + PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].Public), }, }, } @@ -368,7 +368,7 @@ var _ = Describe("Create DID tests", func() { Id: ImposterKey1, Type: Ed25519VerificationKey2020, Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].PublicKey), + PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].Public), }, }, } diff --git a/x/cheqd/tests/setup.go b/x/cheqd/tests/setup.go index b5fdf30f3..975cbb106 100644 --- a/x/cheqd/tests/setup.go +++ b/x/cheqd/tests/setup.go @@ -24,11 +24,6 @@ import ( const Ed25519VerificationKey2020 = "Ed25519VerificationKey2020" -type KeyPair struct { - PrivateKey ed25519.PrivateKey - PublicKey ed25519.PublicKey -} - type TestSetup struct { Cdc codec.Codec Ctx sdk.Context @@ -36,11 +31,6 @@ type TestSetup struct { Handler sdk.Handler } -type SignerKey struct { - signer string - key ed25519.PrivateKey -} - func Setup() TestSetup { // Init Codec ir := codectypes.NewInterfaceRegistry() @@ -147,14 +137,14 @@ func (s *TestSetup) WrapCreateRequest(payload *types.MsgCreateDidPayload, keys m } } -func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys []SignerKey) *types.MsgUpdateDid { +func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys []SignInput) *types.MsgUpdateDid { var signatures []*types.SignInfo signingInput := payload.GetSignBytes() for _, skey := range keys { - signature := base64.StdEncoding.EncodeToString(ed25519.Sign(skey.key, signingInput)) + signature := base64.StdEncoding.EncodeToString(ed25519.Sign(skey.Key, signingInput)) signatures = append(signatures, &types.SignInfo{ - VerificationMethodId: skey.signer, + VerificationMethodId: skey.VerificationMethodId, Signature: signature, }) } @@ -192,7 +182,7 @@ func (s *TestSetup) InitDid(did string) (map[string]ed25519.PrivateKey, *types.M return keys, didMsg, nil } -func (s *TestSetup) SendUpdateDid(msg *types.MsgUpdateDidPayload, keys []SignerKey) (*types.Did, error) { +func (s *TestSetup) SendUpdateDid(msg *types.MsgUpdateDidPayload, keys []SignInput) (*types.Did, error) { // query Did state, _ := s.Keeper.GetDid(&s.Ctx, msg.Id) if len(msg.VersionId) == 0 { @@ -226,12 +216,12 @@ func ConcatKeys(dst map[string]ed25519.PrivateKey, src map[string]ed25519.Privat return dst } -func MapToListOfSignerKeys(mp map[string]ed25519.PrivateKey) []SignerKey { - rlist := []SignerKey{} +func MapToListOfSignerKeys(mp map[string]ed25519.PrivateKey) []SignInput { + rlist := []SignInput{} for k, v := range mp { - rlist = append(rlist, SignerKey{ - signer: k, - key: v, + rlist = append(rlist, SignInput{ + VerificationMethodId: k, + Key: v, }) } return rlist @@ -326,7 +316,7 @@ func (s TestSetup) CreateTestDIDs(keys map[string]KeyPair) error { msg := prefilled.msg for _, vm := range msg.VerificationMethod { - encoded, err := multibase.Encode(multibase.Base58BTC, keys[vm.Id].PublicKey) + encoded, err := multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) if err != nil { return err } @@ -335,7 +325,7 @@ func (s TestSetup) CreateTestDIDs(keys map[string]KeyPair) error { signerKeys := map[string]ed25519.PrivateKey{} for _, signer := range prefilled.signers { - signerKeys[signer] = keys[signer].PrivateKey + signerKeys[signer] = keys[signer].Private } _, err := s.SendCreateDid(msg, signerKeys) diff --git a/x/cheqd/tests/constants.go b/x/cheqd/tests/test_data.go similarity index 100% rename from x/cheqd/tests/constants.go rename to x/cheqd/tests/test_data.go diff --git a/x/cheqd/tests/tests_suite_test.go b/x/cheqd/tests/tests_suite_test.go index bd60da49f..eab13e53b 100644 --- a/x/cheqd/tests/tests_suite_test.go +++ b/x/cheqd/tests/tests_suite_test.go @@ -1,4 +1,4 @@ -package tests_test +package tests import ( "testing" @@ -9,5 +9,5 @@ import ( func TestTestsGeneral(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "General Tests Suite") + RunSpecs(t, "Cheqd Module") } diff --git a/x/cheqd/tests/types.go b/x/cheqd/tests/types.go new file mode 100644 index 000000000..ddafef7bd --- /dev/null +++ b/x/cheqd/tests/types.go @@ -0,0 +1,13 @@ +package tests + +import "crypto/ed25519" + +type KeyPair struct { + Private ed25519.PrivateKey + Public ed25519.PublicKey +} + +type SignInput struct { + VerificationMethodId string + Key ed25519.PrivateKey +} diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index 4917283a2..244fc1db5 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -15,7 +15,7 @@ var _ = Describe("Update DID tests", func() { // params for cases var valid bool var signers []string - var signerKeys []SignerKey + var signerKeys []SignInput var msg *types.MsgUpdateDidPayload errMsg := "" @@ -39,7 +39,7 @@ var _ = Describe("Update DID tests", func() { // setup valid = false signers = []string{} - signerKeys = []SignerKey{} + signerKeys = []SignInput{} msg = &types.MsgUpdateDidPayload{} errMsg = "" }) @@ -49,19 +49,19 @@ var _ = Describe("Update DID tests", func() { for _, vm := range msg.VerificationMethod { if vm.PublicKeyMultibase == "" { - vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, mainKeys[vm.Id].PublicKey) + vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, mainKeys[vm.Id].Public) } Expect(err).To(BeNil()) } - compiledKeys := []SignerKey{} + compiledKeys := []SignInput{} if len(signerKeys) > 0 { compiledKeys = signerKeys } else { for _, signer := range signers { - compiledKeys = append(compiledKeys, SignerKey{ - signer: signer, - key: mainKeys[signer].PrivateKey, + compiledKeys = append(compiledKeys, SignInput{ + VerificationMethodId: signer, + Key: mainKeys[signer].Private, }) } } @@ -89,24 +89,25 @@ var _ = Describe("Update DID tests", func() { It("Valid: Key rotation works", func() { valid = true - signerKeys = []SignerKey{ + signerKeys = []SignInput{ { - signer: AliceKey1, - key: mainKeys[AliceKey1].PrivateKey, + VerificationMethodId: AliceKey1, + Key: mainKeys[AliceKey1].Private, }, { - signer: AliceKey1, - key: mainKeys[AliceKey2].PrivateKey, + VerificationMethodId: AliceKey1, + Key: mainKeys[AliceKey2].Private, }, } msg = &types.MsgUpdateDidPayload{ Id: AliceDID, VerificationMethod: []*types.VerificationMethod{ { - Id: AliceKey1, - Type: Ed25519VerificationKey2020, - Controller: AliceDID, - PublicKeyMultibase: "z" + base58.Encode(mainKeys[AliceKey2].PublicKey), + Id: AliceKey1, + Type: Ed25519VerificationKey2020, + Controller: AliceDID, + // TODO: Use multibase encoding + PublicKeyMultibase: "z" + base58.Encode(mainKeys[AliceKey2].Public), }, }, } diff --git a/x/cheqd/tests/utils.go b/x/cheqd/tests/utils.go index f6a79c69c..6509bec72 100644 --- a/x/cheqd/tests/utils.go +++ b/x/cheqd/tests/utils.go @@ -6,18 +6,18 @@ import ( . "github.com/onsi/gomega" ) -var letters = []rune("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") +var base58Runes = []rune("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") -func randSeq(n int) string { +func randBase58Seq(n int) string { b := make([]rune, n) for i := range b { - b[i] = letters[rand.Intn(len(letters))] + b[i] = base58Runes[rand.Intn(len(base58Runes))] } return string(b) } func GenerateDID() string { - return "did:cheqd:test:" + randSeq(16) + return "did:cheqd:test:" + randBase58Seq(16) } func GenerateFragment(did string) string { diff --git a/x/cheqd/types/types_test.go b/x/cheqd/types/types_test.go index d3c237d8d..0421edfd7 100644 --- a/x/cheqd/types/types_test.go +++ b/x/cheqd/types/types_test.go @@ -9,5 +9,5 @@ import ( func TestUtils(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Types Tests Suite") + RunSpecs(t, "Cheqd Module Types") } diff --git a/x/cheqd/utils/utils_suite_test.go b/x/cheqd/utils/utils_suite_test.go index 9ca82ff0d..6bd2b0c8e 100644 --- a/x/cheqd/utils/utils_suite_test.go +++ b/x/cheqd/utils/utils_suite_test.go @@ -9,5 +9,5 @@ import ( func TestUtils(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Utils Suite") + RunSpecs(t, "Cheqd Module Utils") } diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index 6156e48bf..ca31f3694 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -1,4 +1,4 @@ -package tests_test +package tests import ( "crypto/ed25519" @@ -6,7 +6,6 @@ import ( "fmt" cheqdutils "github.com/cheqd/cheqd-node/x/cheqd/utils" - resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" . "github.com/onsi/ginkgo/v2" @@ -15,16 +14,16 @@ import ( var _ = Describe("CreateResource", func() { Describe("Validate", func() { - var setup resourcetests.TestSetup + var setup TestSetup var err error - keys := resourcetests.GenerateTestKeys() + keys := GenerateTestKeys() BeforeEach(func() { - setup = resourcetests.Setup() - didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) - _, err = setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + setup = Setup() + didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + _, err = setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) - resourcePayload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) - _, err = setup.SendCreateResource(resourcePayload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + resourcePayload := GenerateCreateResourcePayload(ExistingResource()) + _, err = setup.SendCreateResource(resourcePayload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) }) DescribeTable("Validate MsgCreateResource", @@ -60,73 +59,73 @@ var _ = Describe("CreateResource", func() { }, Entry("Valid: Works", true, - map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, &resourcetypes.MsgCreateResourcePayload{ - CollectionId: resourcetests.ExistingDIDIdentifier, - Id: resourcetests.ResourceId, + CollectionId: ExistingDIDIdentifier, + Id: ResourceId, Name: "Test Resource Name", - ResourceType: resourcetests.CLSchemaType, - Data: []byte(resourcetests.SchemaData), + ResourceType: CLSchemaType, + Data: []byte(SchemaData), }, - resourcetests.JsonResourceType, + JsonResourceType, "", "", ), Entry("Valid: Add new resource version", true, - map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, &resourcetypes.MsgCreateResourcePayload{ - CollectionId: resourcetests.ExistingResource().Header.CollectionId, - Id: resourcetests.ResourceId, - Name: resourcetests.ExistingResource().Header.Name, - ResourceType: resourcetests.ExistingResource().Header.ResourceType, - Data: resourcetests.ExistingResource().Data, + CollectionId: ExistingResource().Header.CollectionId, + Id: ResourceId, + Name: ExistingResource().Header.Name, + ResourceType: ExistingResource().Header.ResourceType, + Data: ExistingResource().Data, }, - resourcetests.ExistingResource().Header.MediaType, - resourcetests.ExistingResource().Header.Id, + ExistingResource().Header.MediaType, + ExistingResource().Header.Id, "", ), Entry("Invalid: No signature", false, map[string]ed25519.PrivateKey{}, &resourcetypes.MsgCreateResourcePayload{ - CollectionId: resourcetests.ExistingDIDIdentifier, - Id: resourcetests.ResourceId, + CollectionId: ExistingDIDIdentifier, + Id: ResourceId, Name: "Test Resource Name", - ResourceType: resourcetests.CLSchemaType, - Data: []byte(resourcetests.SchemaData), + ResourceType: CLSchemaType, + Data: []byte(SchemaData), }, - resourcetests.JsonResourceType, + JsonResourceType, "", - fmt.Errorf("signer: %s: signature is required but not found", resourcetests.ExistingDID).Error(), + fmt.Errorf("signer: %s: signature is required but not found", ExistingDID).Error(), ), Entry("Invalid: Resource Id is not an acceptable format", false, map[string]ed25519.PrivateKey{}, &resourcetypes.MsgCreateResourcePayload{ - CollectionId: resourcetests.ExistingDIDIdentifier, - Id: resourcetests.IncorrectResourceId, + CollectionId: ExistingDIDIdentifier, + Id: IncorrectResourceId, Name: "Test Resource Name", - ResourceType: resourcetests.CLSchemaType, - Data: []byte(resourcetests.SchemaData), + ResourceType: CLSchemaType, + Data: []byte(SchemaData), }, - resourcetests.JsonResourceType, + JsonResourceType, "", - fmt.Errorf("signer: %s: signature is required but not found", resourcetests.ExistingDID).Error(), + fmt.Errorf("signer: %s: signature is required but not found", ExistingDID).Error(), ), Entry("Invalid: DidDoc not found", false, map[string]ed25519.PrivateKey{}, &resourcetypes.MsgCreateResourcePayload{ - CollectionId: resourcetests.NotFoundDIDIdentifier, - Id: resourcetests.IncorrectResourceId, + CollectionId: NotFoundDIDIdentifier, + Id: IncorrectResourceId, Name: "Test Resource Name", - ResourceType: resourcetests.CLSchemaType, - Data: []byte(resourcetests.SchemaData), + ResourceType: CLSchemaType, + Data: []byte(SchemaData), }, - resourcetests.JsonResourceType, + JsonResourceType, "", - fmt.Errorf("did:cheqd:test:%s: not found", resourcetests.NotFoundDIDIdentifier).Error(), + fmt.Errorf("did:cheqd:test:%s: not found", NotFoundDIDIdentifier).Error(), ), ) }) diff --git a/x/resource/tests/query_all_resource_versions_test.go b/x/resource/tests/query_all_resource_versions_test.go index e70307963..23ffdb903 100644 --- a/x/resource/tests/query_all_resource_versions_test.go +++ b/x/resource/tests/query_all_resource_versions_test.go @@ -1,10 +1,9 @@ -package tests_test +package tests import ( "crypto/ed25519" "fmt" - resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" "github.com/cheqd/cheqd-node/x/resource/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,15 +13,15 @@ import ( var _ = Describe("QueryAllResourceVersions", func() { Describe("Validate", func() { - var setup resourcetests.TestSetup - keys := resourcetests.GenerateTestKeys() + var setup TestSetup + keys := GenerateTestKeys() BeforeEach(func() { - setup = resourcetests.Setup() - didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) - _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + setup = Setup() + didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) - payload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) - _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + payload := GenerateCreateResourcePayload(ExistingResource()) + _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) }) DescribeTable("Validate QueryGetAllResourceVersionsRequest", @@ -33,17 +32,17 @@ var _ = Describe("QueryAllResourceVersions", func() { response *types.QueryGetAllResourceVersionsResponse, errMsg string, ) { - existingResource := resourcetests.ExistingResource() + existingResource := ExistingResource() - payload := resourcetests.GenerateCreateResourcePayload(existingResource) - payload.Id = resourcetests.ResourceId + payload := GenerateCreateResourcePayload(existingResource) + payload.Id = ResourceId nextVersionResource, err := setup.SendCreateResource(payload, signerKeys) Expect(err).To(BeNil()) Expect(nextVersionResource).ToNot(Equal(existingResource)) - payload = resourcetests.GenerateCreateResourcePayload(existingResource) - payload.Id = resourcetests.AnotherResourceId + payload = GenerateCreateResourcePayload(existingResource) + payload.Id = AnotherResourceId payload.Name = "AnotherResourceVersion" differentResource, err := setup.SendCreateResource(payload, signerKeys) Expect(err).To(BeNil()) @@ -72,27 +71,27 @@ var _ = Describe("QueryAllResourceVersions", func() { }, Entry("Valid: should return all resources", true, - map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, &types.QueryGetAllResourceVersionsRequest{ - CollectionId: resourcetests.ExistingDIDIdentifier, - Name: resourcetests.ExistingResource().Header.Name, + CollectionId: ExistingDIDIdentifier, + Name: ExistingResource().Header.Name, }, &types.QueryGetAllResourceVersionsResponse{ Resources: []*types.ResourceHeader{ - resourcetests.ExistingResource().Header, + ExistingResource().Header, }, }, "", ), Entry("Invalid: should return an error if the collection id is invalid", false, - map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}, + map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, &types.QueryGetAllResourceVersionsRequest{ - CollectionId: resourcetests.NotFoundDIDIdentifier, - Name: resourcetests.ExistingResource().Header.Name, + CollectionId: NotFoundDIDIdentifier, + Name: ExistingResource().Header.Name, }, nil, - fmt.Errorf("did:cheqd:test:%s: DID Doc not found", resourcetests.NotFoundDIDIdentifier).Error(), + fmt.Errorf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier).Error(), ), ) }) diff --git a/x/resource/tests/query_collection_resources_test.go b/x/resource/tests/query_collection_resources_test.go index abd7d6bff..198810ec3 100644 --- a/x/resource/tests/query_collection_resources_test.go +++ b/x/resource/tests/query_collection_resources_test.go @@ -1,10 +1,9 @@ -package tests_test +package tests import ( "crypto/ed25519" "fmt" - resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,15 +13,15 @@ import ( var _ = Describe("QueryCollectionResources", func() { Describe("Validate", func() { - var setup resourcetests.TestSetup - keys := resourcetests.GenerateTestKeys() + var setup TestSetup + keys := GenerateTestKeys() BeforeEach(func() { - setup = resourcetests.Setup() - didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) - _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + setup = Setup() + didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) - payload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) - _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + payload := GenerateCreateResourcePayload(ExistingResource()) + _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) }) DescribeTable("Validate QueryCollectionResources", @@ -51,20 +50,20 @@ var _ = Describe("QueryCollectionResources", func() { Entry("Valid: Works", true, &resourcetypes.QueryGetCollectionResourcesRequest{ - CollectionId: resourcetests.ExistingDIDIdentifier, + CollectionId: ExistingDIDIdentifier, }, &resourcetypes.QueryGetCollectionResourcesResponse{ - Resources: []*resourcetypes.ResourceHeader{resourcetests.ExistingResource().Header}, + Resources: []*resourcetypes.ResourceHeader{ExistingResource().Header}, }, "", ), Entry("Invalid: DID Doc is not found", false, &resourcetypes.QueryGetCollectionResourcesRequest{ - CollectionId: resourcetests.NotFoundDIDIdentifier, + CollectionId: NotFoundDIDIdentifier, }, nil, - fmt.Errorf("did:cheqd:test:%s: DID Doc not found", resourcetests.NotFoundDIDIdentifier).Error(), + fmt.Errorf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier).Error(), ), ) }) diff --git a/x/resource/tests/query_resource_test.go b/x/resource/tests/query_resource_test.go index 0abe65791..6ee4b9d0e 100644 --- a/x/resource/tests/query_resource_test.go +++ b/x/resource/tests/query_resource_test.go @@ -1,11 +1,10 @@ -package tests_test +package tests import ( "crypto/ed25519" "crypto/sha256" "fmt" - resourcetests "github.com/cheqd/cheqd-node/x/resource/tests" resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" @@ -14,16 +13,16 @@ import ( var _ = Describe("QueryGetResource", func() { Describe("Validate", func() { - var setup resourcetests.TestSetup - keys := resourcetests.GenerateTestKeys() - existingResource := resourcetests.ExistingResource() + var setup TestSetup + keys := GenerateTestKeys() + existingResource := ExistingResource() BeforeEach(func() { - setup = resourcetests.Setup() - didDoc := setup.CreateDid(keys[resourcetests.ExistingDIDKey].PublicKey, resourcetests.ExistingDID) - _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + setup = Setup() + didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) - payload := resourcetests.GenerateCreateResourcePayload(resourcetests.ExistingResource()) - _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{resourcetests.ExistingDIDKey: keys[resourcetests.ExistingDIDKey].PrivateKey}) + payload := GenerateCreateResourcePayload(ExistingResource()) + _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) }) DescribeTable("Validate QueryGetResourceRequest", @@ -56,7 +55,7 @@ var _ = Describe("QueryGetResource", func() { Entry("Valid: Works", true, &resourcetypes.QueryGetResourceRequest{ - CollectionId: resourcetests.ExistingDIDIdentifier, + CollectionId: ExistingDIDIdentifier, Id: existingResource.Header.Id, }, &resourcetypes.QueryGetResourceResponse{ @@ -67,20 +66,20 @@ var _ = Describe("QueryGetResource", func() { Entry("Invalid: Resource not found", false, &resourcetypes.QueryGetResourceRequest{ - CollectionId: resourcetests.ExistingDIDIdentifier, - Id: resourcetests.AnotherResourceId, + CollectionId: ExistingDIDIdentifier, + Id: AnotherResourceId, }, nil, - fmt.Errorf("resource %s:%s: not found", resourcetests.ExistingDIDIdentifier, resourcetests.AnotherResourceId).Error(), + fmt.Errorf("resource %s:%s: not found", ExistingDIDIdentifier, AnotherResourceId).Error(), ), Entry("Invalid: DIDDoc not found", false, &resourcetypes.QueryGetResourceRequest{ - CollectionId: resourcetests.NotFoundDIDIdentifier, + CollectionId: NotFoundDIDIdentifier, Id: existingResource.Header.Id, }, nil, - fmt.Errorf("did:cheqd:test:%s: DID Doc not found", resourcetests.NotFoundDIDIdentifier).Error(), + fmt.Errorf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier).Error(), ), ) }) diff --git a/x/resource/tests/tests_suite_test.go b/x/resource/tests/tests_suite_test.go index 3b0acded2..c77802530 100644 --- a/x/resource/tests/tests_suite_test.go +++ b/x/resource/tests/tests_suite_test.go @@ -1,4 +1,4 @@ -package tests_test +package tests import ( "testing" @@ -9,5 +9,5 @@ import ( func TestTests(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Tests Suite") + RunSpecs(t, "Resource Module") } diff --git a/x/resource/types/types_suite_test.go b/x/resource/types/types_suite_test.go index b1cf86cdb..cb73a491c 100644 --- a/x/resource/types/types_suite_test.go +++ b/x/resource/types/types_suite_test.go @@ -9,5 +9,5 @@ import ( func TestTypes(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Resource Types Suite") + RunSpecs(t, "Resource Module Types") } diff --git a/x/resource/utils/utils_suite_test.go b/x/resource/utils/utils_suite_test.go index 5c7bf50ab..27ffc5d23 100644 --- a/x/resource/utils/utils_suite_test.go +++ b/x/resource/utils/utils_suite_test.go @@ -9,5 +9,5 @@ import ( func TestUtils(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Resource Utils Suite") + RunSpecs(t, "Resource Module Utils") } From faa0dd0405ec126f3e66a97b7f263e773f81dba5 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Tue, 11 Oct 2022 16:04:25 +0500 Subject: [PATCH 27/76] Switch wrom legacy routers to proto servers --- x/cheqd/keeper/msg_server.go | 6 +- x/cheqd/keeper/msg_server_create_did.go | 2 +- x/cheqd/keeper/msg_server_update_did.go | 2 +- x/cheqd/keeper/query_server.go | 6 +- x/cheqd/tests/config.go | 3 + x/cheqd/tests/const.go | 3 + x/cheqd/tests/create_did_test.go | 77 ++++++++++++++++++ x/cheqd/tests/setup.go | 78 +++++++++++-------- x/cheqd/tests/utils.go | 11 ++- x/resource/tests/create_resource_test.go | 4 +- .../tests/query_all_resource_versions_test.go | 3 +- .../tests/query_collection_resources_test.go | 3 +- x/resource/tests/query_resource_test.go | 3 +- x/resource/tests/setup.go | 50 +++++++----- 14 files changed, 180 insertions(+), 71 deletions(-) create mode 100644 x/cheqd/tests/config.go create mode 100644 x/cheqd/tests/const.go diff --git a/x/cheqd/keeper/msg_server.go b/x/cheqd/keeper/msg_server.go index ee41b5468..f7a9e5110 100644 --- a/x/cheqd/keeper/msg_server.go +++ b/x/cheqd/keeper/msg_server.go @@ -8,16 +8,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -type msgServer struct { +type MsgServer struct { Keeper } // NewMsgServer returns an implementation of the MsgServer interface for the provided Keeper. func NewMsgServer(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} + return &MsgServer{Keeper: keeper} } -var _ types.MsgServer = msgServer{} +var _ types.MsgServer = MsgServer{} func FindDid(k *Keeper, ctx *sdk.Context, inMemoryDIDs map[string]types.StateValue, did string) (res types.StateValue, found bool, err error) { // Look in inMemory dict diff --git a/x/cheqd/keeper/msg_server_create_did.go b/x/cheqd/keeper/msg_server_create_did.go index 2ba9df228..10809d56e 100644 --- a/x/cheqd/keeper/msg_server_create_did.go +++ b/x/cheqd/keeper/msg_server_create_did.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -func (k msgServer) CreateDid(goCtx context.Context, msg *types.MsgCreateDid) (*types.MsgCreateDidResponse, error) { +func (k MsgServer) CreateDid(goCtx context.Context, msg *types.MsgCreateDid) (*types.MsgCreateDidResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) // Validate DID doesn't exist diff --git a/x/cheqd/keeper/msg_server_update_did.go b/x/cheqd/keeper/msg_server_update_did.go index d19e6a66f..8e7fcaea7 100644 --- a/x/cheqd/keeper/msg_server_update_did.go +++ b/x/cheqd/keeper/msg_server_update_did.go @@ -10,7 +10,7 @@ import ( const UpdatedPostfix string = "-updated" -func (k msgServer) UpdateDid(goCtx context.Context, msg *types.MsgUpdateDid) (*types.MsgUpdateDidResponse, error) { +func (k MsgServer) UpdateDid(goCtx context.Context, msg *types.MsgUpdateDid) (*types.MsgUpdateDidResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) // Validate DID does exist diff --git a/x/cheqd/keeper/query_server.go b/x/cheqd/keeper/query_server.go index 966633539..e3a62bffc 100644 --- a/x/cheqd/keeper/query_server.go +++ b/x/cheqd/keeper/query_server.go @@ -4,13 +4,13 @@ import ( "github.com/cheqd/cheqd-node/x/cheqd/types" ) -type queryServer struct { +type QueryServer struct { Keeper } // NewQueryServer returns an implementation of the MsgServer interface for the provided Keeper. func NewQueryServer(keeper Keeper) types.QueryServer { - return &queryServer{Keeper: keeper} + return &QueryServer{Keeper: keeper} } -var _ types.QueryServer = queryServer{} +var _ types.QueryServer = QueryServer{} diff --git a/x/cheqd/tests/config.go b/x/cheqd/tests/config.go new file mode 100644 index 000000000..9d067e0c2 --- /dev/null +++ b/x/cheqd/tests/config.go @@ -0,0 +1,3 @@ +package tests + +const DID_NAMESPACE = "test" diff --git a/x/cheqd/tests/const.go b/x/cheqd/tests/const.go new file mode 100644 index 000000000..cd5394f9c --- /dev/null +++ b/x/cheqd/tests/const.go @@ -0,0 +1,3 @@ +package tests + +const Ed25519VerificationKey2020 = "Ed25519VerificationKey2020" diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index dddc534ab..0cb4a7bad 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -13,6 +13,83 @@ import ( "github.com/multiformats/go-multibase" ) +var _ = Describe("Create DID tests new", func() { + // params for cases + var valid bool + var keys map[string]KeyPair + var signers []string + var msg *types.MsgCreateDidPayload + errMsg := "" + + var setup TestSetup + var err error + mainKeys := GenerateTestKeys() + + BeforeEach(func() { + // setup + valid = false + keys = map[string]KeyPair{} + signers = []string{} + msg = &types.MsgCreateDidPayload{} + errMsg = "" + }) + + AfterEach(func() { + setup = InitEnv(mainKeys) + + for _, vm := range msg.VerificationMethod { + if vm.PublicKeyMultibase == "" { + vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) + } + Expect(err).To(BeNil()) + } + + signerKeys := map[string]ed25519.PrivateKey{} + for _, signer := range signers { + signerKeys[signer] = keys[signer].Private + } + + did, err := setup.SendCreateDid(msg, signerKeys) + + if valid { + Expect(err).To(BeNil()) + Expect(msg.Id).To(Equal(did.Id)) + Expect(msg.Controller).To(Equal(did.Controller)) + Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) + Expect(msg.Authentication).To(Equal(did.Authentication)) + Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) + Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) + Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) + Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) + Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) + Expect(msg.Service).To(Equal(did.Service)) + Expect(msg.Context).To(Equal(did.Context)) + } else { + Expect(err).To(HaveOccurred()) + Expect(errMsg).To(Equal(err.Error())) + } + }) + + It("Valid: Works", func() { + valid = true + keys = map[string]KeyPair{ + ImposterKey1: GenerateKeyPair(), + } + signers = []string{ImposterKey1} + msg = &types.MsgCreateDidPayload{ + Id: ImposterDID, + Authentication: []string{ImposterKey1}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: ImposterKey1, + Type: Ed25519VerificationKey2020, + Controller: ImposterDID, + }, + }, + } + }) +}) + var _ = Describe("Create DID tests", func() { // params for cases var valid bool diff --git a/x/cheqd/tests/setup.go b/x/cheqd/tests/setup.go index 975cbb106..2bde90df9 100644 --- a/x/cheqd/tests/setup.go +++ b/x/cheqd/tests/setup.go @@ -1,13 +1,12 @@ package tests import ( + "context" "crypto/ed25519" "crypto/rand" "encoding/base64" "time" - "github.com/btcsuite/btcutil/base58" - "github.com/cheqd/cheqd-node/x/cheqd" "github.com/cheqd/cheqd-node/x/cheqd/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/multiformats/go-multibase" @@ -22,13 +21,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -const Ed25519VerificationKey2020 = "Ed25519VerificationKey2020" - type TestSetup struct { - Cdc codec.Codec - Ctx sdk.Context - Keeper keeper.Keeper - Handler sdk.Handler + Cdc codec.Codec + + SdkCtx sdk.Context + StdCtx context.Context + + Keeper keeper.Keeper + MsgServer types.MsgServer + QueryServer types.QueryServer } func Setup() TestSetup { @@ -59,21 +60,29 @@ func Setup() TestSetup { tmproto.Header{ChainID: "test", Time: blockTime}, false, log.NewNopLogger()).WithTxBytes(txBytes) - handler := cheqd.NewHandler(*newKeeper) + msgServer := keeper.NewMsgServer(*newKeeper) + queryServer := keeper.NewQueryServer(*newKeeper) setup := TestSetup{ - Cdc: cdc, - Ctx: ctx, - Keeper: *newKeeper, - Handler: handler, + Cdc: cdc, + + SdkCtx: ctx, + StdCtx: sdk.WrapSDKContext(ctx), + + Keeper: *newKeeper, + MsgServer: msgServer, + QueryServer: queryServer, } - setup.Keeper.SetDidNamespace(&ctx, "test") + setup.Keeper.SetDidNamespace(&ctx, DID_NAMESPACE) return setup } func (s *TestSetup) CreateDid(pubKey ed25519.PublicKey, did string) *types.MsgCreateDidPayload { - PublicKeyMultibase := "z" + base58.Encode(pubKey) + PublicKeyMultibase, err := multibase.Encode(multibase.Base58BTC, pubKey) + if err != nil { + panic(err) + } VerificationMethod := types.VerificationMethod{ Id: did + "#key-1", @@ -155,11 +164,6 @@ func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys [ } } -func GenerateKeyPair() KeyPair { - PublicKey, PrivateKey, _ := ed25519.GenerateKey(rand.Reader) - return KeyPair{PrivateKey, PublicKey} -} - func (s *TestSetup) InitDid(did string) (map[string]ed25519.PrivateKey, *types.MsgCreateDidPayload, error) { pubKey, privKey, _ := ed25519.GenerateKey(rand.Reader) @@ -169,43 +173,49 @@ func (s *TestSetup) InitDid(did string) (map[string]ed25519.PrivateKey, *types.M keyId := did + "#key-1" keys := map[string]ed25519.PrivateKey{keyId: privKey} - result, err := s.Handler(s.Ctx, s.WrapCreateRequest(didMsg, keys)) + _, err := s.MsgServer.CreateDid(s.StdCtx, s.WrapCreateRequest(didMsg, keys)) if err != nil { return nil, nil, err } - didResponse := types.MsgCreateDidResponse{} - if err := didResponse.Unmarshal(result.Data); err != nil { - return nil, nil, err - } - return keys, didMsg, nil } func (s *TestSetup) SendUpdateDid(msg *types.MsgUpdateDidPayload, keys []SignInput) (*types.Did, error) { - // query Did - state, _ := s.Keeper.GetDid(&s.Ctx, msg.Id) + req := types.QueryGetDidRequest{ + Id: msg.Id, + } + + state, _ := s.QueryServer.Did(s.StdCtx, &req) if len(msg.VersionId) == 0 { msg.VersionId = state.Metadata.VersionId } - _, err := s.Handler(s.Ctx, s.WrapUpdateRequest(msg, keys)) + _, err := s.MsgServer.UpdateDid(s.StdCtx, s.WrapUpdateRequest(msg, keys)) if err != nil { return nil, err } - updated, _ := s.Keeper.GetDid(&s.Ctx, msg.Id) - return updated.UnpackDataAsDid() + req = types.QueryGetDidRequest{ + Id: msg.Id, + } + + updated, _ := s.QueryServer.Did(s.StdCtx, &req) + return updated.Did, nil } func (s *TestSetup) SendCreateDid(msg *types.MsgCreateDidPayload, keys map[string]ed25519.PrivateKey) (*types.Did, error) { - _, err := s.Handler(s.Ctx, s.WrapCreateRequest(msg, keys)) + _, err := s.MsgServer.CreateDid(s.StdCtx, s.WrapCreateRequest(msg, keys)) if err != nil { return nil, err } - created, _ := s.Keeper.GetDid(&s.Ctx, msg.Id) - return created.UnpackDataAsDid() + req := types.QueryGetDidRequest{ + Id: msg.Id, + } + + created, _ := s.QueryServer.Did(s.StdCtx, &req) + return created.Did, nil } func ConcatKeys(dst map[string]ed25519.PrivateKey, src map[string]ed25519.PrivateKey) map[string]ed25519.PrivateKey { diff --git a/x/cheqd/tests/utils.go b/x/cheqd/tests/utils.go index 6509bec72..ff1d6e28c 100644 --- a/x/cheqd/tests/utils.go +++ b/x/cheqd/tests/utils.go @@ -1,7 +1,9 @@ package tests import ( - "math/rand" + "crypto/ed25519" + "crypto/rand" + mathrand "math/rand" . "github.com/onsi/gomega" ) @@ -11,7 +13,7 @@ var base58Runes = []rune("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuv func randBase58Seq(n int) string { b := make([]rune, n) for i := range b { - b[i] = base58Runes[rand.Intn(len(base58Runes))] + b[i] = base58Runes[mathrand.Intn(len(base58Runes))] } return string(b) } @@ -45,3 +47,8 @@ func InitEnv(keys map[string]KeyPair) TestSetup { Expect(err).To(BeNil()) return setup } + +func GenerateKeyPair() KeyPair { + PublicKey, PrivateKey, _ := ed25519.GenerateKey(rand.Reader) + return KeyPair{PrivateKey, PublicKey} +} diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index ca31f3694..285ae1d50 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "fmt" + cheqdtypes "github.com/cheqd/cheqd-node/x/cheqd/types" cheqdutils "github.com/cheqd/cheqd-node/x/cheqd/utils" resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" @@ -40,7 +41,8 @@ var _ = Describe("CreateResource", func() { Expect(err).To(BeNil()) did := cheqdutils.JoinDID("cheqd", "test", resource.Header.CollectionId) - didStateValue, err := setup.Keeper.GetDid(&setup.Ctx, did) + req := cheqdtypes.QueryGetDidRequest{Id: did} + didStateValue, err := setup.QueryServer.Did(setup.StdCtx, &req) Expect(err).To(BeNil()) Expect(didStateValue.Metadata.Resources).Should(ContainElement(resource.Header.Id)) diff --git a/x/resource/tests/query_all_resource_versions_test.go b/x/resource/tests/query_all_resource_versions_test.go index 23ffdb903..a92be3701 100644 --- a/x/resource/tests/query_all_resource_versions_test.go +++ b/x/resource/tests/query_all_resource_versions_test.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/cheqd/cheqd-node/x/resource/types" - sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -49,7 +48,7 @@ var _ = Describe("QueryAllResourceVersions", func() { Expect(differentResource).ToNot(Equal(existingResource)) Expect(differentResource).ToNot(Equal(nextVersionResource)) - queryResponse, err := setup.QueryServer.AllResourceVersions(sdk.WrapSDKContext(setup.Ctx), msg) + queryResponse, err := setup.ResourceQueryServer.AllResourceVersions(setup.StdCtx, msg) if valid { resources := queryResponse.Resources diff --git a/x/resource/tests/query_collection_resources_test.go b/x/resource/tests/query_collection_resources_test.go index 198810ec3..10431db91 100644 --- a/x/resource/tests/query_collection_resources_test.go +++ b/x/resource/tests/query_collection_resources_test.go @@ -5,7 +5,6 @@ import ( "fmt" resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" - sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -31,7 +30,7 @@ var _ = Describe("QueryCollectionResources", func() { response *resourcetypes.QueryGetCollectionResourcesResponse, errMsg string, ) { - queryResponse, err := setup.QueryServer.CollectionResources(sdk.WrapSDKContext(setup.Ctx), msg) + queryResponse, err := setup.ResourceQueryServer.CollectionResources(setup.StdCtx, msg) if valid { resources := queryResponse.Resources diff --git a/x/resource/tests/query_resource_test.go b/x/resource/tests/query_resource_test.go index 6ee4b9d0e..ba8a8be47 100644 --- a/x/resource/tests/query_resource_test.go +++ b/x/resource/tests/query_resource_test.go @@ -6,7 +6,6 @@ import ( "fmt" resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" - sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -32,7 +31,7 @@ var _ = Describe("QueryGetResource", func() { response *resourcetypes.QueryGetResourceResponse, errMsg string, ) { - queryResponse, err := setup.QueryServer.Resource(sdk.WrapSDKContext(setup.Ctx), msg) + queryResponse, err := setup.ResourceQueryServer.Resource(setup.StdCtx, msg) if valid { resource := queryResponse.Resource diff --git a/x/resource/tests/setup.go b/x/resource/tests/setup.go index b0944ff4f..ca6e6ba77 100644 --- a/x/resource/tests/setup.go +++ b/x/resource/tests/setup.go @@ -6,12 +6,9 @@ import ( "encoding/base64" "time" - "github.com/cheqd/cheqd-node/x/cheqd" cheqdkeeper "github.com/cheqd/cheqd-node/x/cheqd/keeper" - cheqdtests "github.com/cheqd/cheqd-node/x/cheqd/tests" cheqdtypes "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/cheqd/cheqd-node/x/resource" "github.com/cheqd/cheqd-node/x/resource/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -28,9 +25,9 @@ import ( type TestSetup struct { cheqdtests.TestSetup - ResourceKeeper keeper.Keeper - ResourceHandler sdk.Handler - QueryServer types.QueryServer + ResourceKeeper keeper.Keeper + ResourceMsgServer types.MsgServer + ResourceQueryServer types.QueryServer } func Setup() TestSetup { @@ -56,7 +53,6 @@ func Setup() TestSetup { // Init Keepers cheqdKeeper := cheqdkeeper.NewKeeper(cdc, cheqdStoreKey) resourceKeeper := keeper.NewKeeper(cdc, resourceStoreKey) - queryServer := keeper.NewQueryServer(*resourceKeeper, *cheqdKeeper) // Create Tx txBytes := make([]byte, 28) @@ -68,22 +64,31 @@ func Setup() TestSetup { tmproto.Header{ChainID: "test", Time: blockTime}, false, log.NewNopLogger()).WithTxBytes(txBytes) - cheqdHandler := cheqd.NewHandler(*cheqdKeeper) - resourceHandler := resource.NewHandler(*resourceKeeper, *cheqdKeeper) + // Init servers + cheqdMsgServer := cheqdkeeper.NewMsgServer(*cheqdKeeper) + cheqdQueryServer := cheqdkeeper.NewQueryServer(*cheqdKeeper) + + msgServer := keeper.NewMsgServer(*resourceKeeper, *cheqdKeeper) + queryServer := keeper.NewQueryServer(*resourceKeeper, *cheqdKeeper) setup := TestSetup{ TestSetup: cheqdtests.TestSetup{ - Cdc: cdc, - Ctx: ctx, - Keeper: *cheqdKeeper, - Handler: cheqdHandler, + Cdc: cdc, + + SdkCtx: ctx, + StdCtx: sdk.WrapSDKContext(ctx), + + Keeper: *cheqdKeeper, + MsgServer: cheqdMsgServer, + QueryServer: cheqdQueryServer, }, - ResourceKeeper: *resourceKeeper, - ResourceHandler: resourceHandler, - QueryServer: queryServer, + + ResourceKeeper: *resourceKeeper, + ResourceMsgServer: msgServer, + ResourceQueryServer: queryServer, } - setup.Keeper.SetDidNamespace(&ctx, "test") + setup.Keeper.SetDidNamespace(&ctx, cheqdtests.DID_NAMESPACE) return setup } @@ -116,13 +121,18 @@ func (s *TestSetup) WrapCreateRequest(payload *types.MsgCreateResourcePayload, k } func (s *TestSetup) SendCreateResource(msg *types.MsgCreateResourcePayload, keys map[string]ed25519.PrivateKey) (*types.Resource, error) { - _, err := s.ResourceHandler(s.Ctx, s.WrapCreateRequest(msg, keys)) + _, err := s.ResourceMsgServer.CreateResource(s.StdCtx, s.WrapCreateRequest(msg, keys)) if err != nil { return nil, err } - created, _ := s.ResourceKeeper.GetResource(&s.Ctx, msg.CollectionId, msg.Id) - return &created, nil + req := &types.QueryGetResourceRequest{ + CollectionId: msg.CollectionId, + Id: msg.Id, + } + + created, _ := s.ResourceQueryServer.Resource(s.StdCtx, req) + return created.Resource, nil } func GenerateTestKeys() map[string]cheqdtests.KeyPair { From f084839b69bb77ce030e298cb4e68da9504abbaf Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Tue, 11 Oct 2022 16:13:20 +0500 Subject: [PATCH 28/76] Cleaning up --- x/cheqd/tests/create_did_test.go | 135 ++++++++---------- x/cheqd/tests/setup.go | 43 +++--- x/cheqd/tests/signature_verification_test.go | 4 +- x/cheqd/tests/utils.go | 7 + x/resource/tests/create_resource_test.go | 2 +- .../tests/query_all_resource_versions_test.go | 2 +- .../tests/query_collection_resources_test.go | 2 +- x/resource/tests/query_resource_test.go | 2 +- 8 files changed, 91 insertions(+), 106 deletions(-) diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index 0cb4a7bad..4840f0814 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -13,82 +13,65 @@ import ( "github.com/multiformats/go-multibase" ) -var _ = Describe("Create DID tests new", func() { - // params for cases - var valid bool - var keys map[string]KeyPair - var signers []string - var msg *types.MsgCreateDidPayload - errMsg := "" - - var setup TestSetup - var err error - mainKeys := GenerateTestKeys() - - BeforeEach(func() { - // setup - valid = false - keys = map[string]KeyPair{} - signers = []string{} - msg = &types.MsgCreateDidPayload{} - errMsg = "" - }) - - AfterEach(func() { - setup = InitEnv(mainKeys) - - for _, vm := range msg.VerificationMethod { - if vm.PublicKeyMultibase == "" { - vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) - } - Expect(err).To(BeNil()) - } - - signerKeys := map[string]ed25519.PrivateKey{} - for _, signer := range signers { - signerKeys[signer] = keys[signer].Private - } - - did, err := setup.SendCreateDid(msg, signerKeys) - - if valid { - Expect(err).To(BeNil()) - Expect(msg.Id).To(Equal(did.Id)) - Expect(msg.Controller).To(Equal(did.Controller)) - Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) - Expect(msg.Authentication).To(Equal(did.Authentication)) - Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) - Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) - Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) - Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) - Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) - Expect(msg.Service).To(Equal(did.Service)) - Expect(msg.Context).To(Equal(did.Context)) - } else { - Expect(err).To(HaveOccurred()) - Expect(errMsg).To(Equal(err.Error())) - } - }) - - It("Valid: Works", func() { - valid = true - keys = map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - } - signers = []string{ImposterKey1} - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Authentication: []string{ImposterKey1}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: Ed25519VerificationKey2020, - Controller: ImposterDID, - }, - }, - } - }) -}) +// var _ = Describe("Create DID tests new", func() { +// var setup TestSetup + +// BeforeEach(func() { +// setup = Setup() +// }) + +// It("Valid: Works", func() { +// valid = true +// keys = map[string]KeyPair{ +// ImposterKey1: GenerateKeyPair(), +// } +// signers = []string{ImposterKey1} +// msg = &types.MsgCreateDidPayload{ +// Id: ImposterDID, +// Authentication: []string{ImposterKey1}, +// VerificationMethod: []*types.VerificationMethod{ +// { +// Id: ImposterKey1, +// Type: Ed25519VerificationKey2020, +// Controller: ImposterDID, +// }, +// }, +// } + +// for _, vm := range msg.VerificationMethod { +// if vm.PublicKeyMultibase == "" { +// vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) +// } +// Expect(err).To(BeNil()) +// } + +// signerKeys := map[string]ed25519.PrivateKey{} +// for _, signer := range signers { +// signerKeys[signer] = keys[signer].Private +// } + +// did, err := setup.SendCreateDid(msg, signerKeys) + +// if valid { +// Expect(err).To(BeNil()) +// Expect(msg.Id).To(Equal(did.Id)) +// Expect(msg.Controller).To(Equal(did.Controller)) +// Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) +// Expect(msg.Authentication).To(Equal(did.Authentication)) +// Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) +// Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) +// Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) +// Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) +// Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) +// Expect(msg.Service).To(Equal(did.Service)) +// Expect(msg.Context).To(Equal(did.Context)) +// } else { +// Expect(err).To(HaveOccurred()) +// Expect(errMsg).To(Equal(err.Error())) +// } + +// }) +// }) var _ = Describe("Create DID tests", func() { // params for cases diff --git a/x/cheqd/tests/setup.go b/x/cheqd/tests/setup.go index 2bde90df9..8aa457efd 100644 --- a/x/cheqd/tests/setup.go +++ b/x/cheqd/tests/setup.go @@ -78,29 +78,18 @@ func Setup() TestSetup { return setup } -func (s *TestSetup) CreateDid(pubKey ed25519.PublicKey, did string) *types.MsgCreateDidPayload { - PublicKeyMultibase, err := multibase.Encode(multibase.Base58BTC, pubKey) - if err != nil { - panic(err) - } - - VerificationMethod := types.VerificationMethod{ - Id: did + "#key-1", - Type: Ed25519VerificationKey2020, - Controller: did, - PublicKeyMultibase: PublicKeyMultibase, - } - - Service := types.Service{ - Id: did + "#service-2", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - } - +func (s *TestSetup) BuildMsgCreateDidPayload(did string, key ed25519.PublicKey) *types.MsgCreateDidPayload { return &types.MsgCreateDidPayload{ - Id: did, - Controller: nil, - VerificationMethod: []*types.VerificationMethod{&VerificationMethod}, + Id: did, + Controller: nil, + VerificationMethod: []*types.VerificationMethod{ + { + Id: did + "#key-1", + Type: Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(key), + }, + }, Authentication: []string{did + "#key-1"}, AssertionMethod: []string{did + "#key-1"}, CapabilityInvocation: []string{did + "#key-1"}, @@ -108,7 +97,13 @@ func (s *TestSetup) CreateDid(pubKey ed25519.PublicKey, did string) *types.MsgCr KeyAgreement: []string{did + "#key-1"}, AlsoKnownAs: []string{did + "#key-1"}, Context: []string{"Context"}, - Service: []*types.Service{&Service}, + Service: []*types.Service{ + { + Id: did + "#service-2", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + }, + }, } } @@ -168,7 +163,7 @@ func (s *TestSetup) InitDid(did string) (map[string]ed25519.PrivateKey, *types.M pubKey, privKey, _ := ed25519.GenerateKey(rand.Reader) // add new Did - didMsg := s.CreateDid(pubKey, did) + didMsg := s.BuildMsgCreateDidPayload(did, pubKey) keyId := did + "#key-1" keys := map[string]ed25519.PrivateKey{keyId: privKey} diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go index e3c8bd531..09ffb2148 100644 --- a/x/cheqd/tests/signature_verification_test.go +++ b/x/cheqd/tests/signature_verification_test.go @@ -80,8 +80,8 @@ var _ = Describe("Signature Verification. Remove signature/VM", func() { BpubKey, BprivKey, _ = ed25519.GenerateKey(rand.Reader) // Create dids - aliceDid = setup.CreateDid(ApubKey, AliceDID) - bobDid = setup.CreateDid(BpubKey, BobDID) + aliceDid = setup.BuildMsgCreateDidPayload(AliceDID, ApubKey) + bobDid = setup.BuildMsgCreateDidPayload(BobDID, BpubKey) // Collect private keys aliceKeys = map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} diff --git a/x/cheqd/tests/utils.go b/x/cheqd/tests/utils.go index ff1d6e28c..01206dbdb 100644 --- a/x/cheqd/tests/utils.go +++ b/x/cheqd/tests/utils.go @@ -5,6 +5,7 @@ import ( "crypto/rand" mathrand "math/rand" + "github.com/multiformats/go-multibase" . "github.com/onsi/gomega" ) @@ -52,3 +53,9 @@ func GenerateKeyPair() KeyPair { PublicKey, PrivateKey, _ := ed25519.GenerateKey(rand.Reader) return KeyPair{PrivateKey, PublicKey} } + +func MustEncodeBase58(data []byte) string { + encoded, err := multibase.Encode(multibase.Base58BTC, data) + Expect(err).To(BeNil()) + return encoded +} diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index 285ae1d50..e329f6374 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -20,7 +20,7 @@ var _ = Describe("CreateResource", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) _, err = setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) resourcePayload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_all_resource_versions_test.go b/x/resource/tests/query_all_resource_versions_test.go index a92be3701..4b69777cf 100644 --- a/x/resource/tests/query_all_resource_versions_test.go +++ b/x/resource/tests/query_all_resource_versions_test.go @@ -16,7 +16,7 @@ var _ = Describe("QueryAllResourceVersions", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_collection_resources_test.go b/x/resource/tests/query_collection_resources_test.go index 10431db91..c8e04e0e3 100644 --- a/x/resource/tests/query_collection_resources_test.go +++ b/x/resource/tests/query_collection_resources_test.go @@ -16,7 +16,7 @@ var _ = Describe("QueryCollectionResources", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_resource_test.go b/x/resource/tests/query_resource_test.go index ba8a8be47..f9a8e17e4 100644 --- a/x/resource/tests/query_resource_test.go +++ b/x/resource/tests/query_resource_test.go @@ -17,7 +17,7 @@ var _ = Describe("QueryGetResource", func() { existingResource := ExistingResource() BeforeEach(func() { setup = Setup() - didDoc := setup.CreateDid(keys[ExistingDIDKey].Public, ExistingDID) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) From ad96be90bd3d1129d73e8166df26d4287b0fd528 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Tue, 11 Oct 2022 18:05:41 +0500 Subject: [PATCH 29/76] Improving tests structure --- x/cheqd/tests/const.go | 2 +- x/cheqd/tests/create_did_test.go | 170 ++++++++++-------- x/cheqd/tests/setup.go | 107 ++++++++--- x/cheqd/tests/signature_verification_test.go | 11 +- x/cheqd/tests/update_did_test.go | 54 +++--- x/cheqd/tests/utils.go | 26 ++- x/resource/tests/create_resource_test.go | 2 +- .../tests/query_all_resource_versions_test.go | 2 +- .../tests/query_collection_resources_test.go | 2 +- x/resource/tests/query_resource_test.go | 2 +- 10 files changed, 230 insertions(+), 148 deletions(-) diff --git a/x/cheqd/tests/const.go b/x/cheqd/tests/const.go index cd5394f9c..2b33e2506 100644 --- a/x/cheqd/tests/const.go +++ b/x/cheqd/tests/const.go @@ -1,3 +1,3 @@ package tests -const Ed25519VerificationKey2020 = "Ed25519VerificationKey2020" +// const Ed25519VerificationKey2020 = "Ed25519VerificationKey2020" diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index 4840f0814..f498d40c9 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -7,71 +7,89 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/btcsuite/btcutil/base58" - "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/multiformats/go-multibase" ) -// var _ = Describe("Create DID tests new", func() { -// var setup TestSetup - -// BeforeEach(func() { -// setup = Setup() -// }) - -// It("Valid: Works", func() { -// valid = true -// keys = map[string]KeyPair{ -// ImposterKey1: GenerateKeyPair(), -// } -// signers = []string{ImposterKey1} -// msg = &types.MsgCreateDidPayload{ -// Id: ImposterDID, -// Authentication: []string{ImposterKey1}, -// VerificationMethod: []*types.VerificationMethod{ -// { -// Id: ImposterKey1, -// Type: Ed25519VerificationKey2020, -// Controller: ImposterDID, -// }, -// }, -// } - -// for _, vm := range msg.VerificationMethod { -// if vm.PublicKeyMultibase == "" { -// vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) -// } -// Expect(err).To(BeNil()) -// } - -// signerKeys := map[string]ed25519.PrivateKey{} -// for _, signer := range signers { -// signerKeys[signer] = keys[signer].Private -// } - -// did, err := setup.SendCreateDid(msg, signerKeys) - -// if valid { -// Expect(err).To(BeNil()) -// Expect(msg.Id).To(Equal(did.Id)) -// Expect(msg.Controller).To(Equal(did.Controller)) -// Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) -// Expect(msg.Authentication).To(Equal(did.Authentication)) -// Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) -// Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) -// Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) -// Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) -// Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) -// Expect(msg.Service).To(Equal(did.Service)) -// Expect(msg.Context).To(Equal(did.Context)) -// } else { -// Expect(err).To(HaveOccurred()) -// Expect(errMsg).To(Equal(err.Error())) -// } - -// }) -// }) +var _ = Describe("Create DID tests new", func() { + var setup TestSetup + + BeforeEach(func() { + setup = Setup() + }) + + It("Valid: Works", func() { + did := GenerateDID(Base58_16chars) + keypair := GenerateKeyPair() + keyId := did + "#key-1" + + msg := &types.MsgCreateDidPayload{ + Id: did, + Authentication: []string{keyId}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: keyId, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair.Public), + }, + }, + } + + signatures := []SignInput{ + { + VerificationMethodId: keyId, + Key: keypair.Private, + }, + } + + _, err := setup.CreateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(did) + Expect(err).To(BeNil()) + Expect(msg.ToDid()).To(Equal(*created.Did)) + }) + + // ************************** + // ***** Negative cases ***** + // ************************** + + It("Not Valid: Second controller did not sign request", func() { + // Alice + aliceDid, _, _ := setup.CreateTestDid() + + // Bob + bobDid := GenerateDID(Base58_16chars) + bobKeypair := GenerateKeyPair() + bobKeyId := bobDid + "#key-1" + + msg := &types.MsgCreateDidPayload{ + Id: bobDid, + Controller: []string{aliceDid, bobDid}, + Authentication: []string{bobKeyId}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: bobKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bobDid, + PublicKeyMultibase: MustEncodeBase58(bobKeypair.Public), + }, + }, + } + + signatures := []SignInput{ + { + VerificationMethodId: bobKeyId, + Key: bobKeypair.Private, + }, + } + + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", aliceDid))) + }) +}) var _ = Describe("Create DID tests", func() { // params for cases @@ -142,7 +160,7 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, }, }, @@ -163,7 +181,7 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, }, }, @@ -184,7 +202,7 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, }, }, @@ -205,7 +223,7 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, }, }, @@ -226,7 +244,7 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, }, }, @@ -295,17 +313,17 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", }, { Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-2", - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", }, { Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-3", - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", }, { @@ -383,9 +401,9 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].Public), + PublicKeyMultibase: MustEncodeBase58(mainKeys[ImposterKey1].Public), }, }, } @@ -404,9 +422,9 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].Public), + PublicKeyMultibase: MustEncodeBase58(mainKeys[ImposterKey1].Public), }, }, } @@ -426,9 +444,9 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: ImposterKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: ImposterDID, - PublicKeyMultibase: "z" + base58.Encode(mainKeys[ImposterKey1].Public), + PublicKeyMultibase: MustEncodeBase58(mainKeys[ImposterKey1].Public), }, }, } @@ -452,7 +470,7 @@ var _ = Describe("Create DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: CharlieKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: CharlieDID, }, }, diff --git a/x/cheqd/tests/setup.go b/x/cheqd/tests/setup.go index 8aa457efd..9c5631ef4 100644 --- a/x/cheqd/tests/setup.go +++ b/x/cheqd/tests/setup.go @@ -78,32 +78,18 @@ func Setup() TestSetup { return setup } -func (s *TestSetup) BuildMsgCreateDidPayload(did string, key ed25519.PublicKey) *types.MsgCreateDidPayload { +func (s *TestSetup) BuildMsgCreateDidPayload(did string, keyId string, key ed25519.PublicKey) *types.MsgCreateDidPayload { return &types.MsgCreateDidPayload{ - Id: did, - Controller: nil, + Id: did, VerificationMethod: []*types.VerificationMethod{ { - Id: did + "#key-1", - Type: Ed25519VerificationKey2020, + Id: keyId, + Type: types.Ed25519VerificationKey2020, Controller: did, PublicKeyMultibase: MustEncodeBase58(key), }, }, - Authentication: []string{did + "#key-1"}, - AssertionMethod: []string{did + "#key-1"}, - CapabilityInvocation: []string{did + "#key-1"}, - CapabilityDelegation: []string{did + "#key-1"}, - KeyAgreement: []string{did + "#key-1"}, - AlsoKnownAs: []string{did + "#key-1"}, - Context: []string{"Context"}, - Service: []*types.Service{ - { - Id: did + "#service-2", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - }, - }, + Authentication: []string{keyId}, } } @@ -123,6 +109,7 @@ func (s *TestSetup) CreateToUpdateDid(did *types.MsgCreateDidPayload) *types.Msg } } +// TODO: Remove func (s *TestSetup) WrapCreateRequest(payload *types.MsgCreateDidPayload, keys map[string]ed25519.PrivateKey) *types.MsgCreateDid { var signatures []*types.SignInfo signingInput := payload.GetSignBytes() @@ -141,6 +128,68 @@ func (s *TestSetup) WrapCreateRequest(payload *types.MsgCreateDidPayload, keys m } } +func (s *TestSetup) CreateDid(payload *types.MsgCreateDidPayload, signInputs []SignInput) (*types.MsgCreateDidResponse, error) { + signBytes := payload.GetSignBytes() + var signatures []*types.SignInfo + + for _, input := range signInputs { + signature := ed25519.Sign(input.Key, signBytes) + + signatures = append(signatures, &types.SignInfo{ + VerificationMethodId: input.VerificationMethodId, + Signature: base64.StdEncoding.EncodeToString(signature), + }) + } + + msg := &types.MsgCreateDid{ + Payload: payload, + Signatures: signatures, + } + + return s.MsgServer.CreateDid(s.StdCtx, msg) +} + +func (s *TestSetup) CreateTestDid() (string, KeyPair, string) { + did := GenerateDID(Base58_16chars) + keypair := GenerateKeyPair() + keyId := did + "#key-1" + + msg := types.MsgCreateDidPayload{ + Id: did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: keyId, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair.Public), + }, + }, + Authentication: []string{keyId}, + } + + signatures := []SignInput{ + { + VerificationMethodId: keyId, + Key: keypair.Private, + }, + } + + _, err := s.CreateDid(&msg, signatures) + if err != nil { + panic(err) + } + + return did, keypair, keyId +} + +func (s *TestSetup) QueryDid(did string) (*types.QueryGetDidResponse, error) { + req := &types.QueryGetDidRequest{ + Id: did, + } + + return s.QueryServer.Did(s.StdCtx, req) +} + func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys []SignInput) *types.MsgUpdateDid { var signatures []*types.SignInfo signingInput := payload.GetSignBytes() @@ -161,11 +210,11 @@ func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys [ func (s *TestSetup) InitDid(did string) (map[string]ed25519.PrivateKey, *types.MsgCreateDidPayload, error) { pubKey, privKey, _ := ed25519.GenerateKey(rand.Reader) + keyId := did + "#key-1" // add new Did - didMsg := s.BuildMsgCreateDidPayload(did, pubKey) + didMsg := s.BuildMsgCreateDidPayload(did, keyId, pubKey) - keyId := did + "#key-1" keys := map[string]ed25519.PrivateKey{keyId: privKey} _, err := s.MsgServer.CreateDid(s.StdCtx, s.WrapCreateRequest(didMsg, keys)) @@ -245,7 +294,7 @@ func (s TestSetup) CreateTestDIDs(keys map[string]KeyPair) error { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -266,22 +315,22 @@ func (s TestSetup) CreateTestDIDs(keys map[string]KeyPair) error { VerificationMethod: []*types.VerificationMethod{ { Id: BobKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: BobKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: BobKey3, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: BobKey4, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, }, @@ -299,17 +348,17 @@ func (s TestSetup) CreateTestDIDs(keys map[string]KeyPair) error { VerificationMethod: []*types.VerificationMethod{ { Id: CharlieKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: CharlieKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: CharlieKey3, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, }, diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go index 09ffb2148..fb1ecca8e 100644 --- a/x/cheqd/tests/signature_verification_test.go +++ b/x/cheqd/tests/signature_verification_test.go @@ -9,7 +9,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" ) @@ -36,7 +35,7 @@ var _ = Describe("Signature Verification while updating DID", func() { When("Old signature in verification method is absent", func() { It("should fail", func() { updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod[0].Type = Ed25519VerificationKey2020 + updatedDidDoc.VerificationMethod[0].Type = types.Ed25519VerificationKey2020 _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) // check @@ -80,8 +79,8 @@ var _ = Describe("Signature Verification. Remove signature/VM", func() { BpubKey, BprivKey, _ = ed25519.GenerateKey(rand.Reader) // Create dids - aliceDid = setup.BuildMsgCreateDidPayload(AliceDID, ApubKey) - bobDid = setup.BuildMsgCreateDidPayload(BobDID, BpubKey) + aliceDid = setup.BuildMsgCreateDidPayload(AliceDID, AliceKey1, ApubKey) + bobDid = setup.BuildMsgCreateDidPayload(BobDID, BobKey1, BpubKey) // Collect private keys aliceKeys = map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} @@ -91,8 +90,8 @@ var _ = Describe("Signature Verification. Remove signature/VM", func() { aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ Id: AliceKey2, Controller: BobDID, - Type: Ed25519VerificationKey2020, - PublicKeyMultibase: "z" + base58.Encode(BpubKey), + Type: types.Ed25519VerificationKey2020, + PublicKeyMultibase: MustEncodeBase58(BpubKey), }) }) diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index 244fc1db5..cd4049328 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -104,7 +104,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, // TODO: Use multibase encoding PublicKeyMultibase: "z" + base58.Encode(mainKeys[AliceKey2].Public), @@ -122,7 +122,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -139,7 +139,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -167,7 +167,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, }, @@ -182,7 +182,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, }, @@ -198,7 +198,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -213,7 +213,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -229,7 +229,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -247,12 +247,12 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, }, @@ -268,12 +268,12 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, }, @@ -290,12 +290,12 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -321,7 +321,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -337,7 +337,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -354,7 +354,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -373,7 +373,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -389,7 +389,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -406,7 +406,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -423,12 +423,12 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: AliceKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, { Id: AliceKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: AliceDID, }, }, @@ -449,22 +449,22 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: CharlieKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: CharlieKey2, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: CharlieKey3, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, { Id: CharlieKey4, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: CharlieDID, }, }, @@ -479,7 +479,7 @@ var _ = Describe("Update DID tests", func() { VerificationMethod: []*types.VerificationMethod{ { Id: BobKey1, - Type: Ed25519VerificationKey2020, + Type: types.Ed25519VerificationKey2020, Controller: BobDID, }, }, diff --git a/x/cheqd/tests/utils.go b/x/cheqd/tests/utils.go index 01206dbdb..9ac2e2848 100644 --- a/x/cheqd/tests/utils.go +++ b/x/cheqd/tests/utils.go @@ -5,6 +5,7 @@ import ( "crypto/rand" mathrand "math/rand" + "github.com/google/uuid" "github.com/multiformats/go-multibase" . "github.com/onsi/gomega" ) @@ -19,12 +20,27 @@ func randBase58Seq(n int) string { return string(b) } -func GenerateDID() string { - return "did:cheqd:test:" + randBase58Seq(16) -} +type IDType int + +const ( + Base58_16chars IDType = iota + Base58_32chars IDType = iota + UUID IDType = iota +) -func GenerateFragment(did string) string { - return did + "#key-1" +func GenerateDID(idtype IDType) string { + prefix := "did:cheqd:" + DID_NAMESPACE + ":" + + switch idtype { + case Base58_16chars: + return prefix + randBase58Seq(16) + case Base58_32chars: + return prefix + randBase58Seq(32) + case UUID: + return prefix + uuid.NewString() + default: + panic("Unknown ID type") + } } func GenerateTestKeys() map[string]KeyPair { diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index e329f6374..692fefe81 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -20,7 +20,7 @@ var _ = Describe("CreateResource", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err = setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) resourcePayload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_all_resource_versions_test.go b/x/resource/tests/query_all_resource_versions_test.go index 4b69777cf..750a6938b 100644 --- a/x/resource/tests/query_all_resource_versions_test.go +++ b/x/resource/tests/query_all_resource_versions_test.go @@ -16,7 +16,7 @@ var _ = Describe("QueryAllResourceVersions", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_collection_resources_test.go b/x/resource/tests/query_collection_resources_test.go index c8e04e0e3..18036de72 100644 --- a/x/resource/tests/query_collection_resources_test.go +++ b/x/resource/tests/query_collection_resources_test.go @@ -16,7 +16,7 @@ var _ = Describe("QueryCollectionResources", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_resource_test.go b/x/resource/tests/query_resource_test.go index f9a8e17e4..0d87dd13a 100644 --- a/x/resource/tests/query_resource_test.go +++ b/x/resource/tests/query_resource_test.go @@ -17,7 +17,7 @@ var _ = Describe("QueryGetResource", func() { existingResource := ExistingResource() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, keys[ExistingDIDKey].Public) + didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) From 9f381d36d66b64cd419f0a94ff39d7a4c8c6f0db Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Tue, 11 Oct 2022 19:39:06 +0500 Subject: [PATCH 30/76] Improve did creation tests --- x/cheqd/tests/create_did_test.go | 562 +++++++++++++------------------ 1 file changed, 229 insertions(+), 333 deletions(-) diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index f498d40c9..e71969bcd 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -1,14 +1,12 @@ package tests import ( - "crypto/ed25519" "fmt" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/multiformats/go-multibase" ) var _ = Describe("Create DID tests new", func() { @@ -18,7 +16,7 @@ var _ = Describe("Create DID tests new", func() { setup = Setup() }) - It("Valid: Works", func() { + It("Valid: Works for simple did doc", func() { did := GenerateDID(Base58_16chars) keypair := GenerateKeyPair() keyId := did + "#key-1" @@ -52,13 +50,10 @@ var _ = Describe("Create DID tests new", func() { Expect(msg.ToDid()).To(Equal(*created.Did)) }) - // ************************** - // ***** Negative cases ***** - // ************************** - - It("Not Valid: Second controller did not sign request", func() { + It("Valid: DID with external controllers", func() { // Alice - aliceDid, _, _ := setup.CreateTestDid() + aliceDid, aliceKeypair, aliceKeyId := setup.CreateTestDid() + annaDid, annaKeypair, annaKeyId := setup.CreateTestDid() // Bob bobDid := GenerateDID(Base58_16chars) @@ -67,13 +62,13 @@ var _ = Describe("Create DID tests new", func() { msg := &types.MsgCreateDidPayload{ Id: bobDid, - Controller: []string{aliceDid, bobDid}, + Controller: []string{aliceDid, annaDid}, Authentication: []string{bobKeyId}, VerificationMethod: []*types.VerificationMethod{ { Id: bobKeyId, Type: types.Ed25519VerificationKey2020, - Controller: bobDid, + Controller: annaDid, PublicKeyMultibase: MustEncodeBase58(bobKeypair.Public), }, }, @@ -81,412 +76,313 @@ var _ = Describe("Create DID tests new", func() { signatures := []SignInput{ { - VerificationMethodId: bobKeyId, - Key: bobKeypair.Private, + VerificationMethodId: aliceKeyId, + Key: aliceKeypair.Private, + }, + { + VerificationMethodId: annaKeyId, + Key: annaKeypair.Private, }, } _, err := setup.CreateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", aliceDid))) - }) -}) - -var _ = Describe("Create DID tests", func() { - // params for cases - var valid bool - var keys map[string]KeyPair - var signers []string - var msg *types.MsgCreateDidPayload - errMsg := "" - - var setup TestSetup - var err error - mainKeys := GenerateTestKeys() + Expect(err).To(BeNil()) - BeforeEach(func() { - // setup - valid = false - keys = map[string]KeyPair{} - signers = []string{} - msg = &types.MsgCreateDidPayload{} - errMsg = "" + // check + created, err := setup.QueryDid(bobDid) + Expect(err).To(BeNil()) + Expect(msg.ToDid()).To(Equal(*created.Did)) }) - AfterEach(func() { - setup = InitEnv(mainKeys) + It("Valid: Works for the did doc witha all properties", func() { + did := GenerateDID(Base58_16chars) - for _, vm := range msg.VerificationMethod { - if vm.PublicKeyMultibase == "" { - vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) - } - Expect(err).To(BeNil()) - } + keypair1 := GenerateKeyPair() + keyId1 := did + "#key-1" - signerKeys := map[string]ed25519.PrivateKey{} - for _, signer := range signers { - signerKeys[signer] = keys[signer].Private - } + keypair2 := GenerateKeyPair() + keyId2 := did + "#key-2" - did, err := setup.SendCreateDid(msg, signerKeys) - - if valid { - Expect(err).To(BeNil()) - Expect(msg.Id).To(Equal(did.Id)) - Expect(msg.Controller).To(Equal(did.Controller)) - Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) - Expect(msg.Authentication).To(Equal(did.Authentication)) - Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) - Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) - Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) - Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) - Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) - Expect(msg.Service).To(Equal(did.Service)) - Expect(msg.Context).To(Equal(did.Context)) - } else { - Expect(err).To(HaveOccurred()) - Expect(errMsg).To(Equal(err.Error())) - } - }) + keypair3 := GenerateKeyPair() + keyId3 := did + "#key-3" - It("Valid: Works", func() { - valid = true - keys = map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - } - signers = []string{ImposterKey1} - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Authentication: []string{ImposterKey1}, + keypair4 := GenerateKeyPair() + keyId4 := did + "#key-4" + + msg := &types.MsgCreateDidPayload{ + Context: []string{"abc", "def"}, + Id: did, + Controller: []string{did}, VerificationMethod: []*types.VerificationMethod{ { - Id: ImposterKey1, - Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, + Id: keyId1, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair1.Public), }, - }, - } - }) - - It("Valid: Works with Key Agreement", func() { - valid = true - keys = map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: mainKeys[AliceKey1], - } - signers = []string{ImposterKey1, AliceKey1} - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - KeyAgreement: []string{ImposterKey1}, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ { - Id: ImposterKey1, - Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, + Id: keyId2, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair2.Public), + }, + { + Id: keyId3, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair3.Public), + }, + { + Id: keyId4, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair4.Public), }, }, - } - }) - - It("Valid: Works with Assertion Method", func() { - valid = true - keys = map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: mainKeys[AliceKey1], - } - signers = []string{AliceKey1, ImposterKey1} - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - AssertionMethod: []string{ImposterKey1}, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ + Authentication: []string{keyId1, keyId2}, + AssertionMethod: []string{keyId3}, + CapabilityInvocation: []string{keyId4, keyId1}, + CapabilityDelegation: []string{keyId4, keyId2}, + KeyAgreement: []string{keyId1, keyId2, keyId3, keyId4}, + Service: []*types.Service{ { - Id: ImposterKey1, - Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, + Id: did + "#service-1", + Type: "type-1", + ServiceEndpoint: "endpoint-1", }, }, + AlsoKnownAs: []string{"alias-1", "alias-2"}, } - }) - It("Valid: Works with Capability Delegation", func() { - valid = true - keys = map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: mainKeys[AliceKey1], - } - signers = []string{AliceKey1, ImposterKey1} - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - CapabilityDelegation: []string{ImposterKey1}, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: ImposterKey1, - Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, - }, + signatures := []SignInput{ + { + VerificationMethodId: keyId1, + Key: keypair1.Private, }, } + + _, err := setup.CreateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(did) + Expect(err).To(BeNil()) + Expect(msg.ToDid()).To(Equal(*created.Did)) }) - It("Valid: Works with Capability Invocation", func() { - valid = true - keys = map[string]KeyPair{ - ImposterKey1: GenerateKeyPair(), - AliceKey1: mainKeys[AliceKey1], - } - signers = []string{AliceKey1, ImposterKey1} - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - CapabilityInvocation: []string{ImposterKey1}, - Controller: []string{AliceDID}, + // ************************** + // ***** Negative cases ***** + // ************************** + + It("Not Valid: Second controller did not sign request", func() { + // Alice + aliceDid, _, _ := setup.CreateTestDid() + + // Bob + bobDid := GenerateDID(Base58_16chars) + bobKeypair := GenerateKeyPair() + bobKeyId := bobDid + "#key-1" + + msg := &types.MsgCreateDidPayload{ + Id: bobDid, + Controller: []string{aliceDid, bobDid}, + Authentication: []string{bobKeyId}, VerificationMethod: []*types.VerificationMethod{ { - Id: ImposterKey1, - Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, + Id: bobKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bobDid, + PublicKeyMultibase: MustEncodeBase58(bobKeypair.Public), }, }, } - }) - It("Valid: With controller works", func() { - valid = true - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, BobDID}, - } - signers = []string{AliceKey1, BobKey3} - keys = map[string]KeyPair{ - AliceKey1: mainKeys[AliceKey1], - BobKey3: mainKeys[BobKey3], + signatures := []SignInput{ + { + VerificationMethodId: bobKeyId, + Key: bobKeypair.Private, + }, } + + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", aliceDid))) }) - It("Valid: Full message works", func() { - valid = true - keys = map[string]KeyPair{ - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-2": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-3": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-4": GenerateKeyPair(), - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5": GenerateKeyPair(), - AliceKey1: mainKeys[AliceKey1], - BobKey1: mainKeys[BobKey1], - BobKey2: mainKeys[BobKey2], - BobKey3: mainKeys[BobKey3], - CharlieKey1: mainKeys[CharlieKey1], - CharlieKey2: mainKeys[CharlieKey2], - CharlieKey3: mainKeys[CharlieKey3], - } - signers = []string{ - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", - AliceKey1, - BobKey1, - BobKey2, - BobKey3, - CharlieKey1, - CharlieKey2, - CharlieKey3, - } - msg = &types.MsgCreateDidPayload{ - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy", - Authentication: []string{ - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", - "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", - }, - Context: []string{"abc", "de"}, - CapabilityInvocation: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-2"}, - CapabilityDelegation: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-3"}, - KeyAgreement: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy#key-4"}, - AlsoKnownAs: []string{"SomeUri"}, - Service: []*types.Service{ - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#service-1", - Type: "DIDCommMessaging", - ServiceEndpoint: "ServiceEndpoint", - }, - }, - Controller: []string{"did:cheqd:test:yyyyyyyyyyyyyyyy", AliceDID, BobDID, CharlieDID}, + It("Not Valid: No signature", func() { + did := GenerateDID(Base58_16chars) + keypair := GenerateKeyPair() + keyId := did + "#key-1" + + msg := &types.MsgCreateDidPayload{ + Id: did, + Controller: []string{did}, + Authentication: []string{keyId}, VerificationMethod: []*types.VerificationMethod{ { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-1", - Type: types.Ed25519VerificationKey2020, - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-2", - Type: types.Ed25519VerificationKey2020, - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-3", - Type: types.Ed25519VerificationKey2020, - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-4", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", - }, - { - Id: "did:cheqd:test:yyyyyyyyyyyyyyyy#key-5", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:test:yyyyyyyyyyyyyyyy", + Id: keyId, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair.Public), }, }, } - }) - - // ************************** - // ***** Negative cases ***** - // ************************** - It("Not Valid: Second controller did not sign request", func() { - valid = false - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, BobDID}, - } - signers = []string{AliceKey1} - keys = map[string]KeyPair{ - AliceKey1: mainKeys[AliceKey1], - } - errMsg = fmt.Sprintf("signer: %s: signature is required but not found", BobDID) - }) + signatures := []SignInput{} - It("Not Valid: No signature", func() { - valid = false - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, BobDID}, - } - errMsg = fmt.Sprintf("signer: %s: signature is required but not found", AliceDID) + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", did))) }) It("Not Valid: Controller not found", func() { - valid = false - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, NotFounDID}, - } - signers = []string{AliceKey1, ImposterKey1} - keys = map[string]KeyPair{ - AliceKey1: mainKeys[AliceKey1], - ImposterKey1: GenerateKeyPair(), + did := GenerateDID(Base58_16chars) + keypair := GenerateKeyPair() + keyId := did + "#key-1" + + nonExistingDid := GenerateDID(Base58_16chars) + + msg := &types.MsgCreateDidPayload{ + Id: did, + Controller: []string{nonExistingDid}, + Authentication: []string{keyId}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: keyId, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair.Public), + }, + }, } - errMsg = fmt.Sprintf("%s: DID Doc not found", NotFounDID) + + signatures := []SignInput{} + + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s: DID Doc not found", nonExistingDid))) }) It("Not Valid: Wrong signature", func() { - valid = false - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID}, - } - signers = []string{AliceKey1} - keys = map[string]KeyPair{ - AliceKey1: mainKeys[BobKey1], - } - errMsg = fmt.Sprintf("method id: %s: invalid signature detected", AliceKey1) - }) + did := GenerateDID(Base58_16chars) + keypair := GenerateKeyPair() + keyId := did + "#key-1" - It("Not Valid: DID signed by wrong controller", func() { - valid = false - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Authentication: []string{ImposterKey1}, + msg := &types.MsgCreateDidPayload{ + Id: did, + Controller: []string{did}, + Authentication: []string{keyId}, VerificationMethod: []*types.VerificationMethod{ { - Id: ImposterKey1, + Id: keyId, Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, - PublicKeyMultibase: MustEncodeBase58(mainKeys[ImposterKey1].Public), + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair.Public), }, }, } - signers = []string{AliceKey1} - keys = map[string]KeyPair{ - AliceKey1: mainKeys[AliceKey1], + + invalidKey := GenerateKeyPair() + + signatures := []SignInput{ + { + VerificationMethodId: keyId, + Key: invalidKey.Private, + }, } - errMsg = fmt.Sprintf("signer: %s: signature is required but not found", ImposterDID) + + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("method id: %s: invalid signature detected", keyId))) }) - It("Not Valid: DID self-signed by not existing verification method", func() { - valid = false - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Authentication: []string{ImposterKey1}, + It("Not Valid: DID signed by wrong controller", func() { + // Alice + _, aliceKeypair, aliceKeyId := setup.CreateTestDid() + + // Bob + bobDid := GenerateDID(Base58_16chars) + bobKeypair := GenerateKeyPair() + bobKeyId := bobDid + "#key-1" + + msg := &types.MsgCreateDidPayload{ + Id: bobDid, + Controller: []string{bobDid}, + Authentication: []string{bobKeyId}, VerificationMethod: []*types.VerificationMethod{ { - Id: ImposterKey1, + Id: bobKeyId, Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, - PublicKeyMultibase: MustEncodeBase58(mainKeys[ImposterKey1].Public), + Controller: bobDid, + PublicKeyMultibase: MustEncodeBase58(bobKeypair.Public), }, }, } - signers = []string{ImposterKey2} - keys = map[string]KeyPair{ - ImposterKey2: GenerateKeyPair(), + + signatures := []SignInput{ + { + VerificationMethodId: aliceKeyId, + Key: aliceKeypair.Private, + }, } - errMsg = fmt.Sprintf("%s: verification method not found", ImposterKey2) + + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", bobDid))) }) - It("Not Valid: Self-signature not found", func() { - valid = false - msg = &types.MsgCreateDidPayload{ - Id: ImposterDID, - Controller: []string{AliceDID, ImposterDID}, - Authentication: []string{ImposterKey1}, + It("Not Valid: DID self-signed by not existing verification method", func() { + did := GenerateDID(Base58_16chars) + keypair := GenerateKeyPair() + keyId := did + "#key-1" + + msg := &types.MsgCreateDidPayload{ + Id: did, + Controller: []string{did}, + Authentication: []string{keyId}, VerificationMethod: []*types.VerificationMethod{ { - Id: ImposterKey1, + Id: keyId, Type: types.Ed25519VerificationKey2020, - Controller: ImposterDID, - PublicKeyMultibase: MustEncodeBase58(mainKeys[ImposterKey1].Public), + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keypair.Public), }, }, } - signers = []string{AliceKey1, ImposterKey2} - keys = map[string]KeyPair{ - AliceKey1: mainKeys[AliceKey1], - ImposterKey2: GenerateKeyPair(), + + invalidKeyId := did + "#key-2" + + signatures := []SignInput{ + { + VerificationMethodId: invalidKeyId, + Key: keypair.Private, + }, } - errMsg = fmt.Sprintf("%s: verification method not found", ImposterKey2) + + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s: verification method not found", invalidKeyId))) }) It("Not Valid: DID Doc already exists", func() { - valid = false - keys = map[string]KeyPair{ - CharlieKey1: GenerateKeyPair(), - } - signers = []string{CharlieKey1} - msg = &types.MsgCreateDidPayload{ - Id: CharlieDID, - Authentication: []string{CharlieKey1}, + // Alice + aliceDid, aliceKeypair, aliceKeyId := setup.CreateTestDid() + + msg := &types.MsgCreateDidPayload{ + Id: aliceDid, + Authentication: []string{aliceKeyId}, VerificationMethod: []*types.VerificationMethod{ { - Id: CharlieKey1, - Type: types.Ed25519VerificationKey2020, - Controller: CharlieDID, + Id: aliceKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: aliceDid, + PublicKeyMultibase: MustEncodeBase58(aliceKeypair.Public), }, }, } - errMsg = fmt.Sprintf("%s: DID Doc exists", CharlieDID) - }) -}) - -var _ = Describe("TestHandler", func() { - It("Fails cause DIDDoc is already exists", func() { - setup := Setup() - _, _, _ = setup.InitDid(AliceDID) - _, _, err := setup.InitDid(AliceDID) + signatures := []SignInput{ + { + VerificationMethodId: aliceKeyId, + Key: aliceKeypair.Private, + }, + } - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(fmt.Sprintf("%s: DID Doc exists", AliceDID))) + _, err := setup.CreateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s: DID Doc exists", aliceDid))) }) }) From 3d773d5e42554a25ae787b066b1d6f467aa2e3a0 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Wed, 12 Oct 2022 00:12:48 +0500 Subject: [PATCH 31/76] Fix bug with VM update --- x/cheqd/keeper/msg_server_update_did.go | 11 +- x/cheqd/tests/create_did_test.go | 57 +- x/cheqd/tests/setup.go | 94 -- x/cheqd/tests/setup_create_did.go | 100 ++ x/cheqd/tests/setup_query_did.go | 11 + x/cheqd/tests/setup_update_did.go | 29 + x/cheqd/tests/signature_verification_test.go | 129 --- x/cheqd/tests/types.go | 19 +- x/cheqd/tests/update_did_test.go | 932 ++++++++++-------- x/cheqd/types/did_did.go | 13 +- x/cheqd/types/did_verification_method.go | 20 +- x/resource/tests/create_resource_test.go | 2 +- .../tests/query_all_resource_versions_test.go | 2 +- .../tests/query_collection_resources_test.go | 2 +- x/resource/tests/query_resource_test.go | 2 +- 15 files changed, 730 insertions(+), 693 deletions(-) create mode 100644 x/cheqd/tests/setup_create_did.go create mode 100644 x/cheqd/tests/setup_query_did.go create mode 100644 x/cheqd/tests/setup_update_did.go delete mode 100644 x/cheqd/tests/signature_verification_test.go diff --git a/x/cheqd/keeper/msg_server_update_did.go b/x/cheqd/keeper/msg_server_update_did.go index 8e7fcaea7..3cff40319 100644 --- a/x/cheqd/keeper/msg_server_update_did.go +++ b/x/cheqd/keeper/msg_server_update_did.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "reflect" "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/cheqd/cheqd-node/x/cheqd/utils" @@ -151,9 +152,13 @@ func GetSignerDIDsForDIDUpdate(existingDid types.Did, updatedDid types.Did) []st } // VM updated - // We don't compare ids because they will be different after replacing ids on the updated version of DID. - // Fragments equality is checked above. - if !types.CompareVerificationMethodsWithoutIds(existingVM, *updatedVM) { + // We have to revert renaming before comparing veriifcation methods. + // Otherwise we will detect id and controller change + // for non changed VMs because of `-updated` postfix. + originalUpdatedVM := *updatedVM + originalUpdatedVM.ReplaceIds(updatedDid.Id, existingDid.Id) + + if !reflect.DeepEqual(existingVM, originalUpdatedVM) { signers = append(signers, existingVM.Controller, updatedVM.Controller) continue } diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index e71969bcd..a83204ea6 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -9,7 +9,7 @@ import ( "github.com/cheqd/cheqd-node/x/cheqd/types" ) -var _ = Describe("Create DID tests new", func() { +var _ = Describe("Create DID tests", func() { var setup TestSetup BeforeEach(func() { @@ -52,8 +52,8 @@ var _ = Describe("Create DID tests new", func() { It("Valid: DID with external controllers", func() { // Alice - aliceDid, aliceKeypair, aliceKeyId := setup.CreateTestDid() - annaDid, annaKeypair, annaKeyId := setup.CreateTestDid() + alice := setup.CreateSimpleDid() + anna := setup.CreateSimpleDid() // Bob bobDid := GenerateDID(Base58_16chars) @@ -62,28 +62,19 @@ var _ = Describe("Create DID tests new", func() { msg := &types.MsgCreateDidPayload{ Id: bobDid, - Controller: []string{aliceDid, annaDid}, + Controller: []string{alice.Did, anna.Did}, Authentication: []string{bobKeyId}, VerificationMethod: []*types.VerificationMethod{ { Id: bobKeyId, Type: types.Ed25519VerificationKey2020, - Controller: annaDid, + Controller: anna.Did, PublicKeyMultibase: MustEncodeBase58(bobKeypair.Public), }, }, } - signatures := []SignInput{ - { - VerificationMethodId: aliceKeyId, - Key: aliceKeypair.Private, - }, - { - VerificationMethodId: annaKeyId, - Key: annaKeypair.Private, - }, - } + signatures := []SignInput{alice.SignInput, anna.SignInput} _, err := setup.CreateDid(msg, signatures) Expect(err).To(BeNil()) @@ -176,7 +167,7 @@ var _ = Describe("Create DID tests new", func() { It("Not Valid: Second controller did not sign request", func() { // Alice - aliceDid, _, _ := setup.CreateTestDid() + alice := setup.CreateSimpleDid() // Bob bobDid := GenerateDID(Base58_16chars) @@ -185,7 +176,7 @@ var _ = Describe("Create DID tests new", func() { msg := &types.MsgCreateDidPayload{ Id: bobDid, - Controller: []string{aliceDid, bobDid}, + Controller: []string{alice.Did, bobDid}, Authentication: []string{bobKeyId}, VerificationMethod: []*types.VerificationMethod{ { @@ -205,7 +196,7 @@ var _ = Describe("Create DID tests new", func() { } _, err := setup.CreateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", aliceDid))) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", alice.Did))) }) It("Not Valid: No signature", func() { @@ -294,7 +285,7 @@ var _ = Describe("Create DID tests new", func() { It("Not Valid: DID signed by wrong controller", func() { // Alice - _, aliceKeypair, aliceKeyId := setup.CreateTestDid() + alice := setup.CreateSimpleDid() // Bob bobDid := GenerateDID(Base58_16chars) @@ -315,12 +306,7 @@ var _ = Describe("Create DID tests new", func() { }, } - signatures := []SignInput{ - { - VerificationMethodId: aliceKeyId, - Key: aliceKeypair.Private, - }, - } + signatures := []SignInput{alice.SignInput} _, err := setup.CreateDid(msg, signatures) Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("signer: %s: signature is required but not found", bobDid))) @@ -360,29 +346,24 @@ var _ = Describe("Create DID tests new", func() { It("Not Valid: DID Doc already exists", func() { // Alice - aliceDid, aliceKeypair, aliceKeyId := setup.CreateTestDid() + alice := setup.CreateSimpleDid() msg := &types.MsgCreateDidPayload{ - Id: aliceDid, - Authentication: []string{aliceKeyId}, + Id: alice.Did, + Authentication: []string{alice.KeyId}, VerificationMethod: []*types.VerificationMethod{ { - Id: aliceKeyId, + Id: alice.KeyId, Type: types.Ed25519VerificationKey2020, - Controller: aliceDid, - PublicKeyMultibase: MustEncodeBase58(aliceKeypair.Public), + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), }, }, } - signatures := []SignInput{ - { - VerificationMethodId: aliceKeyId, - Key: aliceKeypair.Private, - }, - } + signatures := []SignInput{alice.SignInput} _, err := setup.CreateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s: DID Doc exists", aliceDid))) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s: DID Doc exists", alice.Did))) }) }) diff --git a/x/cheqd/tests/setup.go b/x/cheqd/tests/setup.go index 9c5631ef4..d7881e7b0 100644 --- a/x/cheqd/tests/setup.go +++ b/x/cheqd/tests/setup.go @@ -78,21 +78,6 @@ func Setup() TestSetup { return setup } -func (s *TestSetup) BuildMsgCreateDidPayload(did string, keyId string, key ed25519.PublicKey) *types.MsgCreateDidPayload { - return &types.MsgCreateDidPayload{ - Id: did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: keyId, - Type: types.Ed25519VerificationKey2020, - Controller: did, - PublicKeyMultibase: MustEncodeBase58(key), - }, - }, - Authentication: []string{keyId}, - } -} - func (s *TestSetup) CreateToUpdateDid(did *types.MsgCreateDidPayload) *types.MsgUpdateDidPayload { return &types.MsgUpdateDidPayload{ Id: did.Id, @@ -128,68 +113,6 @@ func (s *TestSetup) WrapCreateRequest(payload *types.MsgCreateDidPayload, keys m } } -func (s *TestSetup) CreateDid(payload *types.MsgCreateDidPayload, signInputs []SignInput) (*types.MsgCreateDidResponse, error) { - signBytes := payload.GetSignBytes() - var signatures []*types.SignInfo - - for _, input := range signInputs { - signature := ed25519.Sign(input.Key, signBytes) - - signatures = append(signatures, &types.SignInfo{ - VerificationMethodId: input.VerificationMethodId, - Signature: base64.StdEncoding.EncodeToString(signature), - }) - } - - msg := &types.MsgCreateDid{ - Payload: payload, - Signatures: signatures, - } - - return s.MsgServer.CreateDid(s.StdCtx, msg) -} - -func (s *TestSetup) CreateTestDid() (string, KeyPair, string) { - did := GenerateDID(Base58_16chars) - keypair := GenerateKeyPair() - keyId := did + "#key-1" - - msg := types.MsgCreateDidPayload{ - Id: did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: keyId, - Type: types.Ed25519VerificationKey2020, - Controller: did, - PublicKeyMultibase: MustEncodeBase58(keypair.Public), - }, - }, - Authentication: []string{keyId}, - } - - signatures := []SignInput{ - { - VerificationMethodId: keyId, - Key: keypair.Private, - }, - } - - _, err := s.CreateDid(&msg, signatures) - if err != nil { - panic(err) - } - - return did, keypair, keyId -} - -func (s *TestSetup) QueryDid(did string) (*types.QueryGetDidResponse, error) { - req := &types.QueryGetDidRequest{ - Id: did, - } - - return s.QueryServer.Did(s.StdCtx, req) -} - func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys []SignInput) *types.MsgUpdateDid { var signatures []*types.SignInfo signingInput := payload.GetSignBytes() @@ -208,23 +131,6 @@ func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys [ } } -func (s *TestSetup) InitDid(did string) (map[string]ed25519.PrivateKey, *types.MsgCreateDidPayload, error) { - pubKey, privKey, _ := ed25519.GenerateKey(rand.Reader) - keyId := did + "#key-1" - - // add new Did - didMsg := s.BuildMsgCreateDidPayload(did, keyId, pubKey) - - keys := map[string]ed25519.PrivateKey{keyId: privKey} - - _, err := s.MsgServer.CreateDid(s.StdCtx, s.WrapCreateRequest(didMsg, keys)) - if err != nil { - return nil, nil, err - } - - return keys, didMsg, nil -} - func (s *TestSetup) SendUpdateDid(msg *types.MsgUpdateDidPayload, keys []SignInput) (*types.Did, error) { req := types.QueryGetDidRequest{ Id: msg.Id, diff --git a/x/cheqd/tests/setup_create_did.go b/x/cheqd/tests/setup_create_did.go new file mode 100644 index 000000000..28fc3d003 --- /dev/null +++ b/x/cheqd/tests/setup_create_did.go @@ -0,0 +1,100 @@ +package tests + +import ( + "crypto/ed25519" + "encoding/base64" + + "github.com/cheqd/cheqd-node/x/cheqd/types" +) + +func (s *TestSetup) CreateDid(payload *types.MsgCreateDidPayload, signInputs []SignInput) (*types.MsgCreateDidResponse, error) { + signBytes := payload.GetSignBytes() + var signatures []*types.SignInfo + + for _, input := range signInputs { + signature := ed25519.Sign(input.Key, signBytes) + + signatures = append(signatures, &types.SignInfo{ + VerificationMethodId: input.VerificationMethodId, + Signature: base64.StdEncoding.EncodeToString(signature), + }) + } + + msg := &types.MsgCreateDid{ + Payload: payload, + Signatures: signatures, + } + + return s.MsgServer.CreateDid(s.StdCtx, msg) +} + +func (s *TestSetup) BuildSimpleDid() DidInfo { + did := GenerateDID(Base58_16chars) + keyPair := GenerateKeyPair() + keyId := did + "#key-1" + + msg := &types.MsgCreateDidPayload{ + Id: did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: keyId, + Type: types.Ed25519VerificationKey2020, + Controller: did, + PublicKeyMultibase: MustEncodeBase58(keyPair.Public), + }, + }, + Authentication: []string{keyId}, + } + + signInput := SignInput{ + VerificationMethodId: keyId, + Key: keyPair.Private, + } + + return DidInfo{ + Did: did, + KeyPair: keyPair, + KeyId: keyId, + Msg: msg, + SignInput: signInput, + } +} + +func (s *TestSetup) CreateSimpleDid() CreatedDidInfo { + did := s.BuildSimpleDid() + + _, err := s.CreateDid(did.Msg, []SignInput{did.SignInput}) + if err != nil { + panic(err) + } + + created, err := s.QueryDid(did.Did) + if err != nil { + panic(err) + } + + return CreatedDidInfo{ + DidInfo: did, + VersionId: created.Metadata.VersionId, + } +} + +func (s *TestSetup) CreateDidWithExternalConterllers(controllers []string, signInputs []SignInput) CreatedDidInfo { + did := s.BuildSimpleDid() + did.Msg.Controller = append(did.Msg.Controller, controllers...) + + _, err := s.CreateDid(did.Msg, append(signInputs, did.SignInput)) + if err != nil { + panic(err) + } + + created, err := s.QueryDid(did.Did) + if err != nil { + panic(err) + } + + return CreatedDidInfo{ + DidInfo: did, + VersionId: created.Metadata.VersionId, + } +} diff --git a/x/cheqd/tests/setup_query_did.go b/x/cheqd/tests/setup_query_did.go new file mode 100644 index 000000000..d1618eb23 --- /dev/null +++ b/x/cheqd/tests/setup_query_did.go @@ -0,0 +1,11 @@ +package tests + +import "github.com/cheqd/cheqd-node/x/cheqd/types" + +func (s *TestSetup) QueryDid(did string) (*types.QueryGetDidResponse, error) { + req := &types.QueryGetDidRequest{ + Id: did, + } + + return s.QueryServer.Did(s.StdCtx, req) +} diff --git a/x/cheqd/tests/setup_update_did.go b/x/cheqd/tests/setup_update_did.go new file mode 100644 index 000000000..c703ec859 --- /dev/null +++ b/x/cheqd/tests/setup_update_did.go @@ -0,0 +1,29 @@ +package tests + +import ( + "crypto/ed25519" + "encoding/base64" + + "github.com/cheqd/cheqd-node/x/cheqd/types" +) + +func (s *TestSetup) UpdateDid(payload *types.MsgUpdateDidPayload, signInputs []SignInput) (*types.MsgUpdateDidResponse, error) { + signBytes := payload.GetSignBytes() + var signatures []*types.SignInfo + + for _, input := range signInputs { + signature := ed25519.Sign(input.Key, signBytes) + + signatures = append(signatures, &types.SignInfo{ + VerificationMethodId: input.VerificationMethodId, + Signature: base64.StdEncoding.EncodeToString(signature), + }) + } + + msg := &types.MsgUpdateDid{ + Payload: payload, + Signatures: signatures, + } + + return s.MsgServer.UpdateDid(s.StdCtx, msg) +} diff --git a/x/cheqd/tests/signature_verification_test.go b/x/cheqd/tests/signature_verification_test.go deleted file mode 100644 index fb1ecca8e..000000000 --- a/x/cheqd/tests/signature_verification_test.go +++ /dev/null @@ -1,129 +0,0 @@ -package tests - -import ( - "crypto/ed25519" - "crypto/rand" - "fmt" - "reflect" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/cheqd/cheqd-node/x/cheqd/types" -) - -var _ = Describe("Signature Verification while updating DID", func() { - var setup TestSetup - var aliceKeys, bobKeys map[string]ed25519.PrivateKey - var aliceDid *types.MsgCreateDidPayload - BeforeEach(func() { - setup = Setup() - aliceKeys, aliceDid, _ = setup.InitDid(AliceDID) - bobKeys, _, _ = setup.InitDid(BobDID) - }) - - It("should have changed DIDDoc controller", func() { - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) - receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - - Expect(aliceDid.Controller).To(Not(Equal(receivedDid.Controller))) - Expect([]string{AliceDID, BobDID}).To(Not(Equal(receivedDid.Controller))) - Expect([]string{BobDID}, receivedDid.Controller) - }) - - When("Old signature in verification method is absent", func() { - It("should fail", func() { - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod[0].Type = types.Ed25519VerificationKey2020 - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - - // check - Expect(err).To(Not(BeNil())) - Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) - }) - }) - - It("should fails cause we need old signature for changing verification method controller", func() { - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod[0].Controller = BobDID - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - - // check - Expect(err).To(Not(BeNil())) - Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) - }) - - It("should fails cause we need old signature for changing DIDDoc controller", func() { - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - - // check - Expect(err).To(Not(BeNil())) - Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) - }) -}) - -var _ = Describe("Signature Verification. Remove signature/VM", func() { - var setup TestSetup - var ApubKey, BpubKey ed25519.PublicKey - var AprivKey, BprivKey ed25519.PrivateKey - var aliceDid, bobDid *types.MsgCreateDidPayload - var aliceKeys, bobKeys map[string]ed25519.PrivateKey - - BeforeEach(func() { - setup = Setup() - // Generate keys - ApubKey, AprivKey, _ = ed25519.GenerateKey(rand.Reader) - BpubKey, BprivKey, _ = ed25519.GenerateKey(rand.Reader) - - // Create dids - aliceDid = setup.BuildMsgCreateDidPayload(AliceDID, AliceKey1, ApubKey) - bobDid = setup.BuildMsgCreateDidPayload(BobDID, BobKey1, BpubKey) - - // Collect private keys - aliceKeys = map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} - bobKeys = map[string]ed25519.PrivateKey{BobKey1: BprivKey} - - // Add verification method - aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ - Id: AliceKey2, - Controller: BobDID, - Type: types.Ed25519VerificationKey2020, - PublicKeyMultibase: MustEncodeBase58(BpubKey), - }) - }) - - It("should fails cause old signature is required for removing this signature", func() { - // Send dids - _, _ = setup.SendCreateDid(bobDid, bobKeys) - _, _ = setup.SendCreateDid(aliceDid, aliceKeys) - - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} - updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} - _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - - // check - Expect(err).To(Not(BeNil())) - Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) - }) - - It("should not fails while removing the whole verification method", func() { - aliceDid.Authentication = append(aliceDid.Authentication, AliceKey2) - - // Send dids - _, _ = setup.SendCreateDid(bobDid, bobKeys) - _, _ = setup.SendCreateDid(aliceDid, aliceKeys) - - updatedDidDoc := setup.CreateToUpdateDid(aliceDid) - updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} - updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} - receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - - // check - Expect(len(aliceDid.VerificationMethod)).To(Not(Equal(len(receivedDid.VerificationMethod)))) - Expect(reflect.DeepEqual(aliceDid.VerificationMethod[0], receivedDid.VerificationMethod[0])).To(BeTrue()) - }) -}) diff --git a/x/cheqd/tests/types.go b/x/cheqd/tests/types.go index ddafef7bd..0aa97baee 100644 --- a/x/cheqd/tests/types.go +++ b/x/cheqd/tests/types.go @@ -1,6 +1,10 @@ package tests -import "crypto/ed25519" +import ( + "crypto/ed25519" + + "github.com/cheqd/cheqd-node/x/cheqd/types" +) type KeyPair struct { Private ed25519.PrivateKey @@ -11,3 +15,16 @@ type SignInput struct { VerificationMethodId string Key ed25519.PrivateKey } + +type DidInfo struct { + Msg *types.MsgCreateDidPayload + Did string + KeyPair KeyPair + KeyId string + SignInput SignInput +} + +type CreatedDidInfo struct { + DidInfo + VersionId string +} diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index cd4049328..158ee6605 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -6,152 +6,119 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/btcsuite/btcutil/base58" "github.com/cheqd/cheqd-node/x/cheqd/types" - "github.com/multiformats/go-multibase" ) var _ = Describe("Update DID tests", func() { - // params for cases - var valid bool - var signers []string - var signerKeys []SignInput - var msg *types.MsgUpdateDidPayload - errMsg := "" - var setup TestSetup - var err error - mainKeys := map[string]KeyPair{ - AliceKey1: GenerateKeyPair(), - AliceKey2: GenerateKeyPair(), - BobKey1: GenerateKeyPair(), - BobKey2: GenerateKeyPair(), - BobKey3: GenerateKeyPair(), - BobKey4: GenerateKeyPair(), - CharlieKey1: GenerateKeyPair(), - CharlieKey2: GenerateKeyPair(), - CharlieKey3: GenerateKeyPair(), - CharlieKey4: GenerateKeyPair(), - ImposterKey1: GenerateKeyPair(), - } BeforeEach(func() { - // setup - valid = false - signers = []string{} - signerKeys = []SignInput{} - msg = &types.MsgUpdateDidPayload{} - errMsg = "" + setup = Setup() }) - AfterEach(func() { - setup = InitEnv(mainKeys) - - for _, vm := range msg.VerificationMethod { - if vm.PublicKeyMultibase == "" { - vm.PublicKeyMultibase, err = multibase.Encode(multibase.Base58BTC, mainKeys[vm.Id].Public) - } - Expect(err).To(BeNil()) - } - - compiledKeys := []SignInput{} - if len(signerKeys) > 0 { - compiledKeys = signerKeys - } else { - for _, signer := range signers { - compiledKeys = append(compiledKeys, SignInput{ - VerificationMethodId: signer, - Key: mainKeys[signer].Private, - }) - } - } + It("Valid: Key rotation works", func() { + // Create did + did := setup.CreateSimpleDid() - did, err := setup.SendUpdateDid(msg, compiledKeys) - - if valid { - Expect(err).To(BeNil()) - Expect(msg.Id).To(Equal(did.Id)) - Expect(msg.Controller).To(Equal(did.Controller)) - Expect(msg.VerificationMethod).To(Equal(did.VerificationMethod)) - Expect(msg.Authentication).To(Equal(did.Authentication)) - Expect(msg.AssertionMethod).To(Equal(did.AssertionMethod)) - Expect(msg.CapabilityInvocation).To(Equal(did.CapabilityInvocation)) - Expect(msg.CapabilityDelegation).To(Equal(did.CapabilityDelegation)) - Expect(msg.KeyAgreement).To(Equal(did.KeyAgreement)) - Expect(msg.AlsoKnownAs).To(Equal(did.AlsoKnownAs)) - Expect(msg.Service).To(Equal(did.Service)) - Expect(msg.Context).To(Equal(did.Context)) - } else { - Expect(err).To(HaveOccurred()) - Expect(errMsg).To(Equal(err.Error())) - } - }) + // Update did + newKeyPair := GenerateKeyPair() - It("Valid: Key rotation works", func() { - valid = true - signerKeys = []SignInput{ - { - VerificationMethodId: AliceKey1, - Key: mainKeys[AliceKey1].Private, - }, - { - VerificationMethodId: AliceKey1, - Key: mainKeys[AliceKey2].Private, - }, - } - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, + msg := &types.MsgUpdateDidPayload{ + Id: did.Did, VerificationMethod: []*types.VerificationMethod{ { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - // TODO: Use multibase encoding - PublicKeyMultibase: "z" + base58.Encode(mainKeys[AliceKey2].Public), + Id: did.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: did.Did, + PublicKeyMultibase: MustEncodeBase58(newKeyPair.Public), }, }, + VersionId: did.VersionId, + } + + signatures := []SignInput{ + did.SignInput, // Old signature + { + VerificationMethodId: did.KeyId, // New signature + Key: newKeyPair.Private, + }, } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(did.Did) + Expect(err).To(BeNil()) + Expect(msg.ToDid()).To(Equal(*created.Did)) }) - It("Not Valid: replacing controller and Verification method ID does not work without new sign", func() { - valid = false - signers = []string{AliceKey2, BobKey1, AliceKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{CharlieDID}, + It("Not Valid: Did doc update does not work without DID doc controllers signature", func() { + // Setup + alice := setup.CreateSimpleDid() + bob := setup.CreateDidWithExternalConterllers([]string{alice.Did}, []SignInput{alice.SignInput}) + + // Update did + msg := &types.MsgUpdateDidPayload{ + Id: bob.Did, + Controller: []string{alice.Did}, VerificationMethod: []*types.VerificationMethod{ { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, + Id: bob.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bob.Did, + PublicKeyMultibase: MustEncodeBase58(bob.KeyPair.Public), }, }, + Authentication: []string{bob.KeyId}, + AssertionMethod: []string{bob.KeyId}, + VersionId: bob.VersionId, } - errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", CharlieDID) + + signatures := []SignInput{} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", alice.Did))) }) - It("Valid: replacing controller and Verification method ID works with all signatures", func() { - valid = true - signers = []string{AliceKey1, CharlieKey1, AliceKey2} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{CharlieDID}, + It("Valid: Did doc update does not works with DID doc controllers signature", func() { + // Setup + alice := setup.CreateSimpleDid() + bob := setup.CreateDidWithExternalConterllers([]string{alice.Did}, []SignInput{alice.SignInput}) + + // Update did + msg := &types.MsgUpdateDidPayload{ + Id: bob.Did, + Controller: []string{alice.Did}, VerificationMethod: []*types.VerificationMethod{ { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, + Id: bob.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bob.Did, + PublicKeyMultibase: MustEncodeBase58(bob.KeyPair.Public), }, }, + Authentication: []string{bob.KeyId}, + AssertionMethod: []string{bob.KeyId}, + VersionId: bob.VersionId, } - errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", CharlieDID) + + signatures := []SignInput{alice.SignInput} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(bob.Did) + Expect(err).To(BeNil()) + Expect(msg.ToDid()).To(Equal(*created.Did)) }) // Verification method's tests // cases: // - replacing VM controller works // - replacing VM controller does not work without new signature - // - replacing VM controller does not work without old signature ?????? + // - replacing VM controller does not work without old signature // - replacing VM doesn't work without new signature // - replacing VM doesn't work without old signature // - replacing VM works with all signatures @@ -159,331 +126,484 @@ var _ = Describe("Update DID tests", func() { // --- adding new VM without new signature // --- adding new VM without old signature - It("Valid: Replacing VM controller works with one signature", func() { - valid = true - signers = []string{AliceKey1, BobKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - }, - } - }) + It("Valid: Replacing VM controller works with two signatures", func() { + // Setup + alice := setup.CreateSimpleDid() + bob := setup.CreateSimpleDid() - It("Not Valid: Replacing VM controller does not work without new signature", func() { - valid = false - signers = []string{AliceKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, + // Update did + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, VerificationMethod: []*types.VerificationMethod{ { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bob.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), }, }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, } - errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) - }) - It("Not Valid: Replacing VM does not work without new signature", func() { - valid = false - signers = []string{AliceKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", AliceDID) - }) - It("Not Valid: Replacing VM does not work without old signature", func() { - valid = false - signers = []string{AliceKey2} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) - }) - - It("Not Valid: Replacing VM works with all signatures", func() { - valid = true - signers = []string{AliceKey1, AliceKey2} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - }) + signatures := []SignInput{alice.SignInput, bob.SignInput} - // Adding VM + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) - It("Valid: Adding another verification method", func() { - valid = true - signers = []string{AliceKey1, BobKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - }, - } + // check + updated, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*updated.Did).To(Equal(msg.ToDid())) }) - It("Not Valid: Adding another verification method without new sign", func() { - valid = false - signers = []string{AliceKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) - }) - - It("Not Valid: Adding another verification method without old sign", func() { - valid = false - signers = []string{AliceKey2} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) - }) - - // Controller's tests - // cases: - // - replacing Controller works with all signatures - // - replacing Controller doesn't work without old signature - // - replacing Controller doesn't work without new signature - // --- adding Controller works with all signatures - // --- adding Controller doesn't work without old signature - // --- adding Controller doesn't work without new signature - - It("Valid: Replace controller works with all signatures", func() { - valid = true - signers = []string{BobKey1, AliceKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - }) + It("Not Valid: Replacing VM controller does not work without new signature", func() { + // Setup + alice := setup.CreateSimpleDid() + bob := setup.CreateSimpleDid() - It("Not Valid: Replace controller doesn't work without old signatures", func() { - valid = false - signers = []string{BobKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{BobDID}, + // Update did + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, VerificationMethod: []*types.VerificationMethod{ { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bob.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), }, }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, } - errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) - }) - It("Not Valid: Replace controller doesn't work without new signatures", func() { - valid = false - signers = []string{AliceKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) - }) - - // add controller - - It("Valid: Adding second controller works", func() { - valid = true - signers = []string{AliceKey1, CharlieKey3} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID, CharlieDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - }) + signatures := []SignInput{alice.SignInput} - It("Not Valid: Adding controller without old signature", func() { - valid = false - signers = []string{BobKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID, BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", bob.Did))) }) - It("Not Valid: Add controller without new signature doesn't work", func() { - valid = false - signers = []string{AliceKey1} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID, BobDID}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) - }) + It("Not Valid: Replacing VM does not work without new signature", func() { + // Setup + alice := setup.CreateSimpleDid() + bob := setup.CreateSimpleDid() - It("Valid: Adding verification method with the same controller works", func() { - valid = true - signers = []string{AliceKey1, AliceKey2} - msg = &types.MsgUpdateDidPayload{ - Id: AliceDID, - Controller: []string{AliceDID}, + // Update did + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, VerificationMethod: []*types.VerificationMethod{ { - Id: AliceKey2, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bob.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), }, }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, } - }) - It("Valid: Keeping VM with controller different then subject untouched during update should not require Bob signature", func() { - valid = true - signers = []string{CharlieKey1} - msg = &types.MsgUpdateDidPayload{ - Id: CharlieDID, - Authentication: []string{ - CharlieKey1, - CharlieKey2, - CharlieKey3, - }, + signatures := []SignInput{bob.SignInput} - VerificationMethod: []*types.VerificationMethod{ - { - Id: CharlieKey1, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey2, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey3, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey4, - Type: types.Ed25519VerificationKey2020, - Controller: CharlieDID, - }, - }, - } + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", alice.Did))) }) - It("Valid: Removing verification method is possible with any kind of valid Bob's key", func() { - valid = true - signers = []string{BobKey1} - msg = &types.MsgUpdateDidPayload{ - Id: BobDID, - VerificationMethod: []*types.VerificationMethod{ - { - Id: BobKey1, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - }, - } - errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", BobDID) - }) + // It("Not Valid: Replacing VM does not work without old signature", func() { + // valid = false + // signers = []string{AliceKey2} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey2, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) + // }) + + // It("Not Valid: Replacing VM works with all signatures", func() { + // valid = true + // signers = []string{AliceKey1, AliceKey2} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey2, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // }) + + // // Adding VM + + // It("Valid: Adding another verification method", func() { + // valid = true + // signers = []string{AliceKey1, BobKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{AliceDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // { + // Id: AliceKey2, + // Type: types.Ed25519VerificationKey2020, + // Controller: BobDID, + // }, + // }, + // } + // }) + + // It("Not Valid: Adding another verification method without new sign", func() { + // valid = false + // signers = []string{AliceKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{AliceDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // { + // Id: AliceKey2, + // Type: types.Ed25519VerificationKey2020, + // Controller: BobDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) + // }) + + // It("Not Valid: Adding another verification method without old sign", func() { + // valid = false + // signers = []string{AliceKey2} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{AliceDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // { + // Id: AliceKey2, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) + // }) + + // // Controller's tests + // // cases: + // // - replacing Controller works with all signatures + // // - replacing Controller doesn't work without old signature + // // - replacing Controller doesn't work without new signature + // // --- adding Controller works with all signatures + // // --- adding Controller doesn't work without old signature + // // --- adding Controller doesn't work without new signature + + // It("Valid: Replace controller works with all signatures", func() { + // valid = true + // signers = []string{BobKey1, AliceKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{BobDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // }) + + // It("Not Valid: Replace controller doesn't work without old signatures", func() { + // valid = false + // signers = []string{BobKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{BobDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) + // }) + + // It("Not Valid: Replace controller doesn't work without new signatures", func() { + // valid = false + // signers = []string{AliceKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{BobDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) + // }) + + // // add controller + + // It("Valid: Adding second controller works", func() { + // valid = true + // signers = []string{AliceKey1, CharlieKey3} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{AliceDID, CharlieDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // }) + + // It("Not Valid: Adding controller without old signature", func() { + // valid = false + // signers = []string{BobKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{AliceDID, BobDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) + // }) + + // It("Not Valid: Add controller without new signature doesn't work", func() { + // valid = false + // signers = []string{AliceKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{AliceDID, BobDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) + // }) + + // It("Valid: Adding verification method with the same controller works", func() { + // valid = true + // signers = []string{AliceKey1, AliceKey2} + // msg = &types.MsgUpdateDidPayload{ + // Id: AliceDID, + // Controller: []string{AliceDID}, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: AliceKey2, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // { + // Id: AliceKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: AliceDID, + // }, + // }, + // } + // }) + + // It("Valid: Keeping VM with controller different then subject untouched during update should not require Bob signature", func() { + // valid = true + // signers = []string{CharlieKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: CharlieDID, + // Authentication: []string{ + // CharlieKey1, + // CharlieKey2, + // CharlieKey3, + // }, + + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: CharlieKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: BobDID, + // }, + // { + // Id: CharlieKey2, + // Type: types.Ed25519VerificationKey2020, + // Controller: BobDID, + // }, + // { + // Id: CharlieKey3, + // Type: types.Ed25519VerificationKey2020, + // Controller: BobDID, + // }, + // { + // Id: CharlieKey4, + // Type: types.Ed25519VerificationKey2020, + // Controller: CharlieDID, + // }, + // }, + // } + // }) + + // It("Valid: Removing verification method is possible with any kind of valid Bob's key", func() { + // valid = true + // signers = []string{BobKey1} + // msg = &types.MsgUpdateDidPayload{ + // Id: BobDID, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: BobKey1, + // Type: types.Ed25519VerificationKey2020, + // Controller: BobDID, + // }, + // }, + // } + // errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", BobDID) + // }) }) + +// var _ = Describe("Signature Verification while updating DID", func() { +// var setup TestSetup +// var aliceKeys, bobKeys map[string]ed25519.PrivateKey +// var aliceDid *types.MsgCreateDidPayload +// BeforeEach(func() { +// setup = Setup() +// aliceKeys, aliceDid, _ = setup.InitDid(AliceDID) +// bobKeys, _, _ = setup.InitDid(BobDID) +// }) + +// It("should have changed DIDDoc controller", func() { +// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) +// updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) +// receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) + +// Expect(aliceDid.Controller).To(Not(Equal(receivedDid.Controller))) +// Expect([]string{AliceDID, BobDID}).To(Not(Equal(receivedDid.Controller))) +// Expect([]string{BobDID}, receivedDid.Controller) +// }) + +// When("Old signature in verification method is absent", func() { +// It("should fail", func() { +// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) +// updatedDidDoc.VerificationMethod[0].Type = types.Ed25519VerificationKey2020 +// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + +// // check +// Expect(err).To(Not(BeNil())) +// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) +// }) +// }) + +// It("should fails cause we need old signature for changing verification method controller", func() { +// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) +// updatedDidDoc.VerificationMethod[0].Controller = BobDID +// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + +// // check +// Expect(err).To(Not(BeNil())) +// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) +// }) + +// It("should fails cause we need old signature for changing DIDDoc controller", func() { +// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) +// updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) +// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + +// // check +// Expect(err).To(Not(BeNil())) +// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) +// }) +// }) + +// var _ = Describe("Signature Verification. Remove signature/VM", func() { +// var setup TestSetup +// var ApubKey, BpubKey ed25519.PublicKey +// var AprivKey, BprivKey ed25519.PrivateKey +// var aliceDid, bobDid *types.MsgCreateDidPayload +// var aliceKeys, bobKeys map[string]ed25519.PrivateKey + +// BeforeEach(func() { +// setup = Setup() +// // Generate keys +// ApubKey, AprivKey, _ = ed25519.GenerateKey(rand.Reader) +// BpubKey, BprivKey, _ = ed25519.GenerateKey(rand.Reader) + +// // Create dids +// aliceDid = setup.BuildSimpleCreateDidPayload(AliceDID, AliceKey1, ApubKey) +// bobDid = setup.BuildSimpleCreateDidPayload(BobDID, BobKey1, BpubKey) + +// // Collect private keys +// aliceKeys = map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} +// bobKeys = map[string]ed25519.PrivateKey{BobKey1: BprivKey} + +// // Add verification method +// aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ +// Id: AliceKey2, +// Controller: BobDID, +// Type: types.Ed25519VerificationKey2020, +// PublicKeyMultibase: MustEncodeBase58(BpubKey), +// }) +// }) + +// It("should fails cause old signature is required for removing this signature", func() { +// // Send dids +// _, _ = setup.SendCreateDid(bobDid, bobKeys) +// _, _ = setup.SendCreateDid(aliceDid, aliceKeys) + +// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) +// updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} +// updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} +// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) + +// // check +// Expect(err).To(Not(BeNil())) +// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) +// }) + +// It("should not fails while removing the whole verification method", func() { +// aliceDid.Authentication = append(aliceDid.Authentication, AliceKey2) + +// // Send dids +// _, _ = setup.SendCreateDid(bobDid, bobKeys) +// _, _ = setup.SendCreateDid(aliceDid, aliceKeys) + +// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) +// updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} +// updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} +// receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) + +// // check +// Expect(len(aliceDid.VerificationMethod)).To(Not(Equal(len(receivedDid.VerificationMethod)))) +// Expect(reflect.DeepEqual(aliceDid.VerificationMethod[0], receivedDid.VerificationMethod[0])).To(BeTrue()) +// }) +// }) diff --git a/x/cheqd/types/did_did.go b/x/cheqd/types/did_did.go index d0c8238e6..2e5d1ce41 100644 --- a/x/cheqd/types/did_did.go +++ b/x/cheqd/types/did_did.go @@ -47,18 +47,7 @@ func (did *Did) ReplaceIds(old, new string) { } for _, vm := range did.VerificationMethod { - // Controller - if vm.Controller == old { - vm.Controller = new - } - - // Id - did, path, query, fragment := utils.MustSplitDIDUrl(vm.Id) - if did == old { - did = new - } - - vm.Id = utils.JoinDIDUrl(did, path, query, fragment) + vm.ReplaceIds(old, new) } } diff --git a/x/cheqd/types/did_verification_method.go b/x/cheqd/types/did_verification_method.go index 93114a620..f67414271 100644 --- a/x/cheqd/types/did_verification_method.go +++ b/x/cheqd/types/did_verification_method.go @@ -6,7 +6,6 @@ import ( "crypto/rsa" "errors" "fmt" - "reflect" "github.com/cheqd/cheqd-node/x/cheqd/utils" validation "github.com/go-ozzo/ozzo-validation/v4" @@ -121,11 +120,20 @@ func VerificationMethodListToMapByFragment(vms []*VerificationMethod) map[string return result } -func CompareVerificationMethodsWithoutIds(vm1, vm2 VerificationMethod) bool { - // We can override ids because on local copies - vm1.Id = "" - vm2.Id = "" - return reflect.DeepEqual(vm1, vm2) +// ReplaceIds replaces ids in all fields +func (vm *VerificationMethod) ReplaceIds(old, new string) { + // Controller + if vm.Controller == old { + vm.Controller = new + } + + // Id + did, path, query, fragment := utils.MustSplitDIDUrl(vm.Id) + if did == old { + did = new + } + + vm.Id = utils.JoinDIDUrl(did, path, query, fragment) } // Validation diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index 692fefe81..dc01850fa 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -20,7 +20,7 @@ var _ = Describe("CreateResource", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) + didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err = setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) resourcePayload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_all_resource_versions_test.go b/x/resource/tests/query_all_resource_versions_test.go index 750a6938b..e27f534c8 100644 --- a/x/resource/tests/query_all_resource_versions_test.go +++ b/x/resource/tests/query_all_resource_versions_test.go @@ -16,7 +16,7 @@ var _ = Describe("QueryAllResourceVersions", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) + didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_collection_resources_test.go b/x/resource/tests/query_collection_resources_test.go index 18036de72..4c8b19b2f 100644 --- a/x/resource/tests/query_collection_resources_test.go +++ b/x/resource/tests/query_collection_resources_test.go @@ -16,7 +16,7 @@ var _ = Describe("QueryCollectionResources", func() { keys := GenerateTestKeys() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) + didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) diff --git a/x/resource/tests/query_resource_test.go b/x/resource/tests/query_resource_test.go index 0d87dd13a..1c3d57f15 100644 --- a/x/resource/tests/query_resource_test.go +++ b/x/resource/tests/query_resource_test.go @@ -17,7 +17,7 @@ var _ = Describe("QueryGetResource", func() { existingResource := ExistingResource() BeforeEach(func() { setup = Setup() - didDoc := setup.BuildMsgCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) + didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) Expect(err).To(BeNil()) payload := GenerateCreateResourcePayload(ExistingResource()) From 3ac56e73f2237243fc1801d117a6d994941ee0c6 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Wed, 12 Oct 2022 13:13:26 +0500 Subject: [PATCH 32/76] WIP --- x/cheqd/tests/const.go | 3 - x/cheqd/tests/update_did_test.go | 307 +++++++++++++++++++++---------- 2 files changed, 214 insertions(+), 96 deletions(-) delete mode 100644 x/cheqd/tests/const.go diff --git a/x/cheqd/tests/const.go b/x/cheqd/tests/const.go deleted file mode 100644 index 2b33e2506..000000000 --- a/x/cheqd/tests/const.go +++ /dev/null @@ -1,3 +0,0 @@ -package tests - -// const Ed25519VerificationKey2020 = "Ed25519VerificationKey2020" diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index 158ee6605..4d9fdd49d 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -169,7 +169,7 @@ var _ = Describe("Update DID tests", func() { { Id: alice.KeyId, Type: types.Ed25519VerificationKey2020, - Controller: bob.Did, + Controller: bob.Did, // Previously alice PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), }, }, @@ -183,7 +183,7 @@ var _ = Describe("Update DID tests", func() { Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", bob.Did))) }) - It("Not Valid: Replacing VM does not work without new signature", func() { + It("Not Valid: Replacing VM controller does not work without old signature", func() { // Setup alice := setup.CreateSimpleDid() bob := setup.CreateSimpleDid() @@ -209,103 +209,224 @@ var _ = Describe("Update DID tests", func() { Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", alice.Did))) }) - // It("Not Valid: Replacing VM does not work without old signature", func() { - // valid = false - // signers = []string{AliceKey2} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey2, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) - // }) + It("Not Valid: Replacing VM does not work without new signature", func() { + // Setup + alice := setup.CreateSimpleDid() - // It("Not Valid: Replacing VM works with all signatures", func() { - // valid = true - // signers = []string{AliceKey1, AliceKey2} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey2, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // }) + // Update did + newKeyId := alice.Did + "#key-2" + + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + + signatures := []SignInput{alice.SignInput} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", alice.Did))) + }) + + It("Not Valid: Replacing VM does not work without old signature", func() { + // Setup + alice := setup.CreateSimpleDid() + + // Update did + newKeyId := alice.Did + "#key-2" + + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + + signatures := []SignInput{ + { + VerificationMethodId: newKeyId, + Key: alice.KeyPair.Private, + }, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", alice.Did))) + }) + + It("Not Valid: Replacing VM works with all signatures", func() { + // Setup + alice := setup.CreateSimpleDid() + + // Update did + newKeyId := alice.Did + "#key-2" + + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + + signatures := []SignInput{ + alice.SignInput, + { + VerificationMethodId: newKeyId, + Key: alice.KeyPair.Private, + }, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*created).ToNot(Equal(msg.ToDid())) + }) // // Adding VM - // It("Valid: Adding another verification method", func() { - // valid = true - // signers = []string{AliceKey1, BobKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{AliceDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // { - // Id: AliceKey2, - // Type: types.Ed25519VerificationKey2020, - // Controller: BobDID, - // }, - // }, - // } - // }) + It("Valid: Adding another verification method", func() { + // Setup + alice := setup.CreateSimpleDid() - // It("Not Valid: Adding another verification method without new sign", func() { - // valid = false - // signers = []string{AliceKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{AliceDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // { - // Id: AliceKey2, - // Type: types.Ed25519VerificationKey2020, - // Controller: BobDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) - // }) + // Update did + newKeyId := alice.Did + "#key-2" + newKey := GenerateKeyPair() - // It("Not Valid: Adding another verification method without old sign", func() { - // valid = false - // signers = []string{AliceKey2} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{AliceDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // { - // Id: AliceKey2, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID) - // }) + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(newKey.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + + signatures := []SignInput{ + alice.SignInput, + { + VerificationMethodId: newKeyId, + Key: newKey.Private, + }, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*created).ToNot(Equal(msg.ToDid())) + }) + + It("Not Valid: Adding another verification method without new sign", func() { + // Setup + alice := setup.CreateSimpleDid() + + // Update did + newKeyId := alice.Did + "#key-2" + newKey := GenerateKeyPair() + + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(newKey.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + + signatures := []SignInput{ + alice.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID))) + }) + + It("Not Valid: Adding another verification method without old sign", func() { + // Setup + alice := setup.CreateSimpleDid() + + // Update did + newKeyId := alice.Did + "#key-2" + newKey := GenerateKeyPair() + + msg := &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(newKey.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + + signatures := []SignInput{ + { + VerificationMethodId: newKeyId, + Key: newKey.Private, + }, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID))) + }) // // Controller's tests // // cases: From e57999b354c249fd012703f417cf1c84cb9e8350 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Thu, 13 Oct 2022 15:08:27 +0500 Subject: [PATCH 33/76] Implementation --- x/cheqd/tests/update_did_test.go | 211 +++++++++++++++++-------------- 1 file changed, 116 insertions(+), 95 deletions(-) diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index 4d9fdd49d..49a604474 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -9,48 +9,69 @@ import ( "github.com/cheqd/cheqd-node/x/cheqd/types" ) -var _ = Describe("Update DID tests", func() { +var _ = Describe("DID Doc update", func() { var setup TestSetup BeforeEach(func() { setup = Setup() }) - It("Valid: Key rotation works", func() { - // Create did - did := setup.CreateSimpleDid() - - // Update did - newKeyPair := GenerateKeyPair() + Describe("Key rotation", func() { + var did CreatedDidInfo + var newKeyPair KeyPair + var msg *types.MsgUpdateDidPayload + + BeforeEach(func() { + did = setup.CreateSimpleDid() + newKeyPair = GenerateKeyPair() + msg = &types.MsgUpdateDidPayload{ + Id: did.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: did.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: did.Did, + PublicKeyMultibase: MustEncodeBase58(newKeyPair.Public), + }, + }, + VersionId: did.VersionId, + } + }) - msg := &types.MsgUpdateDidPayload{ - Id: did.Did, - VerificationMethod: []*types.VerificationMethod{ + It("Works with two signatures", func() { + signatures := []SignInput{ + did.SignInput, // Old signature { - Id: did.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: did.Did, - PublicKeyMultibase: MustEncodeBase58(newKeyPair.Public), + VerificationMethodId: did.KeyId, // New signature + Key: newKeyPair.Private, }, - }, - VersionId: did.VersionId, - } + } - signatures := []SignInput{ - did.SignInput, // Old signature - { - VerificationMethodId: did.KeyId, // New signature - Key: newKeyPair.Private, - }, - } + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) - _, err := setup.UpdateDid(msg, signatures) - Expect(err).To(BeNil()) + // check + created, err := setup.QueryDid(did.Did) + Expect(err).To(BeNil()) + Expect(msg.ToDid()).To(Equal(*created.Did)) + }) - // check - created, err := setup.QueryDid(did.Did) - Expect(err).To(BeNil()) - Expect(msg.ToDid()).To(Equal(*created.Did)) + It("Doesn't work without new signature", func() { + signatures := []SignInput{did.SignInput} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", did.Did))) + }) + + It("Doesn't work without old signature", func() { + signatures := []SignInput{{ + VerificationMethodId: did.KeyId, + Key: newKeyPair.Private, + }} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", did.Did))) + }) }) It("Not Valid: Did doc update does not work without DID doc controllers signature", func() { @@ -353,80 +374,80 @@ var _ = Describe("Update DID tests", func() { Expect(*created).ToNot(Equal(msg.ToDid())) }) - It("Not Valid: Adding another verification method without new sign", func() { - // Setup - alice := setup.CreateSimpleDid() + // It("Not Valid: Adding another verification method without new sign", func() { + // // Setup + // alice := setup.CreateSimpleDid() - // Update did - newKeyId := alice.Did + "#key-2" - newKey := GenerateKeyPair() + // // Update did + // newKeyId := alice.Did + "#key-2" + // newKey := GenerateKeyPair() - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: alice.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), - }, - { - Id: newKeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(newKey.Public), - }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } + // msg := &types.MsgUpdateDidPayload{ + // Id: alice.Did, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: alice.KeyId, + // Type: types.Ed25519VerificationKey2020, + // Controller: alice.Did, + // PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + // }, + // { + // Id: newKeyId, + // Type: types.Ed25519VerificationKey2020, + // Controller: alice.Did, + // PublicKeyMultibase: MustEncodeBase58(newKey.Public), + // }, + // }, + // Authentication: []string{alice.KeyId}, + // VersionId: alice.VersionId, + // } - signatures := []SignInput{ - alice.SignInput, - } + // signatures := []SignInput{ + // alice.SignInput, + // } - _, err := setup.UpdateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID))) - }) + // _, err := setup.UpdateDid(msg, signatures) + // Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID))) + // }) - It("Not Valid: Adding another verification method without old sign", func() { - // Setup - alice := setup.CreateSimpleDid() + // It("Not Valid: Adding another verification method without old sign", func() { + // // Setup + // alice := setup.CreateSimpleDid() - // Update did - newKeyId := alice.Did + "#key-2" - newKey := GenerateKeyPair() + // // Update did + // newKeyId := alice.Did + "#key-2" + // newKey := GenerateKeyPair() - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: alice.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), - }, - { - Id: newKeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(newKey.Public), - }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } + // msg := &types.MsgUpdateDidPayload{ + // Id: alice.Did, + // VerificationMethod: []*types.VerificationMethod{ + // { + // Id: alice.KeyId, + // Type: types.Ed25519VerificationKey2020, + // Controller: alice.Did, + // PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + // }, + // { + // Id: newKeyId, + // Type: types.Ed25519VerificationKey2020, + // Controller: alice.Did, + // PublicKeyMultibase: MustEncodeBase58(newKey.Public), + // }, + // }, + // Authentication: []string{alice.KeyId}, + // VersionId: alice.VersionId, + // } - signatures := []SignInput{ - { - VerificationMethodId: newKeyId, - Key: newKey.Private, - }, - } + // signatures := []SignInput{ + // { + // VerificationMethodId: newKeyId, + // Key: newKey.Private, + // }, + // } - _, err := setup.UpdateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID))) - }) + // _, err := setup.UpdateDid(msg, signatures) + // Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID))) + // }) // // Controller's tests // // cases: From 9f3fc8f2326441e26c6209f97e6511b3565c7ebb Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Fri, 14 Oct 2022 17:45:26 +0500 Subject: [PATCH 34/76] Finish cheqd module tests --- x/cheqd/tests/update_did_test.go | 1038 ++++++++++++------------------ 1 file changed, 408 insertions(+), 630 deletions(-) diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index 49a604474..238fff23d 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -16,7 +16,210 @@ var _ = Describe("DID Doc update", func() { setup = Setup() }) - Describe("Key rotation", func() { + Describe("DIDDoc: update verification relationship", func() { + var alice CreatedDidInfo + var bob CreatedDidInfo + var msg *types.MsgUpdateDidPayload + + BeforeEach(func() { + alice = setup.CreateSimpleDid() + bob = setup.CreateDidWithExternalConterllers([]string{alice.Did}, []SignInput{alice.SignInput}) + + msg = &types.MsgUpdateDidPayload{ + Id: bob.Did, + Controller: []string{alice.Did}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: bob.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bob.Did, + PublicKeyMultibase: MustEncodeBase58(bob.KeyPair.Public), + }, + }, + Authentication: []string{bob.KeyId}, + AssertionMethod: []string{bob.KeyId}, + VersionId: bob.VersionId, + } + }) + + It("Works with DID doc controllers signature", func() { + signatures := []SignInput{alice.SignInput} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(bob.Did) + Expect(err).To(BeNil()) + Expect(msg.ToDid()).To(Equal(*created.Did)) + }) + + It("Doesn't work without controllers signatures", func() { + signatures := []SignInput{} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", alice.Did))) + }) + }) + + Describe("DIDDoc: replacing controller", func() { + var alice CreatedDidInfo + var bob CreatedDidInfo + var msg *types.MsgUpdateDidPayload + + BeforeEach(func() { + alice = setup.CreateSimpleDid() + bob = setup.CreateSimpleDid() + + msg = &types.MsgUpdateDidPayload{ + Id: alice.Did, + Controller: []string{bob.Did}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + VersionId: alice.VersionId, + } + }) + + It("Works with old and new signatures", func() { + signatures := []SignInput{ + alice.SignInput, + bob.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + updated, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*updated.Did).To(Equal(msg.ToDid())) + }) + + It("Doesn't work with only new controller signature", func() { + signatures := []SignInput{ + bob.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", alice.Did))) + }) + + It("Doesn't work with only old controller signature", func() { + signatures := []SignInput{ + alice.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", bob.Did))) + }) + }) + + Describe("DIDDoc: adding controller", func() { + var alice CreatedDidInfo + var bob CreatedDidInfo + var msg *types.MsgUpdateDidPayload + + BeforeEach(func() { + alice = setup.CreateSimpleDid() + bob = setup.CreateSimpleDid() + + msg = &types.MsgUpdateDidPayload{ + Id: alice.Did, + Controller: []string{alice.Did, bob.Did}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + VersionId: alice.VersionId, + } + }) + + It("Works with old and new signatures", func() { + signatures := []SignInput{ + alice.SignInput, + bob.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + updated, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*updated.Did).To(Equal(msg.ToDid())) + }) + + It("Doesn't work with only new controller signatures", func() { + signatures := []SignInput{ + bob.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", alice.Did))) + }) + + It("Doesn't work with only old controller signatures", func() { + signatures := []SignInput{ + alice.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", bob.Did))) + }) + }) + + Describe("DIDDoc: Keeping VM with controller different then subject untouched during update", func() { + var alice CreatedDidInfo + var bob CreatedDidInfo + var msg *types.MsgUpdateDidPayload + + BeforeEach(func() { + bob = setup.CreateSimpleDid() + alice = setup.CreateDidWithExternalConterllers([]string{bob.Did}, []SignInput{bob.SignInput}) + + msg = &types.MsgUpdateDidPayload{ + Id: alice.Did, + Controller: []string{bob.Did}, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + Authentication: []string{alice.KeyId}, + AssertionMethod: []string{alice.KeyId}, // Adding new VM + VersionId: alice.VersionId, + } + }) + + It("Doesn't require VM's controler signature", func() { + signatures := []SignInput{ + bob.SignInput, + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*created).ToNot(Equal(msg.ToDid())) + }) + }) + + Describe("Verification method: key udpate", func() { var did CreatedDidInfo var newKeyPair KeyPair var msg *types.MsgUpdateDidPayload @@ -74,678 +277,253 @@ var _ = Describe("DID Doc update", func() { }) }) - It("Not Valid: Did doc update does not work without DID doc controllers signature", func() { - // Setup - alice := setup.CreateSimpleDid() - bob := setup.CreateDidWithExternalConterllers([]string{alice.Did}, []SignInput{alice.SignInput}) + Describe("Verification method: controller update", func() { + var alice CreatedDidInfo + var bob CreatedDidInfo + var msg *types.MsgUpdateDidPayload - // Update did - msg := &types.MsgUpdateDidPayload{ - Id: bob.Did, - Controller: []string{alice.Did}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: bob.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: bob.Did, - PublicKeyMultibase: MustEncodeBase58(bob.KeyPair.Public), + BeforeEach(func() { + alice = setup.CreateSimpleDid() + bob = setup.CreateSimpleDid() + + msg = &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: bob.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, }, - }, - Authentication: []string{bob.KeyId}, - AssertionMethod: []string{bob.KeyId}, - VersionId: bob.VersionId, - } + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + }) - signatures := []SignInput{} + It("Works with old and new controller signature", func() { + signatures := []SignInput{alice.SignInput, bob.SignInput} - _, err := setup.UpdateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", alice.Did))) - }) + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) - It("Valid: Did doc update does not works with DID doc controllers signature", func() { - // Setup - alice := setup.CreateSimpleDid() - bob := setup.CreateDidWithExternalConterllers([]string{alice.Did}, []SignInput{alice.SignInput}) + // check + updated, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*updated.Did).To(Equal(msg.ToDid())) + }) - // Update did - msg := &types.MsgUpdateDidPayload{ - Id: bob.Did, - Controller: []string{alice.Did}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: bob.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: bob.Did, - PublicKeyMultibase: MustEncodeBase58(bob.KeyPair.Public), - }, - }, - Authentication: []string{bob.KeyId}, - AssertionMethod: []string{bob.KeyId}, - VersionId: bob.VersionId, - } + It("Doesn't work without old controller signature", func() { + signatures := []SignInput{bob.SignInput} - signatures := []SignInput{alice.SignInput} + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", alice.Did))) + }) - _, err := setup.UpdateDid(msg, signatures) - Expect(err).To(BeNil()) + It("Doesn't work without new controller signature", func() { + signatures := []SignInput{alice.SignInput} - // check - created, err := setup.QueryDid(bob.Did) - Expect(err).To(BeNil()) - Expect(msg.ToDid()).To(Equal(*created.Did)) + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", bob.Did))) + }) }) - // Verification method's tests - // cases: - // - replacing VM controller works - // - replacing VM controller does not work without new signature - // - replacing VM controller does not work without old signature - // - replacing VM doesn't work without new signature - // - replacing VM doesn't work without old signature - // - replacing VM works with all signatures - // --- adding new VM works - // --- adding new VM without new signature - // --- adding new VM without old signature - - It("Valid: Replacing VM controller works with two signatures", func() { - // Setup - alice := setup.CreateSimpleDid() - bob := setup.CreateSimpleDid() - - // Update did - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: alice.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: bob.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), - }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } + Describe("Verification method: id update", func() { + var alice CreatedDidInfo + var newKeyId string + var msg *types.MsgUpdateDidPayload - signatures := []SignInput{alice.SignInput, bob.SignInput} + BeforeEach(func() { + alice = setup.CreateSimpleDid() + newKeyId = alice.Did + "#key-2" - _, err := setup.UpdateDid(msg, signatures) - Expect(err).To(BeNil()) + msg = &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + }) - // check - updated, err := setup.QueryDid(alice.Did) - Expect(err).To(BeNil()) - Expect(*updated.Did).To(Equal(msg.ToDid())) - }) + It("Doesn't work without new VM signature", func() { + signatures := []SignInput{alice.SignInput} - It("Not Valid: Replacing VM controller does not work without new signature", func() { - // Setup - alice := setup.CreateSimpleDid() - bob := setup.CreateSimpleDid() + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", alice.Did))) + }) - // Update did - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ + It("Doesn't work without old VM signature", func() { + signatures := []SignInput{ { - Id: alice.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: bob.Did, // Previously alice - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + VerificationMethodId: newKeyId, + Key: alice.KeyPair.Private, }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } - - signatures := []SignInput{alice.SignInput} - - _, err := setup.UpdateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", bob.Did))) - }) + } - It("Not Valid: Replacing VM controller does not work without old signature", func() { - // Setup - alice := setup.CreateSimpleDid() - bob := setup.CreateSimpleDid() + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", alice.Did))) + }) - // Update did - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ + It("Works with new and old VM signature", func() { + signatures := []SignInput{ { - Id: alice.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: bob.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + VerificationMethodId: newKeyId, + Key: alice.KeyPair.Private, }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } + alice.SignInput, + } - signatures := []SignInput{bob.SignInput} + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) - _, err := setup.UpdateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", alice.Did))) + // check + updated, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*updated.Did).To(Equal(msg.ToDid())) + }) }) - It("Not Valid: Replacing VM does not work without new signature", func() { - // Setup - alice := setup.CreateSimpleDid() + Describe("Verification method: adding a new one", func() { + var alice CreatedDidInfo + var newKeyId string + var newKey KeyPair + var msg *types.MsgUpdateDidPayload - // Update did - newKeyId := alice.Did + "#key-2" + BeforeEach(func() { + alice = setup.CreateSimpleDid() - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: newKeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), - }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } + newKeyId = alice.Did + "#key-2" + newKey = GenerateKeyPair() - signatures := []SignInput{alice.SignInput} + msg = &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + { + Id: newKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(newKey.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + }) - _, err := setup.UpdateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", alice.Did))) - }) + It("Works with only old VM signature", func() { + signatures := []SignInput{ + alice.SignInput, + } - It("Not Valid: Replacing VM does not work without old signature", func() { - // Setup - alice := setup.CreateSimpleDid() + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) - // Update did - newKeyId := alice.Did + "#key-2" + // check + created, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*created).ToNot(Equal(msg.ToDid())) + }) - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ + It("Doesn't work with only new VM signature", func() { + signatures := []SignInput{ { - Id: newKeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + VerificationMethodId: newKeyId, + Key: newKey.Private, }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } - - signatures := []SignInput{ - { - VerificationMethodId: newKeyId, - Key: alice.KeyPair.Private, - }, - } - - _, err := setup.UpdateDid(msg, signatures) - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", alice.Did))) + } + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", alice.Did))) + }) }) - It("Not Valid: Replacing VM works with all signatures", func() { - // Setup - alice := setup.CreateSimpleDid() + Describe("Verification method: removing existing one", func() { + var alice CreatedDidInfo + var secondKeyId string + var secondKey KeyPair + var secondSignInput SignInput + var msg *types.MsgUpdateDidPayload - // Update did - newKeyId := alice.Did + "#key-2" + BeforeEach(func() { + alice = setup.CreateSimpleDid() - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: newKeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + secondKeyId = alice.Did + "#key-2" + secondKey = GenerateKeyPair() + secondSignInput = SignInput{ + VerificationMethodId: secondKeyId, + Key: secondKey.Private, + } + + addSecondKeyMsg := &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + { + Id: secondKeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(secondKey.Public), + }, }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } - - signatures := []SignInput{ - alice.SignInput, - { - VerificationMethodId: newKeyId, - Key: alice.KeyPair.Private, - }, - } - - _, err := setup.UpdateDid(msg, signatures) - Expect(err).To(BeNil()) - - // check - created, err := setup.QueryDid(alice.Did) - Expect(err).To(BeNil()) - Expect(*created).ToNot(Equal(msg.ToDid())) - }) + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } - // // Adding VM + _, err := setup.UpdateDid(addSecondKeyMsg, []SignInput{alice.SignInput}) + Expect(err).To(BeNil()) - It("Valid: Adding another verification method", func() { - // Setup - alice := setup.CreateSimpleDid() + msg = &types.MsgUpdateDidPayload{ + Id: alice.Did, + VerificationMethod: []*types.VerificationMethod{ + { + Id: alice.KeyId, + Type: types.Ed25519VerificationKey2020, + Controller: alice.Did, + PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), + }, + }, + Authentication: []string{alice.KeyId}, + VersionId: alice.VersionId, + } + }) - // Update did - newKeyId := alice.Did + "#key-2" - newKey := GenerateKeyPair() + It("Works with only first VM signature", func() { + signatures := []SignInput{ + alice.SignInput, + } - msg := &types.MsgUpdateDidPayload{ - Id: alice.Did, - VerificationMethod: []*types.VerificationMethod{ - { - Id: alice.KeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), - }, - { - Id: newKeyId, - Type: types.Ed25519VerificationKey2020, - Controller: alice.Did, - PublicKeyMultibase: MustEncodeBase58(newKey.Public), - }, - }, - Authentication: []string{alice.KeyId}, - VersionId: alice.VersionId, - } - - signatures := []SignInput{ - alice.SignInput, - { - VerificationMethodId: newKeyId, - Key: newKey.Private, - }, - } - - _, err := setup.UpdateDid(msg, signatures) - Expect(err).To(BeNil()) - - // check - created, err := setup.QueryDid(alice.Did) - Expect(err).To(BeNil()) - Expect(*created).ToNot(Equal(msg.ToDid())) - }) + _, err := setup.UpdateDid(msg, signatures) + Expect(err).To(BeNil()) - // It("Not Valid: Adding another verification method without new sign", func() { - // // Setup - // alice := setup.CreateSimpleDid() - - // // Update did - // newKeyId := alice.Did + "#key-2" - // newKey := GenerateKeyPair() - - // msg := &types.MsgUpdateDidPayload{ - // Id: alice.Did, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: alice.KeyId, - // Type: types.Ed25519VerificationKey2020, - // Controller: alice.Did, - // PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), - // }, - // { - // Id: newKeyId, - // Type: types.Ed25519VerificationKey2020, - // Controller: alice.Did, - // PublicKeyMultibase: MustEncodeBase58(newKey.Public), - // }, - // }, - // Authentication: []string{alice.KeyId}, - // VersionId: alice.VersionId, - // } - - // signatures := []SignInput{ - // alice.SignInput, - // } - - // _, err := setup.UpdateDid(msg, signatures) - // Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID))) - // }) - - // It("Not Valid: Adding another verification method without old sign", func() { - // // Setup - // alice := setup.CreateSimpleDid() - - // // Update did - // newKeyId := alice.Did + "#key-2" - // newKey := GenerateKeyPair() - - // msg := &types.MsgUpdateDidPayload{ - // Id: alice.Did, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: alice.KeyId, - // Type: types.Ed25519VerificationKey2020, - // Controller: alice.Did, - // PublicKeyMultibase: MustEncodeBase58(alice.KeyPair.Public), - // }, - // { - // Id: newKeyId, - // Type: types.Ed25519VerificationKey2020, - // Controller: alice.Did, - // PublicKeyMultibase: MustEncodeBase58(newKey.Public), - // }, - // }, - // Authentication: []string{alice.KeyId}, - // VersionId: alice.VersionId, - // } - - // signatures := []SignInput{ - // { - // VerificationMethodId: newKeyId, - // Key: newKey.Private, - // }, - // } - - // _, err := setup.UpdateDid(msg, signatures) - // Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (old version): invalid signature detected", AliceDID))) - // }) - - // // Controller's tests - // // cases: - // // - replacing Controller works with all signatures - // // - replacing Controller doesn't work without old signature - // // - replacing Controller doesn't work without new signature - // // --- adding Controller works with all signatures - // // --- adding Controller doesn't work without old signature - // // --- adding Controller doesn't work without new signature - - // It("Valid: Replace controller works with all signatures", func() { - // valid = true - // signers = []string{BobKey1, AliceKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{BobDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // }) - - // It("Not Valid: Replace controller doesn't work without old signatures", func() { - // valid = false - // signers = []string{BobKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{BobDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) - // }) - - // It("Not Valid: Replace controller doesn't work without new signatures", func() { - // valid = false - // signers = []string{AliceKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{BobDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) - // }) - - // // add controller - - // It("Valid: Adding second controller works", func() { - // valid = true - // signers = []string{AliceKey1, CharlieKey3} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{AliceDID, CharlieDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // }) - - // It("Not Valid: Adding controller without old signature", func() { - // valid = false - // signers = []string{BobKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{AliceDID, BobDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID) - // }) - - // It("Not Valid: Add controller without new signature doesn't work", func() { - // valid = false - // signers = []string{AliceKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{AliceDID, BobDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one signature by %s: signature is required but not found", BobDID) - // }) - - // It("Valid: Adding verification method with the same controller works", func() { - // valid = true - // signers = []string{AliceKey1, AliceKey2} - // msg = &types.MsgUpdateDidPayload{ - // Id: AliceDID, - // Controller: []string{AliceDID}, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: AliceKey2, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // { - // Id: AliceKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: AliceDID, - // }, - // }, - // } - // }) - - // It("Valid: Keeping VM with controller different then subject untouched during update should not require Bob signature", func() { - // valid = true - // signers = []string{CharlieKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: CharlieDID, - // Authentication: []string{ - // CharlieKey1, - // CharlieKey2, - // CharlieKey3, - // }, - - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: CharlieKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: BobDID, - // }, - // { - // Id: CharlieKey2, - // Type: types.Ed25519VerificationKey2020, - // Controller: BobDID, - // }, - // { - // Id: CharlieKey3, - // Type: types.Ed25519VerificationKey2020, - // Controller: BobDID, - // }, - // { - // Id: CharlieKey4, - // Type: types.Ed25519VerificationKey2020, - // Controller: CharlieDID, - // }, - // }, - // } - // }) - - // It("Valid: Removing verification method is possible with any kind of valid Bob's key", func() { - // valid = true - // signers = []string{BobKey1} - // msg = &types.MsgUpdateDidPayload{ - // Id: BobDID, - // VerificationMethod: []*types.VerificationMethod{ - // { - // Id: BobKey1, - // Type: types.Ed25519VerificationKey2020, - // Controller: BobDID, - // }, - // }, - // } - // errMsg = fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", BobDID) - // }) -}) + // check + created, err := setup.QueryDid(alice.Did) + Expect(err).To(BeNil()) + Expect(*created).ToNot(Equal(msg.ToDid())) + }) -// var _ = Describe("Signature Verification while updating DID", func() { -// var setup TestSetup -// var aliceKeys, bobKeys map[string]ed25519.PrivateKey -// var aliceDid *types.MsgCreateDidPayload -// BeforeEach(func() { -// setup = Setup() -// aliceKeys, aliceDid, _ = setup.InitDid(AliceDID) -// bobKeys, _, _ = setup.InitDid(BobDID) -// }) - -// It("should have changed DIDDoc controller", func() { -// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) -// updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) -// receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - -// Expect(aliceDid.Controller).To(Not(Equal(receivedDid.Controller))) -// Expect([]string{AliceDID, BobDID}).To(Not(Equal(receivedDid.Controller))) -// Expect([]string{BobDID}, receivedDid.Controller) -// }) - -// When("Old signature in verification method is absent", func() { -// It("should fail", func() { -// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) -// updatedDidDoc.VerificationMethod[0].Type = types.Ed25519VerificationKey2020 -// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - -// // check -// Expect(err).To(Not(BeNil())) -// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) -// }) -// }) - -// It("should fails cause we need old signature for changing verification method controller", func() { -// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) -// updatedDidDoc.VerificationMethod[0].Controller = BobDID -// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - -// // check -// Expect(err).To(Not(BeNil())) -// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) -// }) - -// It("should fails cause we need old signature for changing DIDDoc controller", func() { -// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) -// updatedDidDoc.Controller = append(updatedDidDoc.Controller, BobDID) -// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - -// // check -// Expect(err).To(Not(BeNil())) -// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) -// }) -// }) - -// var _ = Describe("Signature Verification. Remove signature/VM", func() { -// var setup TestSetup -// var ApubKey, BpubKey ed25519.PublicKey -// var AprivKey, BprivKey ed25519.PrivateKey -// var aliceDid, bobDid *types.MsgCreateDidPayload -// var aliceKeys, bobKeys map[string]ed25519.PrivateKey - -// BeforeEach(func() { -// setup = Setup() -// // Generate keys -// ApubKey, AprivKey, _ = ed25519.GenerateKey(rand.Reader) -// BpubKey, BprivKey, _ = ed25519.GenerateKey(rand.Reader) - -// // Create dids -// aliceDid = setup.BuildSimpleCreateDidPayload(AliceDID, AliceKey1, ApubKey) -// bobDid = setup.BuildSimpleCreateDidPayload(BobDID, BobKey1, BpubKey) - -// // Collect private keys -// aliceKeys = map[string]ed25519.PrivateKey{AliceKey1: AprivKey, BobKey1: BprivKey} -// bobKeys = map[string]ed25519.PrivateKey{BobKey1: BprivKey} - -// // Add verification method -// aliceDid.VerificationMethod = append(aliceDid.VerificationMethod, &types.VerificationMethod{ -// Id: AliceKey2, -// Controller: BobDID, -// Type: types.Ed25519VerificationKey2020, -// PublicKeyMultibase: MustEncodeBase58(BpubKey), -// }) -// }) - -// It("should fails cause old signature is required for removing this signature", func() { -// // Send dids -// _, _ = setup.SendCreateDid(bobDid, bobKeys) -// _, _ = setup.SendCreateDid(aliceDid, aliceKeys) - -// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) -// updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} -// updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} -// _, err := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(bobKeys)) - -// // check -// Expect(err).To(Not(BeNil())) -// Expect(err.Error()).To(Equal(fmt.Sprintf("there should be at least one signature by %s (old version): signature is required but not found", AliceDID))) -// }) - -// It("should not fails while removing the whole verification method", func() { -// aliceDid.Authentication = append(aliceDid.Authentication, AliceKey2) - -// // Send dids -// _, _ = setup.SendCreateDid(bobDid, bobKeys) -// _, _ = setup.SendCreateDid(aliceDid, aliceKeys) - -// updatedDidDoc := setup.CreateToUpdateDid(aliceDid) -// updatedDidDoc.Authentication = []string{aliceDid.Authentication[0]} -// updatedDidDoc.VerificationMethod = []*types.VerificationMethod{aliceDid.VerificationMethod[0]} -// receivedDid, _ := setup.SendUpdateDid(updatedDidDoc, MapToListOfSignerKeys(ConcatKeys(aliceKeys, bobKeys))) - -// // check -// Expect(len(aliceDid.VerificationMethod)).To(Not(Equal(len(receivedDid.VerificationMethod)))) -// Expect(reflect.DeepEqual(aliceDid.VerificationMethod[0], receivedDid.VerificationMethod[0])).To(BeTrue()) -// }) -// }) + It("Doesn't work with only second VM signature (which is get deleted)", func() { + signatures := []SignInput{secondSignInput} + + _, err := setup.UpdateDid(msg, signatures) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there should be at least one valid signature by %s (new version): invalid signature detected", alice.Did))) + }) + }) +}) From ade7e7ded9333524cdb675eaca9d9cc6b37b60d5 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Fri, 14 Oct 2022 18:02:25 +0500 Subject: [PATCH 35/76] Reorganising tests --- x/cheqd/tests/create_did_test.go | 5 +- x/cheqd/tests/setup.go | 298 ------------------ x/cheqd/tests/{ => setup}/config.go | 2 +- x/cheqd/tests/setup/setup.go | 76 +++++ x/cheqd/tests/{ => setup}/setup_create_did.go | 2 +- x/cheqd/tests/{ => setup}/setup_query_did.go | 2 +- x/cheqd/tests/{ => setup}/setup_update_did.go | 2 +- x/cheqd/tests/{ => setup}/types.go | 2 +- x/cheqd/tests/{ => setup}/utils.go | 24 +- x/cheqd/tests/test_data.go | 22 -- x/cheqd/tests/update_did_test.go | 2 + x/resource/tests/setup_create_resource.go | 0 x/resource/tests/setup_query_resource | 0 13 files changed, 88 insertions(+), 349 deletions(-) delete mode 100644 x/cheqd/tests/setup.go rename x/cheqd/tests/{ => setup}/config.go (68%) create mode 100644 x/cheqd/tests/setup/setup.go rename x/cheqd/tests/{ => setup}/setup_create_did.go (99%) rename x/cheqd/tests/{ => setup}/setup_query_did.go (94%) rename x/cheqd/tests/{ => setup}/setup_update_did.go (98%) rename x/cheqd/tests/{ => setup}/types.go (96%) rename x/cheqd/tests/{ => setup}/utils.go (65%) delete mode 100644 x/cheqd/tests/test_data.go create mode 100644 x/resource/tests/setup_create_resource.go create mode 100644 x/resource/tests/setup_query_resource diff --git a/x/cheqd/tests/create_did_test.go b/x/cheqd/tests/create_did_test.go index a83204ea6..864faef02 100644 --- a/x/cheqd/tests/create_did_test.go +++ b/x/cheqd/tests/create_did_test.go @@ -3,14 +3,17 @@ package tests import ( "fmt" + . "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" "github.com/cheqd/cheqd-node/x/cheqd/types" ) var _ = Describe("Create DID tests", func() { - var setup TestSetup + var setup setup.TestSetup BeforeEach(func() { setup = Setup() diff --git a/x/cheqd/tests/setup.go b/x/cheqd/tests/setup.go deleted file mode 100644 index d7881e7b0..000000000 --- a/x/cheqd/tests/setup.go +++ /dev/null @@ -1,298 +0,0 @@ -package tests - -import ( - "context" - "crypto/ed25519" - "crypto/rand" - "encoding/base64" - "time" - - "github.com/cheqd/cheqd-node/x/cheqd/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/multiformats/go-multibase" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/store" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - dbm "github.com/tendermint/tm-db" - - "github.com/cheqd/cheqd-node/x/cheqd/keeper" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type TestSetup struct { - Cdc codec.Codec - - SdkCtx sdk.Context - StdCtx context.Context - - Keeper keeper.Keeper - MsgServer types.MsgServer - QueryServer types.QueryServer -} - -func Setup() TestSetup { - // Init Codec - ir := codectypes.NewInterfaceRegistry() - types.RegisterInterfaces(ir) - cdc := codec.NewProtoCodec(ir) - - // Init KVSore - db := dbm.NewMemDB() - - dbStore := store.NewCommitMultiStore(db) - storeKey := sdk.NewKVStoreKey(types.StoreKey) - dbStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, nil) - - _ = dbStore.LoadLatestVersion() - - // Init Keepers - newKeeper := keeper.NewKeeper(cdc, storeKey) - - // Create Tx - txBytes := make([]byte, 28) - _, _ = rand.Read(txBytes) - - // Create context - blockTime, _ := time.Parse(time.RFC3339, "2021-01-01T00:00:00.000Z") - ctx := sdk.NewContext(dbStore, - tmproto.Header{ChainID: "test", Time: blockTime}, - false, log.NewNopLogger()).WithTxBytes(txBytes) - - msgServer := keeper.NewMsgServer(*newKeeper) - queryServer := keeper.NewQueryServer(*newKeeper) - - setup := TestSetup{ - Cdc: cdc, - - SdkCtx: ctx, - StdCtx: sdk.WrapSDKContext(ctx), - - Keeper: *newKeeper, - MsgServer: msgServer, - QueryServer: queryServer, - } - - setup.Keeper.SetDidNamespace(&ctx, DID_NAMESPACE) - return setup -} - -func (s *TestSetup) CreateToUpdateDid(did *types.MsgCreateDidPayload) *types.MsgUpdateDidPayload { - return &types.MsgUpdateDidPayload{ - Id: did.Id, - Controller: did.Controller, - VerificationMethod: did.VerificationMethod, - Authentication: did.Authentication, - AssertionMethod: did.AssertionMethod, - CapabilityInvocation: did.CapabilityInvocation, - CapabilityDelegation: did.CapabilityDelegation, - KeyAgreement: did.KeyAgreement, - AlsoKnownAs: did.AlsoKnownAs, - Service: did.Service, - Context: did.Context, - } -} - -// TODO: Remove -func (s *TestSetup) WrapCreateRequest(payload *types.MsgCreateDidPayload, keys map[string]ed25519.PrivateKey) *types.MsgCreateDid { - var signatures []*types.SignInfo - signingInput := payload.GetSignBytes() - - for privKeyId, privKey := range keys { - signature := base64.StdEncoding.EncodeToString(ed25519.Sign(privKey, signingInput)) - signatures = append(signatures, &types.SignInfo{ - VerificationMethodId: privKeyId, - Signature: signature, - }) - } - - return &types.MsgCreateDid{ - Payload: payload, - Signatures: signatures, - } -} - -func (s *TestSetup) WrapUpdateRequest(payload *types.MsgUpdateDidPayload, keys []SignInput) *types.MsgUpdateDid { - var signatures []*types.SignInfo - signingInput := payload.GetSignBytes() - - for _, skey := range keys { - signature := base64.StdEncoding.EncodeToString(ed25519.Sign(skey.Key, signingInput)) - signatures = append(signatures, &types.SignInfo{ - VerificationMethodId: skey.VerificationMethodId, - Signature: signature, - }) - } - - return &types.MsgUpdateDid{ - Payload: payload, - Signatures: signatures, - } -} - -func (s *TestSetup) SendUpdateDid(msg *types.MsgUpdateDidPayload, keys []SignInput) (*types.Did, error) { - req := types.QueryGetDidRequest{ - Id: msg.Id, - } - - state, _ := s.QueryServer.Did(s.StdCtx, &req) - if len(msg.VersionId) == 0 { - msg.VersionId = state.Metadata.VersionId - } - - _, err := s.MsgServer.UpdateDid(s.StdCtx, s.WrapUpdateRequest(msg, keys)) - if err != nil { - return nil, err - } - - req = types.QueryGetDidRequest{ - Id: msg.Id, - } - - updated, _ := s.QueryServer.Did(s.StdCtx, &req) - return updated.Did, nil -} - -func (s *TestSetup) SendCreateDid(msg *types.MsgCreateDidPayload, keys map[string]ed25519.PrivateKey) (*types.Did, error) { - _, err := s.MsgServer.CreateDid(s.StdCtx, s.WrapCreateRequest(msg, keys)) - if err != nil { - return nil, err - } - - req := types.QueryGetDidRequest{ - Id: msg.Id, - } - - created, _ := s.QueryServer.Did(s.StdCtx, &req) - return created.Did, nil -} - -func ConcatKeys(dst map[string]ed25519.PrivateKey, src map[string]ed25519.PrivateKey) map[string]ed25519.PrivateKey { - for k, v := range src { - dst[k] = v - } - - return dst -} - -func MapToListOfSignerKeys(mp map[string]ed25519.PrivateKey) []SignInput { - rlist := []SignInput{} - for k, v := range mp { - rlist = append(rlist, SignInput{ - VerificationMethodId: k, - Key: v, - }) - } - return rlist -} - -func (s TestSetup) CreateTestDIDs(keys map[string]KeyPair) error { - testDIDs := []struct { - signers []string - msg *types.MsgCreateDidPayload - }{ - { - signers: []string{AliceKey1}, - msg: &types.MsgCreateDidPayload{ - Id: AliceDID, - Authentication: []string{AliceKey1}, - VerificationMethod: []*types.VerificationMethod{ - { - Id: AliceKey1, - Type: types.Ed25519VerificationKey2020, - Controller: AliceDID, - }, - }, - }, - }, - { - signers: []string{BobKey2}, - msg: &types.MsgCreateDidPayload{ - Id: BobDID, - Authentication: []string{ - BobKey1, - BobKey2, - BobKey3, - }, - CapabilityDelegation: []string{ - BobKey4, - }, - VerificationMethod: []*types.VerificationMethod{ - { - Id: BobKey1, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: BobKey2, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: BobKey3, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: BobKey4, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - }, - }, - }, - { - signers: []string{CharlieKey2, BobKey2}, - msg: &types.MsgCreateDidPayload{ - Id: CharlieDID, - Authentication: []string{ - CharlieKey1, - CharlieKey2, - CharlieKey3, - }, - VerificationMethod: []*types.VerificationMethod{ - { - Id: CharlieKey1, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey2, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - { - Id: CharlieKey3, - Type: types.Ed25519VerificationKey2020, - Controller: BobDID, - }, - }, - }, - }, - } - - for _, prefilled := range testDIDs { - msg := prefilled.msg - - for _, vm := range msg.VerificationMethod { - encoded, err := multibase.Encode(multibase.Base58BTC, keys[vm.Id].Public) - if err != nil { - return err - } - vm.PublicKeyMultibase = encoded - } - - signerKeys := map[string]ed25519.PrivateKey{} - for _, signer := range prefilled.signers { - signerKeys[signer] = keys[signer].Private - } - - _, err := s.SendCreateDid(msg, signerKeys) - if err != nil { - return err - } - } - - return nil -} diff --git a/x/cheqd/tests/config.go b/x/cheqd/tests/setup/config.go similarity index 68% rename from x/cheqd/tests/config.go rename to x/cheqd/tests/setup/config.go index 9d067e0c2..1cde54f21 100644 --- a/x/cheqd/tests/config.go +++ b/x/cheqd/tests/setup/config.go @@ -1,3 +1,3 @@ -package tests +package setup const DID_NAMESPACE = "test" diff --git a/x/cheqd/tests/setup/setup.go b/x/cheqd/tests/setup/setup.go new file mode 100644 index 000000000..1f2ad401a --- /dev/null +++ b/x/cheqd/tests/setup/setup.go @@ -0,0 +1,76 @@ +package setup + +import ( + "context" + "crypto/rand" + "time" + + "github.com/cheqd/cheqd-node/x/cheqd/types" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" + + "github.com/cheqd/cheqd-node/x/cheqd/keeper" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type TestSetup struct { + Cdc codec.Codec + + SdkCtx sdk.Context + StdCtx context.Context + + Keeper keeper.Keeper + MsgServer types.MsgServer + QueryServer types.QueryServer +} + +func Setup() TestSetup { + // Init Codec + ir := codectypes.NewInterfaceRegistry() + types.RegisterInterfaces(ir) + cdc := codec.NewProtoCodec(ir) + + // Init KVSore + db := dbm.NewMemDB() + + dbStore := store.NewCommitMultiStore(db) + storeKey := sdk.NewKVStoreKey(types.StoreKey) + dbStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, nil) + + _ = dbStore.LoadLatestVersion() + + // Init Keepers + newKeeper := keeper.NewKeeper(cdc, storeKey) + + // Create Tx + txBytes := make([]byte, 28) + _, _ = rand.Read(txBytes) + + // Create context + blockTime, _ := time.Parse(time.RFC3339, "2021-01-01T00:00:00.000Z") + ctx := sdk.NewContext(dbStore, + tmproto.Header{ChainID: "test", Time: blockTime}, + false, log.NewNopLogger()).WithTxBytes(txBytes) + + msgServer := keeper.NewMsgServer(*newKeeper) + queryServer := keeper.NewQueryServer(*newKeeper) + + setup := TestSetup{ + Cdc: cdc, + + SdkCtx: ctx, + StdCtx: sdk.WrapSDKContext(ctx), + + Keeper: *newKeeper, + MsgServer: msgServer, + QueryServer: queryServer, + } + + setup.Keeper.SetDidNamespace(&ctx, DID_NAMESPACE) + return setup +} diff --git a/x/cheqd/tests/setup_create_did.go b/x/cheqd/tests/setup/setup_create_did.go similarity index 99% rename from x/cheqd/tests/setup_create_did.go rename to x/cheqd/tests/setup/setup_create_did.go index 28fc3d003..bf0a13915 100644 --- a/x/cheqd/tests/setup_create_did.go +++ b/x/cheqd/tests/setup/setup_create_did.go @@ -1,4 +1,4 @@ -package tests +package setup import ( "crypto/ed25519" diff --git a/x/cheqd/tests/setup_query_did.go b/x/cheqd/tests/setup/setup_query_did.go similarity index 94% rename from x/cheqd/tests/setup_query_did.go rename to x/cheqd/tests/setup/setup_query_did.go index d1618eb23..b241cf9f1 100644 --- a/x/cheqd/tests/setup_query_did.go +++ b/x/cheqd/tests/setup/setup_query_did.go @@ -1,4 +1,4 @@ -package tests +package setup import "github.com/cheqd/cheqd-node/x/cheqd/types" diff --git a/x/cheqd/tests/setup_update_did.go b/x/cheqd/tests/setup/setup_update_did.go similarity index 98% rename from x/cheqd/tests/setup_update_did.go rename to x/cheqd/tests/setup/setup_update_did.go index c703ec859..1bd4068c9 100644 --- a/x/cheqd/tests/setup_update_did.go +++ b/x/cheqd/tests/setup/setup_update_did.go @@ -1,4 +1,4 @@ -package tests +package setup import ( "crypto/ed25519" diff --git a/x/cheqd/tests/types.go b/x/cheqd/tests/setup/types.go similarity index 96% rename from x/cheqd/tests/types.go rename to x/cheqd/tests/setup/types.go index 0aa97baee..de7d58e88 100644 --- a/x/cheqd/tests/types.go +++ b/x/cheqd/tests/setup/types.go @@ -1,4 +1,4 @@ -package tests +package setup import ( "crypto/ed25519" diff --git a/x/cheqd/tests/utils.go b/x/cheqd/tests/setup/utils.go similarity index 65% rename from x/cheqd/tests/utils.go rename to x/cheqd/tests/setup/utils.go index 9ac2e2848..89b2c26db 100644 --- a/x/cheqd/tests/utils.go +++ b/x/cheqd/tests/setup/utils.go @@ -1,4 +1,4 @@ -package tests +package setup import ( "crypto/ed25519" @@ -43,28 +43,6 @@ func GenerateDID(idtype IDType) string { } } -func GenerateTestKeys() map[string]KeyPair { - return map[string]KeyPair{ - AliceKey1: GenerateKeyPair(), - AliceKey2: GenerateKeyPair(), - BobKey1: GenerateKeyPair(), - BobKey2: GenerateKeyPair(), - BobKey3: GenerateKeyPair(), - BobKey4: GenerateKeyPair(), - CharlieKey1: GenerateKeyPair(), - CharlieKey2: GenerateKeyPair(), - CharlieKey3: GenerateKeyPair(), - ImposterKey1: GenerateKeyPair(), - } -} - -func InitEnv(keys map[string]KeyPair) TestSetup { - setup := Setup() - err := setup.CreateTestDIDs(keys) - Expect(err).To(BeNil()) - return setup -} - func GenerateKeyPair() KeyPair { PublicKey, PrivateKey, _ := ed25519.GenerateKey(rand.Reader) return KeyPair{PrivateKey, PublicKey} diff --git a/x/cheqd/tests/test_data.go b/x/cheqd/tests/test_data.go deleted file mode 100644 index 47d292149..000000000 --- a/x/cheqd/tests/test_data.go +++ /dev/null @@ -1,22 +0,0 @@ -package tests - -const ( - AliceDID = "did:cheqd:test:aaaaaaaaaaaaaaaa" // 16 chars base58 - BobDID = "did:cheqd:test:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" // 32 chars base58 - CharlieDID = "did:cheqd:test:babbba14-f294-458a-9b9c-474d188680fd" // UUID - ImposterDID = "did:cheqd:test:nananananananana" - NotFounDID = "did:cheqd:test:nfdnfdnfdnfdnfdd" - AliceKey1 = AliceDID + "#key-1" - AliceKey2 = AliceDID + "#key-2" - BobKey1 = BobDID + "#key-1" - BobKey2 = BobDID + "#key-2" - BobKey3 = BobDID + "#key-3" - BobKey4 = BobDID + "#key-4" - ImposterKey1 = ImposterDID + "#key-1" - ImposterKey2 = ImposterDID + "#key-2" - NotFoundKey1 = NotFounDID + "#key-1" - CharlieKey1 = CharlieDID + "#key-1" - CharlieKey2 = CharlieDID + "#key-2" - CharlieKey3 = CharlieDID + "#key-3" - CharlieKey4 = CharlieDID + "#key-4" -) diff --git a/x/cheqd/tests/update_did_test.go b/x/cheqd/tests/update_did_test.go index 238fff23d..3bc9db05a 100644 --- a/x/cheqd/tests/update_did_test.go +++ b/x/cheqd/tests/update_did_test.go @@ -3,6 +3,8 @@ package tests import ( "fmt" + . "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/x/resource/tests/setup_create_resource.go b/x/resource/tests/setup_create_resource.go new file mode 100644 index 000000000..e69de29bb diff --git a/x/resource/tests/setup_query_resource b/x/resource/tests/setup_query_resource new file mode 100644 index 000000000..e69de29bb From 023edf1f2a394285be6b878fd012f78eacc05488 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Mon, 17 Oct 2022 12:46:57 +0500 Subject: [PATCH 36/76] The rest of resource tests --- x/cheqd/tests/setup/setup_create_did.go | 14 +- x/cheqd/tests/setup/types.go | 11 +- x/resource/tests/constants.go | 38 ---- x/resource/tests/create_resource_test.go | 205 ++++++++---------- .../tests/query_all_resource_versions_test.go | 117 ++++------ .../tests/query_collection_resources_test.go | 87 +++----- x/resource/tests/query_resource_test.go | 107 +++------ x/resource/tests/{ => setup}/setup.go | 61 +----- .../tests/setup/setup_create_resource.go | 53 +++++ .../tests/setup/setup_query_all_versions.go | 12 + .../setup/setup_query_collecton_resources.go | 11 + .../tests/setup/setup_query_resource.go | 12 + x/resource/tests/setup/testdata.go | 8 + x/resource/tests/setup_create_resource.go | 0 x/resource/tests/setup_query_resource | 0 15 files changed, 303 insertions(+), 433 deletions(-) delete mode 100644 x/resource/tests/constants.go rename x/resource/tests/{ => setup}/setup.go (56%) create mode 100644 x/resource/tests/setup/setup_create_resource.go create mode 100644 x/resource/tests/setup/setup_query_all_versions.go create mode 100644 x/resource/tests/setup/setup_query_collecton_resources.go create mode 100644 x/resource/tests/setup/setup_query_resource.go create mode 100644 x/resource/tests/setup/testdata.go delete mode 100644 x/resource/tests/setup_create_resource.go delete mode 100644 x/resource/tests/setup_query_resource diff --git a/x/cheqd/tests/setup/setup_create_did.go b/x/cheqd/tests/setup/setup_create_did.go index bf0a13915..402265a47 100644 --- a/x/cheqd/tests/setup/setup_create_did.go +++ b/x/cheqd/tests/setup/setup_create_did.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "github.com/cheqd/cheqd-node/x/cheqd/types" + "github.com/cheqd/cheqd-node/x/cheqd/utils" ) func (s *TestSetup) CreateDid(payload *types.MsgCreateDidPayload, signInputs []SignInput) (*types.MsgCreateDidResponse, error) { @@ -30,6 +31,8 @@ func (s *TestSetup) CreateDid(payload *types.MsgCreateDidPayload, signInputs []S func (s *TestSetup) BuildSimpleDid() DidInfo { did := GenerateDID(Base58_16chars) + _, _, collectionId := utils.MustSplitDID(did) + keyPair := GenerateKeyPair() keyId := did + "#key-1" @@ -52,11 +55,12 @@ func (s *TestSetup) BuildSimpleDid() DidInfo { } return DidInfo{ - Did: did, - KeyPair: keyPair, - KeyId: keyId, - Msg: msg, - SignInput: signInput, + Did: did, + CollectionId: collectionId, + KeyPair: keyPair, + KeyId: keyId, + Msg: msg, + SignInput: signInput, } } diff --git a/x/cheqd/tests/setup/types.go b/x/cheqd/tests/setup/types.go index de7d58e88..a13b46151 100644 --- a/x/cheqd/tests/setup/types.go +++ b/x/cheqd/tests/setup/types.go @@ -17,11 +17,12 @@ type SignInput struct { } type DidInfo struct { - Msg *types.MsgCreateDidPayload - Did string - KeyPair KeyPair - KeyId string - SignInput SignInput + Msg *types.MsgCreateDidPayload + Did string + CollectionId string + KeyPair KeyPair + KeyId string + SignInput SignInput } type CreatedDidInfo struct { diff --git a/x/resource/tests/constants.go b/x/resource/tests/constants.go deleted file mode 100644 index 4571fe208..000000000 --- a/x/resource/tests/constants.go +++ /dev/null @@ -1,38 +0,0 @@ -package tests - -import ( - "crypto/sha256" - - "github.com/cheqd/cheqd-node/x/resource/types" -) - -const ( - CLSchemaType = "CL-Schema" - SchemaData = "{\"attr\":[\"name\",\"age\"]}" - TestResourceName = "Test Resource Name" - JsonResourceType = "application/json" - ResourceId = "988b0ab3-6a39-4598-83ec-b84c6cf8da15" - AnotherResourceId = "71583c78-f16f-11ec-9dd4-cba0f34eb177" - IncorrectResourceId = "1234" - - NotFoundDIDIdentifier = "nfdnfdnfdnfdnfdd" - ExistingDIDIdentifier = "eeeeeeeeeeeeeeee" - ExistingDID = "did:cheqd:test:" + ExistingDIDIdentifier - ExistingDIDKey = ExistingDID + "#key-1" -) - -func ExistingResource() types.Resource { - data := []byte(SchemaData) - checksum := sha256.Sum256(data) - return types.Resource{ - Header: &types.ResourceHeader{ - CollectionId: ExistingDIDIdentifier, - Id: "a09abea0-22e0-4b35-8f70-9cc3a6d0b5fd", - Name: "Existing Resource Name", - ResourceType: CLSchemaType, - MediaType: JsonResourceType, - Checksum: checksum[:], - }, - Data: data, - } -} diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index dc01850fa..5b6b84149 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -1,134 +1,103 @@ package tests import ( - "crypto/ed25519" - "crypto/sha256" - "fmt" + . "github.com/cheqd/cheqd-node/x/resource/tests/setup" + "github.com/google/uuid" - cheqdtypes "github.com/cheqd/cheqd-node/x/cheqd/types" - cheqdutils "github.com/cheqd/cheqd-node/x/cheqd/utils" + cheqdsetup "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -var _ = Describe("CreateResource", func() { - Describe("Validate", func() { - var setup TestSetup - var err error - keys := GenerateTestKeys() +func ExpectPayloadToMatchResource(payload *resourcetypes.MsgCreateResourcePayload, resource *resourcetypes.Resource) { + // Provided header + Expect(payload.Id).To(Equal(resource.Header.Id)) + Expect(payload.CollectionId).To(Equal(resource.Header.CollectionId)) + Expect(payload.Name).To(Equal(resource.Header.Name)) + Expect(payload.ResourceType).To(Equal(resource.Header.ResourceType)) + + // Generated header + // TODO: Uncomment once fixed + // hash := sha256.Sum256(payload.Data) + // Expect(resource.Header.Checksum).To(Equal(hash)) + + // Provided data + Expect(payload.Data).To(Equal(resource.Data)) +} + +var _ = Describe("Create Resource Tests", func() { + var setup TestSetup + var alice cheqdsetup.CreatedDidInfo + + BeforeEach(func() { + setup = Setup() + alice = setup.CreateSimpleDid() + }) + + Describe("Simple resource", func() { + var msg *resourcetypes.MsgCreateResourcePayload + + BeforeEach(func() { + msg = &resourcetypes.MsgCreateResourcePayload{ + CollectionId: alice.CollectionId, + Id: uuid.NewString(), + Name: "Test Resource Name", + ResourceType: CLSchemaType, + Data: []byte(SchemaData), + } + }) + + It("Can be created with DIDDoc controller signature", func() { + _, err := setup.CreateResource(msg, []cheqdsetup.SignInput{alice.SignInput}) + Expect(err).To(BeNil()) + + // check + created, err := setup.QueryResource(alice.CollectionId, msg.Id) + Expect(err).To(BeNil()) + + ExpectPayloadToMatchResource(msg, created.Resource) + }) + + It("Can't be created without DIDDoc controller signatures", func() { + _, err := setup.CreateResource(msg, []cheqdsetup.SignInput{}) + Expect(err.Error()).To(ContainSubstring("signature is required but not found")) + }) + + It("Can't be created with invalid collection id", func() { + msg.CollectionId = cheqdsetup.GenerateDID(cheqdsetup.Base58_16chars) + + _, err := setup.CreateResource(msg, []cheqdsetup.SignInput{alice.SignInput}) + Expect(err.Error()).To(ContainSubstring("not found")) + }) + }) + + Describe("New version", func() { + var existingResource *resourcetypes.MsgCreateResourceResponse + BeforeEach(func() { - setup = Setup() - didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) - _, err = setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) + existingResource = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Test Resource Name", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + }) + + It("Is linked to the previous one when name matches", func() { + msg := resourcetypes.MsgCreateResourcePayload{ + CollectionId: alice.CollectionId, + Id: uuid.NewString(), + Name: existingResource.Resource.Header.Name, + ResourceType: CLSchemaType, + Data: []byte(SchemaData), + } + + _, err := setup.CreateResource(&msg, []cheqdsetup.SignInput{alice.SignInput}) Expect(err).To(BeNil()) - resourcePayload := GenerateCreateResourcePayload(ExistingResource()) - _, err = setup.SendCreateResource(resourcePayload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) + + // check + created, err := setup.QueryResource(alice.CollectionId, msg.Id) Expect(err).To(BeNil()) + + ExpectPayloadToMatchResource(&msg, created.Resource) + Expect(created.Resource.Header.PreviousVersionId).To(Equal(existingResource.Resource.Header.Id)) }) - DescribeTable("Validate MsgCreateResource", - func( - valid bool, - signerKeys map[string]ed25519.PrivateKey, - msg *resourcetypes.MsgCreateResourcePayload, - mediaType string, - previousVersionId string, - errMsg string, - ) { - resource, err := setup.SendCreateResource(msg, signerKeys) - if valid { - Expect(err).To(BeNil()) - - did := cheqdutils.JoinDID("cheqd", "test", resource.Header.CollectionId) - req := cheqdtypes.QueryGetDidRequest{Id: did} - didStateValue, err := setup.QueryServer.Did(setup.StdCtx, &req) - Expect(err).To(BeNil()) - Expect(didStateValue.Metadata.Resources).Should(ContainElement(resource.Header.Id)) - - Expect(resource.Header.CollectionId).To(Equal(msg.CollectionId)) - Expect(resource.Header.Id).To(Equal(msg.Id)) - Expect(resource.Header.Name).To(Equal(msg.Name)) - Expect(resource.Header.ResourceType).To(Equal(msg.ResourceType)) - Expect(resource.Header.MediaType).To(Equal(mediaType)) - Expect(resource.Header.PreviousVersionId).To(Equal(previousVersionId)) - expectedChecksum := sha256.Sum256(msg.Data) - Expect(resource.Header.Checksum).To(Equal(expectedChecksum[:])) - } else { - Expect(err).ToNot(BeNil()) - Expect(err.Error()).To(Equal(errMsg)) - } - }, - Entry("Valid: Works", - true, - map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, - &resourcetypes.MsgCreateResourcePayload{ - CollectionId: ExistingDIDIdentifier, - Id: ResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - JsonResourceType, - "", - "", - ), - Entry("Valid: Add new resource version", - true, - map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, - &resourcetypes.MsgCreateResourcePayload{ - CollectionId: ExistingResource().Header.CollectionId, - Id: ResourceId, - Name: ExistingResource().Header.Name, - ResourceType: ExistingResource().Header.ResourceType, - Data: ExistingResource().Data, - }, - ExistingResource().Header.MediaType, - ExistingResource().Header.Id, - "", - ), - Entry("Invalid: No signature", - false, - map[string]ed25519.PrivateKey{}, - &resourcetypes.MsgCreateResourcePayload{ - CollectionId: ExistingDIDIdentifier, - Id: ResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - JsonResourceType, - "", - fmt.Errorf("signer: %s: signature is required but not found", ExistingDID).Error(), - ), - Entry("Invalid: Resource Id is not an acceptable format", - false, - map[string]ed25519.PrivateKey{}, - &resourcetypes.MsgCreateResourcePayload{ - CollectionId: ExistingDIDIdentifier, - Id: IncorrectResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - JsonResourceType, - "", - fmt.Errorf("signer: %s: signature is required but not found", ExistingDID).Error(), - ), - Entry("Invalid: DidDoc not found", - false, - map[string]ed25519.PrivateKey{}, - &resourcetypes.MsgCreateResourcePayload{ - CollectionId: NotFoundDIDIdentifier, - Id: IncorrectResourceId, - Name: "Test Resource Name", - ResourceType: CLSchemaType, - Data: []byte(SchemaData), - }, - JsonResourceType, - "", - fmt.Errorf("did:cheqd:test:%s: not found", NotFoundDIDIdentifier).Error(), - ), - ) }) }) diff --git a/x/resource/tests/query_all_resource_versions_test.go b/x/resource/tests/query_all_resource_versions_test.go index e27f534c8..e06c517cb 100644 --- a/x/resource/tests/query_all_resource_versions_test.go +++ b/x/resource/tests/query_all_resource_versions_test.go @@ -1,97 +1,54 @@ package tests import ( - "crypto/ed25519" - "fmt" + . "github.com/cheqd/cheqd-node/x/resource/tests/setup" + cheqdsetup "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" "github.com/cheqd/cheqd-node/x/resource/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -var _ = Describe("QueryAllResourceVersions", func() { - Describe("Validate", func() { - var setup TestSetup - keys := GenerateTestKeys() - BeforeEach(func() { - setup = Setup() - didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) - _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) - Expect(err).To(BeNil()) - payload := GenerateCreateResourcePayload(ExistingResource()) - _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) - Expect(err).To(BeNil()) - }) - DescribeTable("Validate QueryGetAllResourceVersionsRequest", - func( - valid bool, - signerKeys map[string]ed25519.PrivateKey, - msg *types.QueryGetAllResourceVersionsRequest, - response *types.QueryGetAllResourceVersionsResponse, - errMsg string, - ) { - existingResource := ExistingResource() +var _ = Describe("Query All Resource Versions", func() { + var setup TestSetup + var alice cheqdsetup.CreatedDidInfo - payload := GenerateCreateResourcePayload(existingResource) - payload.Id = ResourceId + var res1v1 *types.MsgCreateResourceResponse + var res1v2 *types.MsgCreateResourceResponse + var res2v1 *types.MsgCreateResourceResponse - nextVersionResource, err := setup.SendCreateResource(payload, signerKeys) - Expect(err).To(BeNil()) - Expect(nextVersionResource).ToNot(Equal(existingResource)) + BeforeEach(func() { + setup = Setup() - payload = GenerateCreateResourcePayload(existingResource) - payload.Id = AnotherResourceId - payload.Name = "AnotherResourceVersion" - differentResource, err := setup.SendCreateResource(payload, signerKeys) - Expect(err).To(BeNil()) - Expect(differentResource).ToNot(Equal(existingResource)) - Expect(differentResource).ToNot(Equal(nextVersionResource)) + alice = setup.CreateSimpleDid() - queryResponse, err := setup.ResourceQueryServer.AllResourceVersions(setup.StdCtx, msg) + res1v1 = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Resource 1", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + res1v2 = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Resource 1", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + res2v1 = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Resource 2", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + }) + + It("Should return 2 versions for resource 1", func() { + versions, err := setup.AllResourceVersions(alice.CollectionId, res1v1.Resource.Header.Name) + Expect(err).To(BeNil()) + Expect(versions.Resources).To(HaveLen(2)) + + ids := []string{versions.Resources[0].Id, versions.Resources[1].Id} + + Expect(ids).To(ContainElement(res1v1.Resource.Header.Id)) + Expect(ids).To(ContainElement(res1v2.Resource.Header.Id)) + }) + + It("Should return 1 version for resource 2", func() { + versions, err := setup.AllResourceVersions(alice.CollectionId, res2v1.Resource.Header.Name) + Expect(err).To(BeNil()) + Expect(versions.Resources).To(HaveLen(1)) + Expect(versions.Resources[0].Id).To(Equal(res2v1.Resource.Header.Id)) + }) - if valid { - resources := queryResponse.Resources - existingResource.Header.NextVersionId = nextVersionResource.Header.Id - expectedResources := map[string]types.Resource{ - existingResource.Header.Id: existingResource, - nextVersionResource.Header.Id: *nextVersionResource, - } - Expect(err).To(BeNil()) - Expect(len(resources)).To(Equal(len(expectedResources))) - for _, r := range resources { - r.Created = expectedResources[r.Id].Header.Created - Expect(r).To(Equal(expectedResources[r.Id].Header)) - } - } else { - Expect(err).ToNot(BeNil()) - Expect(err.Error()).To(Equal(errMsg)) - } - }, - Entry("Valid: should return all resources", - true, - map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, - &types.QueryGetAllResourceVersionsRequest{ - CollectionId: ExistingDIDIdentifier, - Name: ExistingResource().Header.Name, - }, - &types.QueryGetAllResourceVersionsResponse{ - Resources: []*types.ResourceHeader{ - ExistingResource().Header, - }, - }, - "", - ), - Entry("Invalid: should return an error if the collection id is invalid", - false, - map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}, - &types.QueryGetAllResourceVersionsRequest{ - CollectionId: NotFoundDIDIdentifier, - Name: ExistingResource().Header.Name, - }, - nil, - fmt.Errorf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier).Error(), - ), - ) + It("Should return 0 versions for non-existing resource", func() { + versions, err := setup.AllResourceVersions(alice.CollectionId, "non-existing") + Expect(err).To(BeNil()) + Expect(versions.Resources).To(HaveLen(0)) }) }) diff --git a/x/resource/tests/query_collection_resources_test.go b/x/resource/tests/query_collection_resources_test.go index 4c8b19b2f..219b96357 100644 --- a/x/resource/tests/query_collection_resources_test.go +++ b/x/resource/tests/query_collection_resources_test.go @@ -1,69 +1,42 @@ package tests import ( - "crypto/ed25519" - "fmt" + . "github.com/cheqd/cheqd-node/x/resource/tests/setup" - resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" + cheqdsetup "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" + "github.com/cheqd/cheqd-node/x/resource/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -var _ = Describe("QueryCollectionResources", func() { - Describe("Validate", func() { - var setup TestSetup - keys := GenerateTestKeys() - BeforeEach(func() { - setup = Setup() - didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) - _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) - Expect(err).To(BeNil()) - payload := GenerateCreateResourcePayload(ExistingResource()) - _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) - Expect(err).To(BeNil()) - }) - DescribeTable("Validate QueryCollectionResources", - func( - valid bool, - msg *resourcetypes.QueryGetCollectionResourcesRequest, - response *resourcetypes.QueryGetCollectionResourcesResponse, - errMsg string, - ) { - queryResponse, err := setup.ResourceQueryServer.CollectionResources(setup.StdCtx, msg) +var _ = Describe("Query Collection Resources", func() { + var setup TestSetup + var alice cheqdsetup.CreatedDidInfo - if valid { - resources := queryResponse.Resources - expectedResources := response.Resources - Expect(err).To(BeNil()) - Expect(len(expectedResources)).To(Equal(len(resources))) - for i, r := range resources { - r.Created = expectedResources[i].Created - Expect(expectedResources[i]).To(Equal(r)) - } - } else { - Expect(err).To(HaveOccurred()) - Expect(errMsg).To(Equal(err.Error())) - } - }, - Entry("Valid: Works", - true, - &resourcetypes.QueryGetCollectionResourcesRequest{ - CollectionId: ExistingDIDIdentifier, - }, - &resourcetypes.QueryGetCollectionResourcesResponse{ - Resources: []*resourcetypes.ResourceHeader{ExistingResource().Header}, - }, - "", - ), - Entry("Invalid: DID Doc is not found", - false, - &resourcetypes.QueryGetCollectionResourcesRequest{ - CollectionId: NotFoundDIDIdentifier, - }, - nil, - fmt.Errorf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier).Error(), - ), - ) + var res1v1 *types.MsgCreateResourceResponse + var res1v2 *types.MsgCreateResourceResponse + var res2v1 *types.MsgCreateResourceResponse + + BeforeEach(func() { + setup = Setup() + + alice = setup.CreateSimpleDid() + + res1v1 = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Resource 1", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + res1v2 = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Resource 1", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + res2v1 = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Resource 2", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + }) + + It("Should return all 3 headerrs", func() { + versions, err := setup.CollectionResources(alice.CollectionId) + Expect(err).To(BeNil()) + Expect(versions.Resources).To(HaveLen(3)) + + ids := []string{versions.Resources[0].Id, versions.Resources[1].Id, versions.Resources[2].Id} + + Expect(ids).To(ContainElement(res1v1.Resource.Header.Id)) + Expect(ids).To(ContainElement(res1v2.Resource.Header.Id)) + Expect(ids).To(ContainElement(res2v1.Resource.Header.Id)) }) }) diff --git a/x/resource/tests/query_resource_test.go b/x/resource/tests/query_resource_test.go index 1c3d57f15..6db9f42a3 100644 --- a/x/resource/tests/query_resource_test.go +++ b/x/resource/tests/query_resource_test.go @@ -1,85 +1,44 @@ package tests import ( - "crypto/ed25519" - "crypto/sha256" - "fmt" + . "github.com/cheqd/cheqd-node/x/resource/tests/setup" + "github.com/google/uuid" + + cheqdsetup "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" + "github.com/cheqd/cheqd-node/x/resource/types" - resourcetypes "github.com/cheqd/cheqd-node/x/resource/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -var _ = Describe("QueryGetResource", func() { - Describe("Validate", func() { - var setup TestSetup - keys := GenerateTestKeys() - existingResource := ExistingResource() - BeforeEach(func() { - setup = Setup() - didDoc := setup.BuildSimpleCreateDidPayload(ExistingDID, ExistingDIDKey, keys[ExistingDIDKey].Public) - _, err := setup.SendCreateDid(didDoc, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) - Expect(err).To(BeNil()) - payload := GenerateCreateResourcePayload(ExistingResource()) - _, err = setup.SendCreateResource(payload, map[string]ed25519.PrivateKey{ExistingDIDKey: keys[ExistingDIDKey].Private}) - Expect(err).To(BeNil()) - }) - DescribeTable("Validate QueryGetResourceRequest", - func( - valid bool, - msg *resourcetypes.QueryGetResourceRequest, - response *resourcetypes.QueryGetResourceResponse, - errMsg string, - ) { - queryResponse, err := setup.ResourceQueryServer.Resource(setup.StdCtx, msg) +var _ = Describe("Query Collection Resources", func() { + var setup TestSetup + var alice cheqdsetup.CreatedDidInfo + var resource *types.MsgCreateResourceResponse + + BeforeEach(func() { + setup = Setup() + alice = setup.CreateSimpleDid() + resource = setup.CreateSimpleResource(alice.CollectionId, SchemaData, "Resource 1", CLSchemaType, []cheqdsetup.SignInput{alice.SignInput}) + }) + + It("Works", func() { + versions, err := setup.QueryResource(alice.CollectionId, resource.Resource.Header.Id) + Expect(err).To(BeNil()) + Expect(versions.Resource.Header.Id).To(Equal(resource.Resource.Header.Id)) + }) + + It("Returns error if resource does not exist", func() { + nonExistingResource := uuid.NewString() + + _, err := setup.QueryResource(alice.CollectionId, nonExistingResource) + Expect(err.Error()).To(ContainSubstring("not found")) + }) + + It("Returns error if collection does not exist", func() { + nonExistingCollection := cheqdsetup.GenerateDID(cheqdsetup.Base58_16chars) - if valid { - resource := queryResponse.Resource - Expect(err).To(BeNil()) - Expect(response.Resource.Header.CollectionId).To(Equal(resource.Header.CollectionId)) - Expect(response.Resource.Header.Id).To(Equal(resource.Header.Id)) - Expect(response.Resource.Header.MediaType).To(Equal(resource.Header.MediaType)) - Expect(response.Resource.Header.ResourceType).To(Equal(resource.Header.ResourceType)) - Expect(response.Resource.Data).To(Equal(resource.Data)) - Expect(response.Resource.Header.Name).To(Equal(resource.Header.Name)) - checksum := sha256.Sum256(response.Resource.Data) - Expect(checksum[:]).To(Equal(resource.Header.Checksum)) - Expect(response.Resource.Header.PreviousVersionId).To(Equal(resource.Header.PreviousVersionId)) - Expect(response.Resource.Header.NextVersionId).To(Equal(resource.Header.NextVersionId)) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal(errMsg)) - } - }, - Entry("Valid: Works", - true, - &resourcetypes.QueryGetResourceRequest{ - CollectionId: ExistingDIDIdentifier, - Id: existingResource.Header.Id, - }, - &resourcetypes.QueryGetResourceResponse{ - Resource: &existingResource, - }, - "", - ), - Entry("Invalid: Resource not found", - false, - &resourcetypes.QueryGetResourceRequest{ - CollectionId: ExistingDIDIdentifier, - Id: AnotherResourceId, - }, - nil, - fmt.Errorf("resource %s:%s: not found", ExistingDIDIdentifier, AnotherResourceId).Error(), - ), - Entry("Invalid: DIDDoc not found", - false, - &resourcetypes.QueryGetResourceRequest{ - CollectionId: NotFoundDIDIdentifier, - Id: existingResource.Header.Id, - }, - nil, - fmt.Errorf("did:cheqd:test:%s: DID Doc not found", NotFoundDIDIdentifier).Error(), - ), - ) + _, err := setup.QueryResource(nonExistingCollection, resource.Resource.Header.Id) + Expect(err.Error()).To(ContainSubstring("DID Doc not found")) }) }) diff --git a/x/resource/tests/setup.go b/x/resource/tests/setup/setup.go similarity index 56% rename from x/resource/tests/setup.go rename to x/resource/tests/setup/setup.go index ca6e6ba77..2f05fdebb 100644 --- a/x/resource/tests/setup.go +++ b/x/resource/tests/setup/setup.go @@ -1,13 +1,11 @@ -package tests +package setup import ( - "crypto/ed25519" "crypto/rand" - "encoding/base64" "time" cheqdkeeper "github.com/cheqd/cheqd-node/x/cheqd/keeper" - cheqdtests "github.com/cheqd/cheqd-node/x/cheqd/tests" + cheqdsetup "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" cheqdtypes "github.com/cheqd/cheqd-node/x/cheqd/types" "github.com/cheqd/cheqd-node/x/resource/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -23,7 +21,7 @@ import ( ) type TestSetup struct { - cheqdtests.TestSetup + cheqdsetup.TestSetup ResourceKeeper keeper.Keeper ResourceMsgServer types.MsgServer @@ -72,7 +70,7 @@ func Setup() TestSetup { queryServer := keeper.NewQueryServer(*resourceKeeper, *cheqdKeeper) setup := TestSetup{ - TestSetup: cheqdtests.TestSetup{ + TestSetup: cheqdsetup.TestSetup{ Cdc: cdc, SdkCtx: ctx, @@ -88,55 +86,6 @@ func Setup() TestSetup { ResourceQueryServer: queryServer, } - setup.Keeper.SetDidNamespace(&ctx, cheqdtests.DID_NAMESPACE) + setup.Keeper.SetDidNamespace(&ctx, cheqdsetup.DID_NAMESPACE) return setup } - -func GenerateCreateResourcePayload(resource types.Resource) *types.MsgCreateResourcePayload { - return &types.MsgCreateResourcePayload{ - CollectionId: resource.Header.CollectionId, - Id: resource.Header.Id, - Name: resource.Header.Name, - ResourceType: resource.Header.ResourceType, - Data: resource.Data, - } -} - -func (s *TestSetup) WrapCreateRequest(payload *types.MsgCreateResourcePayload, keys map[string]ed25519.PrivateKey) *types.MsgCreateResource { - var signatures []*cheqdtypes.SignInfo - signingInput := payload.GetSignBytes() - - for privKeyId, privKey := range keys { - signature := base64.StdEncoding.EncodeToString(ed25519.Sign(privKey, signingInput)) - signatures = append(signatures, &cheqdtypes.SignInfo{ - VerificationMethodId: privKeyId, - Signature: signature, - }) - } - - return &types.MsgCreateResource{ - Payload: payload, - Signatures: signatures, - } -} - -func (s *TestSetup) SendCreateResource(msg *types.MsgCreateResourcePayload, keys map[string]ed25519.PrivateKey) (*types.Resource, error) { - _, err := s.ResourceMsgServer.CreateResource(s.StdCtx, s.WrapCreateRequest(msg, keys)) - if err != nil { - return nil, err - } - - req := &types.QueryGetResourceRequest{ - CollectionId: msg.CollectionId, - Id: msg.Id, - } - - created, _ := s.ResourceQueryServer.Resource(s.StdCtx, req) - return created.Resource, nil -} - -func GenerateTestKeys() map[string]cheqdtests.KeyPair { - return map[string]cheqdtests.KeyPair{ - ExistingDIDKey: cheqdtests.GenerateKeyPair(), - } -} diff --git a/x/resource/tests/setup/setup_create_resource.go b/x/resource/tests/setup/setup_create_resource.go new file mode 100644 index 000000000..3fe6c0695 --- /dev/null +++ b/x/resource/tests/setup/setup_create_resource.go @@ -0,0 +1,53 @@ +package setup + +import ( + "crypto/ed25519" + "encoding/base64" + + "github.com/cheqd/cheqd-node/x/cheqd/tests/setup" + cheqdtypes "github.com/cheqd/cheqd-node/x/cheqd/types" + "github.com/cheqd/cheqd-node/x/resource/types" + "github.com/google/uuid" +) + +func (s *TestSetup) CreateResource(payload *types.MsgCreateResourcePayload, signInputs []setup.SignInput) (*types.MsgCreateResourceResponse, error) { + signBytes := payload.GetSignBytes() + var signatures []*cheqdtypes.SignInfo + + for _, input := range signInputs { + signature := ed25519.Sign(input.Key, signBytes) + + signatures = append(signatures, &cheqdtypes.SignInfo{ + VerificationMethodId: input.VerificationMethodId, + Signature: base64.StdEncoding.EncodeToString(signature), + }) + } + + msg := &types.MsgCreateResource{ + Payload: payload, + Signatures: signatures, + } + + return s.ResourceMsgServer.CreateResource(s.StdCtx, msg) +} + +func (s *TestSetup) BuildSimpleResource(collectionId, data, name, _type string) types.MsgCreateResourcePayload { + return types.MsgCreateResourcePayload{ + Id: uuid.NewString(), + CollectionId: collectionId, + Data: []byte(data), + Name: name, + ResourceType: _type, + } +} + +func (s *TestSetup) CreateSimpleResource(collectionId, data, name, _type string, signInputs []setup.SignInput) *types.MsgCreateResourceResponse { + resource := s.BuildSimpleResource(collectionId, data, name, _type) + res, err := s.CreateResource(&resource, signInputs) + + if err != nil { + panic(err) + } + + return res +} diff --git a/x/resource/tests/setup/setup_query_all_versions.go b/x/resource/tests/setup/setup_query_all_versions.go new file mode 100644 index 000000000..8a49deff8 --- /dev/null +++ b/x/resource/tests/setup/setup_query_all_versions.go @@ -0,0 +1,12 @@ +package setup + +import "github.com/cheqd/cheqd-node/x/resource/types" + +func (s *TestSetup) AllResourceVersions(collectionId, name string) (*types.QueryGetAllResourceVersionsResponse, error) { + req := &types.QueryGetAllResourceVersionsRequest{ + CollectionId: collectionId, + Name: name, + } + + return s.ResourceQueryServer.AllResourceVersions(s.StdCtx, req) +} diff --git a/x/resource/tests/setup/setup_query_collecton_resources.go b/x/resource/tests/setup/setup_query_collecton_resources.go new file mode 100644 index 000000000..708877110 --- /dev/null +++ b/x/resource/tests/setup/setup_query_collecton_resources.go @@ -0,0 +1,11 @@ +package setup + +import "github.com/cheqd/cheqd-node/x/resource/types" + +func (s *TestSetup) CollectionResources(collectionId string) (*types.QueryGetCollectionResourcesResponse, error) { + req := &types.QueryGetCollectionResourcesRequest{ + CollectionId: collectionId, + } + + return s.ResourceQueryServer.CollectionResources(s.StdCtx, req) +} diff --git a/x/resource/tests/setup/setup_query_resource.go b/x/resource/tests/setup/setup_query_resource.go new file mode 100644 index 000000000..34c47bc1d --- /dev/null +++ b/x/resource/tests/setup/setup_query_resource.go @@ -0,0 +1,12 @@ +package setup + +import "github.com/cheqd/cheqd-node/x/resource/types" + +func (s *TestSetup) QueryResource(collectionId, resourceId string) (*types.QueryGetResourceResponse, error) { + req := &types.QueryGetResourceRequest{ + CollectionId: collectionId, + Id: resourceId, + } + + return s.ResourceQueryServer.Resource(s.StdCtx, req) +} diff --git a/x/resource/tests/setup/testdata.go b/x/resource/tests/setup/testdata.go new file mode 100644 index 000000000..e5b005e9b --- /dev/null +++ b/x/resource/tests/setup/testdata.go @@ -0,0 +1,8 @@ +package setup + +const ( + CLSchemaType = "CL-Schema" + SchemaData = "{\"attr\":[\"name\",\"age\"]}" + TestResourceName = "Test Resource Name" + JsonResourceType = "application/json" +) diff --git a/x/resource/tests/setup_create_resource.go b/x/resource/tests/setup_create_resource.go deleted file mode 100644 index e69de29bb..000000000 diff --git a/x/resource/tests/setup_query_resource b/x/resource/tests/setup_query_resource deleted file mode 100644 index e69de29bb..000000000 From 515a2a3ba1ab1e7abe7d425d43b25b70d94559c9 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Mon, 17 Oct 2022 13:07:52 +0500 Subject: [PATCH 37/76] Optimize ginkgo installation --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 16055f813..9ea382c1f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,9 +34,9 @@ jobs: cache: true - name: Install ginkgo + working-directory: ./.. run: | - go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo - go get github.com/onsi/gomega/... + go install github.com/onsi/ginkgo/v2/ginkgo@latest go install github.com/jstemmer/go-junit-report/v2@latest - name: Run Ginkgo tests From 3bd4ac3f4641a4d0237b4e2db7cd3737df215b98 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Mon, 17 Oct 2022 13:09:56 +0500 Subject: [PATCH 38/76] Cleaning up --- .github/workflows/dispatch.yml | 46 ++++++++++++++++------------------ .github/workflows/test.yml | 11 -------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index d15a4a6fb..14bdbbd07 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -1,31 +1,29 @@ name: "Workflow Dispatch" on: push -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: + call-lint: + name: "Lint" + uses: ./.github/workflows/lint.yml - call-lint: - name: "Lint" - uses: ./.github/workflows/lint.yml - - call-build: - name: "Build" - needs: call-lint - uses: ./.github/workflows/build.yml - secrets: inherit + call-build: + name: "Build" + needs: call-lint + uses: ./.github/workflows/build.yml + secrets: inherit - call-test: - name: "Test" - needs: call-build - uses: ./.github/workflows/test.yml - secrets: inherit + call-test: + name: "Test" + needs: call-build + uses: ./.github/workflows/test.yml + secrets: inherit - call-release: - name: "Release" - needs: [call-test, call-build] - if: ${{ github.ref_protected == true }} - uses: ./.github/workflows/release.yml - secrets: inherit \ No newline at end of file + call-release: + name: "Release" + needs: [call-test, call-build] + if: ${{ github.ref_protected == true }} + uses: ./.github/workflows/release.yml + secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ea382c1f..8ed49f978 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,16 +1,5 @@ name: "Test" on: - pull_request_target: - branches: - - main - - develop - types: - - opened - - reopened - - edited - - synchronize - - ready_for_review - - review_requested workflow_call: defaults: run: From ca33e1af8b33da7a34eb5a399eabf96bbcea768c Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Mon, 17 Oct 2022 13:19:08 +0500 Subject: [PATCH 39/76] Mod tidy + liner issues --- go.mod | 9 ++------- go.sum | 4 ++-- x/resource/client/cli/tx_create_resource.go | 4 ++-- x/resource/tests/setup/setup_create_resource.go | 1 - 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 7e6fb3eb0..f290fd0ac 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.17 require ( filippo.io/edwards25519 v1.0.0-beta.2 - github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cosmos/cosmos-sdk v0.45.5 github.com/cosmos/ibc-go/v3 v3.1.1 github.com/gabriel-vasile/mimetype v1.4.1 @@ -17,13 +16,12 @@ require ( github.com/lestrrat-go/jwx v1.2.25 github.com/multiformats/go-multibase v0.1.1 github.com/onsi/ginkgo/v2 v2.1.6 - github.com/onsi/gomega v1.20.1 + github.com/onsi/gomega v1.22.0 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.6.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.12.0 - github.com/stretchr/testify v1.7.1 github.com/tendermint/tendermint v0.34.19 github.com/tendermint/tm-db v0.6.6 google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd @@ -64,7 +62,6 @@ require ( github.com/go-kit/log v0.2.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect - github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/gateway v1.1.0 // indirect @@ -72,7 +69,6 @@ require ( github.com/google/btree v1.0.0 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/google/orderedcode v0.0.1 // indirect - github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect @@ -107,7 +103,6 @@ require ( github.com/mtibben/percent v0.2.1 // indirect github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect - github.com/onsi/gomega v1.22.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect @@ -124,6 +119,7 @@ require ( github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect github.com/spf13/afero v1.8.2 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/stretchr/testify v1.7.1 // indirect github.com/subosito/gotenv v1.3.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect @@ -137,7 +133,6 @@ require ( golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect - golang.org/x/tools v0.1.12 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.4 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 80970d8ae..fb95add73 100644 --- a/go.sum +++ b/go.sum @@ -368,7 +368,6 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= @@ -471,7 +470,6 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -778,9 +776,11 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= +github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU= github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= diff --git a/x/resource/client/cli/tx_create_resource.go b/x/resource/client/cli/tx_create_resource.go index 470e15fc4..e28a348cf 100644 --- a/x/resource/client/cli/tx_create_resource.go +++ b/x/resource/client/cli/tx_create_resource.go @@ -1,7 +1,7 @@ package cli import ( - "io/ioutil" + "os" cheqdcli "github.com/cheqd/cheqd-node/x/cheqd/client/cli" "github.com/cheqd/cheqd-node/x/resource/types" @@ -60,7 +60,7 @@ func CmdCreateResource() *cobra.Command { return err } - data, err := ioutil.ReadFile(resourceFile) + data, err := os.ReadFile(resourceFile) if err != nil { return err } diff --git a/x/resource/tests/setup/setup_create_resource.go b/x/resource/tests/setup/setup_create_resource.go index 3fe6c0695..40f13df3e 100644 --- a/x/resource/tests/setup/setup_create_resource.go +++ b/x/resource/tests/setup/setup_create_resource.go @@ -44,7 +44,6 @@ func (s *TestSetup) BuildSimpleResource(collectionId, data, name, _type string) func (s *TestSetup) CreateSimpleResource(collectionId, data, name, _type string, signInputs []setup.SignInput) *types.MsgCreateResourceResponse { resource := s.BuildSimpleResource(collectionId, data, name, _type) res, err := s.CreateResource(&resource, signInputs) - if err != nil { panic(err) } From d5194473e5f3dbebedb77deaf31577da4a11d691 Mon Sep 17 00:00:00 2001 From: Alexandr Kolesov Date: Mon, 17 Oct 2022 15:20:29 +0500 Subject: [PATCH 40/76] Cleanup --- app/export.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/export.go b/app/export.go index b6d449ead..15aebb9e1 100644 --- a/app/export.go +++ b/app/export.go @@ -49,8 +49,7 @@ func (app *App) ExportAppStateAndValidators( // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated -// -// in favour of export at a block height +// in favour of export at a block height func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false From 8645992276907a5c22e854ae5472e96f3de75dd6 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 21:29:25 +0100 Subject: [PATCH 41/76] Update dispatch.yml --- .github/workflows/dispatch.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 43ab2b5b7..0bba1c544 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -16,16 +16,16 @@ jobs: needs: call-lint uses: cheqd/cheqd-node/.github/workflows/build.yml@develop - # call-test: - # name: "Test" - # needs: call-build - # uses: ./.github/workflows/test.yml - # secrets: inherit + call-test: + name: "Test" + needs: call-build + uses: cheqd/cheqd-node/.github/workflows/test.yml@develop + secrets: inherit call-release: name: "Release" - # needs: call-test - needs: call-build + needs: call-test + # needs: call-build if: ${{ github.ref_protected == true }} uses: cheqd/cheqd-node/.github/workflows/release.yml@develop secrets: inherit From 1239add0db97a2ffe7c27f3e9abd4e10b3ce0294 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 21:29:48 +0100 Subject: [PATCH 42/76] Update test.yml --- .github/workflows/test.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ed49f978..3e6576d86 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,15 +23,14 @@ jobs: cache: true - name: Install ginkgo - working-directory: ./.. run: | - go install github.com/onsi/ginkgo/v2/ginkgo@latest - go install github.com/jstemmer/go-junit-report/v2@latest + go get github.com/onsi/ginkgo/v2/ginkgo + go get github.com/onsi/gomega/... - name: Run Ginkgo tests run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml - - uses: mikepenz/action-junit-report@v3 - if: success() || failure() - with: - report_paths: 'report.xml' + # - uses: mikepenz/action-junit-report@v3 + # if: success() || failure() # run this step even if previous step failed + # with: + # report_paths: 'report.xml' From 67bf86811952690f3ca46e3ce2838a4784dbfcd1 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 21:35:52 +0100 Subject: [PATCH 43/76] Update test.yml --- .github/workflows/test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e6576d86..595e045b1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,14 +4,15 @@ on: defaults: run: shell: bash +env: + NODE_CONFIGS_BASE: "/home/runner/work/cheqd-node/cheqd-node/docker/localnet/network-config" permissions: - id-token: write contents: write - checks: write + packages: read jobs: unit-tests: - name: "Unit tests" + name: "Unit Tests" runs-on: ubuntu-latest steps: From 668cedee71a1e3cf77bb3aa9424c65fc405be40f Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 21:35:55 +0100 Subject: [PATCH 44/76] Update go.mod --- go.mod | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index f963f3d94..95da11e32 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.18 require ( filippo.io/edwards25519 v1.0.0-beta.2 - github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cosmos/cosmos-sdk v0.45.9 github.com/cosmos/ibc-go/v3 v3.3.0 github.com/gabriel-vasile/mimetype v1.4.1 @@ -23,7 +22,6 @@ require ( github.com/spf13/cobra v1.5.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.12.0 - github.com/stretchr/testify v1.8.0 github.com/tendermint/tendermint v0.34.21 github.com/tendermint/tm-db v0.6.6 google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b @@ -101,7 +99,6 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect github.com/minio/highwayhash v1.0.2 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mr-tron/base58 v1.1.0 // indirect github.com/mtibben/percent v0.2.1 // indirect @@ -123,6 +120,7 @@ require ( github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect github.com/spf13/afero v1.8.2 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/stretchr/testify v1.8.0 // indirect github.com/subosito/gotenv v1.4.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect @@ -145,6 +143,7 @@ require ( ) replace ( + github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 // Dragonberry fix github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 @@ -152,9 +151,14 @@ replace ( github.com/cosmos/cosmos-sdk => github.com/cheqd/cosmos-sdk v0.45.9-cheqd-tag // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. + // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 - github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 + github.com/jhump/protoreflect => github.com/jhump/protoreflect v1.9.0 + github.com/tecbot/gorocksdb => github.com/cosmos/gorocksdb v1.2.0 + + // latest grpc doesn't work with with our modified proto compiler, so we need to enforce + // the following version across all dependencies. google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) From d54b6297d03b599126397e554741509b4e76a69b Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 21:35:58 +0100 Subject: [PATCH 45/76] Update go.sum --- go.sum | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/go.sum b/go.sum index 818892a08..6f0daedad 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,6 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-beta.2 h1:/BZRNzm8N4K4eWfK28dL4yescorxtO7YG1yun8fy+pI= filippo.io/edwards25519 v1.0.0-beta.2/go.mod h1:X+pm78QAUPtFLi1z9PYIlS/bdDnvbCOGKtZ+ACWEf7o= -github.com/99designs/keyring v1.1.6 h1:kVDC2uCgVwecxCk+9zoCt2uEL6dt+dfVzMvGgnVcIuM= -github.com/99designs/keyring v1.1.6/go.mod h1:16e0ds7LGQQcT59QqkTg72Hh5ShM51Byv5PEmW6uoRU= github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc= github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4= @@ -121,7 +119,6 @@ github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+q github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts= github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= -github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= @@ -173,6 +170,8 @@ github.com/cosmos/iavl v0.19.3 h1:cESO0OwTTxQm5rmyESKW+zESheDUYI7CcZDWWDwnuxg= github.com/cosmos/iavl v0.19.3/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/ibc-go/v3 v3.3.0 h1:r8gYUvQreMQrf4R5RgedK9gcbjLk4uE2q6fuZGjf4n0= github.com/cosmos/ibc-go/v3 v3.3.0/go.mod h1:VUWLHw0C3USmTQZnTdkuXXdUdLbW8zsK3lV1Ieposog= +github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU= +github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= @@ -347,6 +346,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= @@ -453,7 +453,7 @@ github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jhump/protoreflect v1.12.1-0.20220721211354-060cc04fc18b h1:izTof8BKh/nE1wrKOrloNA5q4odOarjf+Xpe+4qow98= +github.com/jhump/protoreflect v1.9.0 h1:npqHz788dryJiR/l6K/RUQAyh2SwV91+d1dnh4RjO9w= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= @@ -546,7 +546,6 @@ github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= @@ -600,6 +599,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU= +github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= @@ -1202,8 +1203,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 1e3c9e670acd398adc1bc3e4f4009ca461c9da5e Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 21:37:08 +0100 Subject: [PATCH 46/76] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 95da11e32..19fa8d9d1 100644 --- a/go.mod +++ b/go.mod @@ -154,8 +154,8 @@ replace ( // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/jhump/protoreflect => github.com/jhump/protoreflect v1.9.0 + github.com/jhump/protoreflect => github.com/jhump/protoreflect v1.9.0 github.com/tecbot/gorocksdb => github.com/cosmos/gorocksdb v1.2.0 // latest grpc doesn't work with with our modified proto compiler, so we need to enforce From 128f2488c0577a2fa92139a532eec65893ff9181 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 23:24:25 +0100 Subject: [PATCH 47/76] Update dispatch.yml --- .github/workflows/dispatch.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 0bba1c544..39f23005f 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -9,17 +9,17 @@ jobs: call-lint: name: "Lint" - uses: cheqd/cheqd-node/.github/workflows/lint.yml@develop + uses: ./.github/workflows/lint.yml call-build: name: "Build" needs: call-lint - uses: cheqd/cheqd-node/.github/workflows/build.yml@develop + uses: ./.github/workflows/build.yml call-test: name: "Test" needs: call-build - uses: cheqd/cheqd-node/.github/workflows/test.yml@develop + uses: ./.github/workflows/test.yml secrets: inherit call-release: @@ -27,5 +27,5 @@ jobs: needs: call-test # needs: call-build if: ${{ github.ref_protected == true }} - uses: cheqd/cheqd-node/.github/workflows/release.yml@develop + uses: ./.github/workflows/release.yml secrets: inherit From c9de4dbe9b5fb448dfe24bc3e0c10ae9972d4cf3 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Mon, 17 Oct 2022 23:31:30 +0100 Subject: [PATCH 48/76] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 595e045b1..9ba106cd2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: go get github.com/onsi/gomega/... - name: Run Ginkgo tests - run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml + run: go run ./ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml # - uses: mikepenz/action-junit-report@v3 # if: success() || failure() # run this step even if previous step failed From 6ddda3eda12659216f43f3290955e97bfc11c45a Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 18 Oct 2022 16:04:14 +0300 Subject: [PATCH 49/76] Get rid of AfterEach functionality --- x/cheqd/types/did_did_test.go | 410 +++++++++--------- x/cheqd/types/did_service_test.go | 95 ++-- x/cheqd/types/did_verification_method_test.go | 200 +++++---- x/cheqd/types/tx_msg_create_did_test.go | 54 ++- x/cheqd/types/tx_msg_update_did_test.go | 74 ++-- x/cheqd/types/tx_sign_ingo_test.go | 178 ++++---- 6 files changed, 485 insertions(+), 526 deletions(-) diff --git a/x/cheqd/types/did_did_test.go b/x/cheqd/types/did_did_test.go index 53140c03a..d562aebe3 100644 --- a/x/cheqd/types/did_did_test.go +++ b/x/cheqd/types/did_did_test.go @@ -10,241 +10,221 @@ import ( ) var _ = Describe("DID Validation tests", func() { - var struct_ *Did - var allowedNamespaces []string - var isValid bool - var errorMsg string - - BeforeEach(func() { - struct_ = &Did{} - allowedNamespaces = []string{} - isValid = false - errorMsg = "" - }) - - AfterEach(func() { - err := struct_.Validate(allowedNamespaces) - - if isValid { - Expect(err).To(BeNil()) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) - } - }) - - When("DID is allowed", func() { - It("is valid", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, - }, - }, + type TestCaseDIDStruct struct { + did *Did + allowedNamespaces []string + isValid bool + errorMsg string + } + + DescribeTable("DID Validation tests", func(testCase TestCaseDIDStruct) { + + err := testCase.did.Validate(testCase.allowedNamespaces) + + if testCase.isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) } - isValid = true - errorMsg = "" - }) - }) - - When("DID is not allowed", func() { - It("should fail with error", func() { - struct_ = &Did{ - Id: InvalidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, + }, + + Entry( + "Did is valid", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, }, - } - isValid = false - errorMsg = "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).)." - }) - }) - - When("Verification method is Ed25519VerificationKey2020", func() { - It("is valid", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, + isValid: true, + errorMsg: ""}), + + Entry( + "DID is not allowed", + TestCaseDIDStruct{ + did: &Did{ + Id: InvalidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, }, - } - isValid = true - errorMsg = "" - }) - }) - - When("Verification method is jwk", func() { - It("is valid", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "JsonWebKey2020", - Controller: ValidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", + isValid: false, + errorMsg: "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).)."}), + + Entry( + "Verification method is Ed25519VerificationKey2020", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, }, - } - isValid = true - errorMsg = "" - }) - }) - - When("verification method has wrong id", func() { - It("should fail with corresponding error", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: InvalidTestDID, - Type: "JsonWebKey2020", - Controller: ValidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", + isValid: true, + errorMsg: ""}), + + Entry( + "Verification method is jwk", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "JsonWebKey2020", + Controller: ValidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, }, }, - } - isValid = false - errorMsg = "verification_method: (0: (id: unable to split did into method, namespace and id.).)." - }) - }) - When("verification method has wrong controller", func() { - It("should fail with corresponding error", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "JsonWebKey2020", - Controller: InvalidTestDID, - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", + isValid: true, + errorMsg: ""}), + + Entry("Verification method has wrong id", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: InvalidTestDID, + Type: "JsonWebKey2020", + Controller: ValidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, }, }, - } - isValid = false - errorMsg = "verification_method: (0: (controller: unable to split did into method, namespace and id.).)." - }) - }) - - When("list of DIDs in cotroller is allowed", func() { - It("s valid", func() { - struct_ = &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID, ValidTestDID2}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + isValid: false, + errorMsg: "verification_method: (0: (id: unable to split did into method, namespace and id.).)."}), + Entry( + "Verification method has wrong controller", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "JsonWebKey2020", + Controller: InvalidTestDID, + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, }, }, - } - isValid = true - errorMsg = "" - }) - }) - - When("list of DIDs in cotroller is not allowed", func() { - It("should fail with corresponding error", func() { - struct_ = &Did{ - Context: nil, - Id: ValidTestDID, - Controller: []string{ValidTestDID, InvalidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + isValid: false, + errorMsg: "verification_method: (0: (controller: unable to split did into method, namespace and id.).)."}), + Entry( + "List of DIDs in cotroller is allowed", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID, ValidTestDID2}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, }, - } - isValid = false - errorMsg = "controller: (1: unable to split did into method, namespace and id.)." - }) - }) - - When("namespace in controleer is not in list of allowed", func() { - It("should fail", func() { - struct_ = &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + isValid: true, + errorMsg: ""}), + Entry( + "List of DIDs in cotroller is not allowed", + TestCaseDIDStruct{ + did: &Did{ + Context: nil, + Id: ValidTestDID, + Controller: []string{ValidTestDID, InvalidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, }, - } - allowedNamespaces = []string{"mainnet"} - isValid = false - errorMsg = "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).)." - }) - }) - - When("controller is duplicated", func() { - It("should fail", func() { - struct_ = &Did{ - Id: ValidTestDID, - Controller: []string{ValidTestDID, ValidTestDID}, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + isValid: false, + errorMsg: "controller: (1: unable to split did into method, namespace and id.)."}), + Entry( + "Namespace in controler is not in list of allowed", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, }, - } - isValid = false - errorMsg = "controller: there should be no duplicates." - }) - }) - - When("verification method is duplicated", func() { - It("should fail", func() { - struct_ = &Did{ - Id: ValidTestDID, - VerificationMethod: []*VerificationMethod{ - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + allowedNamespaces: []string{"mainnet"}, + isValid: false, + errorMsg: "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).)."}), + Entry( + "Controller is duplicated", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + Controller: []string{ValidTestDID, ValidTestDID}, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, - { - Id: fmt.Sprintf("%s#fragment", ValidTestDID), - Type: "Ed25519VerificationKey2020", - Controller: ValidTestDID, - PublicKeyMultibase: ValidEd25519PubKey, + }, + isValid: false, + errorMsg: "controller: there should be no duplicates."}), + Entry( + "Verification method is duplicated", + TestCaseDIDStruct{ + did: &Did{ + Id: ValidTestDID, + VerificationMethod: []*VerificationMethod{ + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, + { + Id: fmt.Sprintf("%s#fragment", ValidTestDID), + Type: "Ed25519VerificationKey2020", + Controller: ValidTestDID, + PublicKeyMultibase: ValidEd25519PubKey, + }, }, }, - } - isValid = false - errorMsg = "verification_method: there are verification method duplicates." - }) - }) + isValid: false, + errorMsg: "verification_method: there are verification method duplicates."}), + ) }) diff --git a/x/cheqd/types/did_service_test.go b/x/cheqd/types/did_service_test.go index b2b47c9c2..6fdf18fe6 100644 --- a/x/cheqd/types/did_service_test.go +++ b/x/cheqd/types/did_service_test.go @@ -7,67 +7,64 @@ import ( . "github.com/cheqd/cheqd-node/x/cheqd/types" ) -var _ = Describe("DID Validation tests", func() { - var struct_ Service - var baseDid string - var allowedNamespaces []string - var isValid bool - var errorMsg string +var _ = Describe("Service tests", func() { + type TestCaseServiceStruct struct { + service *Service + baseDid string + allowedNamespaces []string + isValid bool + errorMsg string + } - BeforeEach(func() { - struct_ = Service{} - baseDid = "" - allowedNamespaces = []string{} - isValid = false - errorMsg = "" - }) + DescribeTable("Service Validation tests", func(testCase TestCaseServiceStruct) { + err := testCase.service.Validate(testCase.baseDid, testCase.allowedNamespaces) - AfterEach(func() { - err := struct_.Validate(baseDid, allowedNamespaces) - - if isValid { + if testCase.isValid { Expect(err).To(BeNil()) } else { Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) + Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) } - }) + }, - It("Positive case", func() { - struct_ = Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - } - baseDid = "did:cheqd:aaaaaaaaaaaaaaaa" - allowedNamespaces = []string{""} - isValid = true - errorMsg = "" - }) + Entry( + "Positive case", + TestCaseServiceStruct{ + service: &Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + }, + baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", + allowedNamespaces: []string{""}, + isValid: true, + errorMsg: "", + }), - When("Namespace is not allowed", func() { - It("should fail", func() { - struct_ = Service{ + Entry( + "Namespace is not allowed", + TestCaseServiceStruct{ + service: &Service{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", Type: "DIDCommMessaging", ServiceEndpoint: "endpoint", - } - allowedNamespaces = []string{"mainnet"} - isValid = false - errorMsg = "id: did namespace must be one of: mainnet." - }) - }) + }, + allowedNamespaces: []string{"mainnet"}, + isValid: false, + errorMsg: "id: did namespace must be one of: mainnet.", + }), - When("base DID is not the same as in id", func() { - It("should fail", func() { - struct_ = Service{ + Entry( + "Base DID is not the same as in id", + TestCaseServiceStruct{ + service: &Service{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", Type: "DIDCommMessaging", ServiceEndpoint: "endpoint", - } - baseDid = "did:cheqd:baaaaaaaaaaaaaab" - isValid = false - errorMsg = "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab." - }) - }) -}) + }, + baseDid: "did:cheqd:baaaaaaaaaaaaaab", + isValid: false, + errorMsg: "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab.", + }), + ) +}) \ No newline at end of file diff --git a/x/cheqd/types/did_verification_method_test.go b/x/cheqd/types/did_verification_method_test.go index c1e4e7f09..e2210402a 100644 --- a/x/cheqd/types/did_verification_method_test.go +++ b/x/cheqd/types/did_verification_method_test.go @@ -16,158 +16,152 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("Verification Method Validation tests", func() { - var struct_ VerificationMethod - var baseDid string - var allowedNamespaces []string - var isValid bool - var errorMsg string - - BeforeEach(func() { - struct_ = VerificationMethod{} - baseDid = "" - allowedNamespaces = []string{} - isValid = false - errorMsg = "" - }) - - AfterEach(func() { - err := struct_.Validate(baseDid, allowedNamespaces) - - if isValid { +var _ = Describe("Verification Method tests", func() { + type TestCaseVerificationMethodStruct struct { + vm VerificationMethod + baseDid string + allowedNamespaces []string + isValid bool + errorMsg string + } + + DescribeTable("Verification Method Validation tests", func(testCase TestCaseVerificationMethodStruct) { + + err := testCase.vm.Validate(testCase.baseDid, testCase.allowedNamespaces) + + if testCase.isValid { Expect(err).To(BeNil()) } else { Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) + Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) } - }) - When("verification method with expected multibase key", func() { - It("is valid", func() { - struct_ = VerificationMethod{ + }, + + Entry( + "Verification method with expected multibase key", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "Ed25519VerificationKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: nil, PublicKeyMultibase: ValidEd25519PubKey, - } - isValid = true - errorMsg = "" - }) - }) - - When("verification method with expected jwk key", func() { - It("is valid", func() { - struct_ = VerificationMethod{ + }, + isValid: true, + errorMsg: "", + }), + + Entry( + "Verification method with expected jwk key", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - } - isValid = true - errorMsg = "" - }) - }) - - When("id has expected DID as a base", func() { - It("is valid", func() { - struct_ = VerificationMethod{ + }, + isValid: true, + errorMsg: "", + }), + + Entry( + "Id has expected DID as a base", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - } - baseDid = "did:cheqd:aaaaaaaaaaaaaaaa" - isValid = true - errorMsg = "" - }) - }) - - When("id does not have expected DID as a base", func() { - It("should fail", func() { - struct_ = VerificationMethod{ + }, + baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", + isValid: true, + errorMsg: "", + }), + + Entry( + "Id does not have expected DID as a base", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - } - baseDid = "did:cheqd:bbbbbbbbbbbbbbbb" - isValid = false - errorMsg = "id: must have prefix: did:cheqd:bbbbbbbbbbbbbbbb." - }) - }) - - When("namespace is allowed", func() { - It("is valid", func() { - struct_ = VerificationMethod{ + }, + baseDid: "did:cheqd:bbbbbbbbbbbbbbbb", + isValid: false, + errorMsg: "id: must have prefix: did:cheqd:bbbbbbbbbbbbbbbb.", + }), + + Entry( + "Namespace is allowed", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - } - allowedNamespaces = []string{"mainnet", ""} - isValid = true - }) - }) - - When("namespace is not allowed", func() { - It("should fail", func() { - struct_ = VerificationMethod{ + }, + allowedNamespaces: []string{"mainnet", ""}, + isValid: true, + }), + + Entry( + "Namespace is not allowed", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - } - allowedNamespaces = []string{"testnet"} - isValid = false - errorMsg = "controller: did namespace must be one of: testnet; id: did namespace must be one of: testnet." - }) - }) - - When("JWK key has expected format", func() { - It("is valid", func() { - struct_ = VerificationMethod{ + }, + allowedNamespaces: []string{"testnet"}, + isValid: false, + errorMsg: "controller: did namespace must be one of: testnet; id: did namespace must be one of: testnet.", + }), + Entry( + "JWK key has expected format", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: ValidPublicKeyJWK, PublicKeyMultibase: "", - } - isValid = true - }) - }) - - When("JWK key has unexpected format", func() { - It("is not valid", func() { - struct_ = VerificationMethod{ + }, + isValid: true, + }), + Entry( + "JWK key has unexpected format", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: NotValidPublicKeyJWK, PublicKeyMultibase: "", - } - isValid = false - errorMsg = "public_key_jwk: can't parse jwk: failed to parse key: invalid key type from JSON (SomeOtherKeyType)." - }) - }) - - When("not all keys and valuesin JWK have expected format", func() { - It("should fail", func() { - struct_ = VerificationMethod{ + }, + isValid: false, + errorMsg: "public_key_jwk: can't parse jwk: failed to parse key: invalid key type from JSON (SomeOtherKeyType).", + }), + Entry( + "Not all keys and valuesin JWK have expected format", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", Type: "JsonWebKey2020", Controller: "did:cheqd:bbbbbbbbbbbbbbbb", PublicKeyJwk: append(ValidPublicKeyJWK, &KeyValuePair{Key: "", Value: ""}), PublicKeyMultibase: "", - } - isValid = false - errorMsg = "public_key_jwk: (6: (key: cannot be blank; value: cannot be blank.).)." - }) - }) + }, + isValid: false, + errorMsg: "public_key_jwk: (6: (key: cannot be blank; value: cannot be blank.).).", + }), + ) }) var _ = Describe("Validation ed25519 Signature in verification method", func() { diff --git a/x/cheqd/types/tx_msg_create_did_test.go b/x/cheqd/types/tx_msg_create_did_test.go index 714504135..b54d5a01b 100644 --- a/x/cheqd/types/tx_msg_create_did_test.go +++ b/x/cheqd/types/tx_msg_create_did_test.go @@ -8,30 +8,27 @@ import ( ) var _ = Describe("Message for DID creation", func() { - var struct_ *MsgCreateDid - var isValid bool - var errorMsg string + type TestCaseMsgCreateDID struct { + msg *MsgCreateDid + isValid bool + errorMsg string + } - BeforeEach(func() { - struct_ = &MsgCreateDid{} - isValid = false - errorMsg = "" - }) + DescribeTable("Tests for message for DID creation", func(testCase TestCaseMsgCreateDID) { + err := testCase.msg.ValidateBasic() - AfterEach(func() { - err := struct_.ValidateBasic() - - if isValid { + if testCase.isValid { Expect(err).To(BeNil()) } else { Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) + Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) } - }) + }, - When("all fields are set properly", func() { - It("should pass", func() { - struct_ = &MsgCreateDid{ + Entry( + "All fields are set properly", + TestCaseMsgCreateDID{ + msg: &MsgCreateDid{ Payload: &MsgCreateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -45,14 +42,13 @@ var _ = Describe("Message for DID creation", func() { Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, }, Signatures: nil, - } - isValid = true - }) - }) + }, + isValid: true}), - When("IDs are duplicated", func() { - It("should fail the validation", func() { - struct_ = &MsgCreateDid{ + Entry( + "IDs are duplicated", + TestCaseMsgCreateDID{ + msg: &MsgCreateDid{ Payload: &MsgCreateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -66,9 +62,9 @@ var _ = Describe("Message for DID creation", func() { Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#key1"}, }, Signatures: nil, - } - isValid = false - errorMsg = "payload: (authentication: there should be no duplicates.).: basic validation failed" - }) - }) + }, + isValid: false, + errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", + }), + ) }) diff --git a/x/cheqd/types/tx_msg_update_did_test.go b/x/cheqd/types/tx_msg_update_did_test.go index c29f35982..0a24f35c3 100644 --- a/x/cheqd/types/tx_msg_update_did_test.go +++ b/x/cheqd/types/tx_msg_update_did_test.go @@ -7,31 +7,28 @@ import ( . "github.com/cheqd/cheqd-node/x/cheqd/types" ) -var _ = Describe("Message for DID creation", func() { - var struct_ *MsgUpdateDid - var isValid bool - var errorMsg string +var _ = Describe("Message for DID updating", func() { + type TestCaseMsgUpdateDID struct { + msg *MsgUpdateDid + isValid bool + errorMsg string + } - BeforeEach(func() { - struct_ = &MsgUpdateDid{} - isValid = false - errorMsg = "" - }) + DescribeTable("Tests for message for DID updating", func(testCase TestCaseMsgUpdateDID) { + err := testCase.msg.ValidateBasic() - AfterEach(func() { - err := struct_.ValidateBasic() - - if isValid { + if testCase.isValid { Expect(err).To(BeNil()) } else { Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) + Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) } - }) + }, - When("all fields are set properly", func() { - It("Will pass", func() { - struct_ = &MsgUpdateDid{ + Entry( + "All fields are set properly", + TestCaseMsgUpdateDID{ + msg: &MsgUpdateDid{ Payload: &MsgUpdateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -46,14 +43,14 @@ var _ = Describe("Message for DID creation", func() { VersionId: "version1", }, Signatures: nil, - } - isValid = true - }) - }) + }, + isValid: true, + }), - When("IDs are duplicated", func() { - It("should fail the validation", func() { - struct_ = &MsgUpdateDid{ + Entry( + "IDs are duplicated", + TestCaseMsgUpdateDID{ + msg: &MsgUpdateDid{ Payload: &MsgUpdateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -68,15 +65,14 @@ var _ = Describe("Message for DID creation", func() { VersionId: "version1", }, Signatures: nil, - } - isValid = false - errorMsg = "payload: (authentication: there should be no duplicates.).: basic validation failed" - }) - }) - - When("VersionId is empty", func() { - It("should fail on validation", func() { - struct_ = &MsgUpdateDid{ + }, + isValid: false, + errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", + }), + Entry( + "VersionId is empty", + TestCaseMsgUpdateDID{ + msg: &MsgUpdateDid{ Payload: &MsgUpdateDidPayload{ Id: "did:cheqd:testnet:123456789abcdefg", VerificationMethod: []*VerificationMethod{ @@ -90,9 +86,9 @@ var _ = Describe("Message for DID creation", func() { Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, }, Signatures: nil, - } - isValid = false - errorMsg = "payload: (version_id: cannot be blank.).: basic validation failed" - }) - }) + }, + isValid: false, + errorMsg: "payload: (version_id: cannot be blank.).: basic validation failed", + }), + ) }) diff --git a/x/cheqd/types/tx_sign_ingo_test.go b/x/cheqd/types/tx_sign_ingo_test.go index 597e9616c..d78293eec 100644 --- a/x/cheqd/types/tx_sign_ingo_test.go +++ b/x/cheqd/types/tx_sign_ingo_test.go @@ -7,80 +7,76 @@ import ( . "github.com/cheqd/cheqd-node/x/cheqd/types" ) -var _ = Describe("SignInfo validation tests", func() { - var struct_ SignInfo - var allowedNamespaces []string - var isValid bool - var errorMsg string - - BeforeEach(func() { - struct_ = SignInfo{} - allowedNamespaces = []string{} - isValid = false - errorMsg = "" - }) - - AfterEach(func() { - err := struct_.Validate(allowedNamespaces) - - if isValid { +var _ = Describe("SignInfo tests", func() { + type TestCaseSignInfoStruct struct { + si SignInfo + allowedNamespaces []string + isValid bool + errorMsg string + } + + DescribeTable("SignInfo validation tests", func(testCase TestCaseSignInfoStruct) { + err := testCase.si.Validate(testCase.allowedNamespaces) + + if testCase.isValid { Expect(err).To(BeNil()) } else { Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(errorMsg)) + Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) } - }) - - It("Positive case", func() { - struct_ = SignInfo{ - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", - } - isValid = true - errorMsg = "" - }) - - When("namespace is not allowed", func() { - It("should fail", func() { - struct_ = SignInfo{ + }, + + Entry( + "Positive case", + TestCaseSignInfoStruct{ + si: SignInfo{ + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, + isValid: true, + errorMsg: "", + }), + + Entry( + "Namespace is not allowed", + TestCaseSignInfoStruct{ + si: SignInfo{ VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", Signature: "DIDCommMessaging", - } - allowedNamespaces = []string{"mainnet"} - isValid = false - errorMsg = "verification_method_id: did namespace must be one of: mainnet." - }) - }) - - When("signature is not valid base64 string", func() { - It("should fail", func() { - struct_ = SignInfo{ + }, + allowedNamespaces: []string{"mainnet"}, + isValid: false, + errorMsg: "verification_method_id: did namespace must be one of: mainnet.", + }), + + Entry( + "Signature is not valid base64 string", + TestCaseSignInfoStruct{ + si: SignInfo{ VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", Signature: "!@#", - } - isValid = false - errorMsg = "signature: must be encoded in Base64." - }) - }) + }, + isValid: false, + errorMsg: "signature: must be encoded in Base64.", + }), + ) }) var _ = Describe("Full SignInfo duplicates tests", func() { - var structs_ []*SignInfo - var isValid bool - - BeforeEach(func() { - structs_ = []*SignInfo{} - isValid = false - }) - - AfterEach(func() { - res_ := IsUniqueSignInfoList(structs_) - Expect(res_).To(Equal(isValid)) - }) - - When("signatures are different", func() { - It("should pass", func() { - structs_ = []*SignInfo{ + type TestCaseSignInfosStruct struct { + signInfos []*SignInfo + isValid bool + } + + DescribeTable("SignInfo duplicates tests", func(testCase TestCaseSignInfosStruct) { + res_ := IsUniqueSignInfoList(testCase.signInfos) + Expect(res_).To(Equal(testCase.isValid)) + }, + + Entry( + "Signatures are different", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -89,14 +85,14 @@ var _ = Describe("Full SignInfo duplicates tests", func() { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "bbb=", }, - } - isValid = true - }) - }) - - When("all fields are different", func() { - It("should pass", func() { - structs_ = []*SignInfo{ + }, + isValid: true, + }), + + Entry( + "All fields are different", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -105,14 +101,14 @@ var _ = Describe("Full SignInfo duplicates tests", func() { VerificationMethodId: "did:cheqd:bbbbbbbbbbbbbbbb#method1", Signature: "bbb=", }, - } - isValid = true - }) - }) - - When("all fields are the same", func() { - It("should fail", func() { - structs_ = []*SignInfo{ + }, + isValid: true, + }), + + Entry( + "All fields are the same", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -121,14 +117,14 @@ var _ = Describe("Full SignInfo duplicates tests", func() { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", }, - } - isValid = false - }) - }) - - When("all fields are the same and more elments", func() { - It("should fail", func() { - structs_ = []*SignInfo{ + }, + isValid: false, + }), + + Entry( + "All fields are the same and more elments", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", @@ -141,8 +137,8 @@ var _ = Describe("Full SignInfo duplicates tests", func() { VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", Signature: "aaa=", }, - } - isValid = false - }) - }) + }, + isValid: false, + }), + ) }) From 38bf67111dbed6900e224a5a32b9d4d3d5ab7148 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 18 Oct 2022 16:43:36 +0300 Subject: [PATCH 50/76] Makes linter happy --- x/cheqd/types/did_did_test.go | 94 ++++--- x/cheqd/types/did_service_test.go | 84 +++--- x/cheqd/types/did_verification_method_test.go | 257 +++++++++--------- x/cheqd/types/tx_msg_create_did_test.go | 73 ++--- x/cheqd/types/tx_msg_update_did_test.go | 114 ++++---- x/cheqd/types/tx_sign_ingo_test.go | 192 ++++++------- 6 files changed, 412 insertions(+), 402 deletions(-) diff --git a/x/cheqd/types/did_did_test.go b/x/cheqd/types/did_did_test.go index d562aebe3..981612ed0 100644 --- a/x/cheqd/types/did_did_test.go +++ b/x/cheqd/types/did_did_test.go @@ -11,26 +11,25 @@ import ( var _ = Describe("DID Validation tests", func() { type TestCaseDIDStruct struct { - did *Did + did *Did allowedNamespaces []string - isValid bool - errorMsg string + isValid bool + errorMsg string } DescribeTable("DID Validation tests", func(testCase TestCaseDIDStruct) { + err := testCase.did.Validate(testCase.allowedNamespaces) - err := testCase.did.Validate(testCase.allowedNamespaces) - - if testCase.isValid { - Expect(err).To(BeNil()) - } else { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) - } - }, + if testCase.isValid { + Expect(err).To(BeNil()) + } else { + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring(testCase.errorMsg)) + } + }, Entry( - "Did is valid", + "Did is valid", TestCaseDIDStruct{ did: &Did{ Id: ValidTestDID, @@ -44,8 +43,9 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: true, - errorMsg: ""}), + isValid: true, + errorMsg: "", + }), Entry( "DID is not allowed", @@ -62,8 +62,9 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: false, - errorMsg: "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).)."}), + isValid: false, + errorMsg: "id: unable to split did into method, namespace and id; verification_method: (0: (id: must have prefix: badDid.).).", + }), Entry( "Verification method is Ed25519VerificationKey2020", @@ -80,11 +81,12 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: true, - errorMsg: ""}), + isValid: true, + errorMsg: "", + }), Entry( - "Verification method is jwk", + "Verification method is jwk", TestCaseDIDStruct{ did: &Did{ Id: ValidTestDID, @@ -98,10 +100,11 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: true, - errorMsg: ""}), + isValid: true, + errorMsg: "", + }), - Entry("Verification method has wrong id", + Entry("Verification method has wrong id", TestCaseDIDStruct{ did: &Did{ Id: ValidTestDID, @@ -115,10 +118,11 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: false, - errorMsg: "verification_method: (0: (id: unable to split did into method, namespace and id.).)."}), + isValid: false, + errorMsg: "verification_method: (0: (id: unable to split did into method, namespace and id.).).", + }), Entry( - "Verification method has wrong controller", + "Verification method has wrong controller", TestCaseDIDStruct{ did: &Did{ Id: ValidTestDID, @@ -132,10 +136,11 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: false, - errorMsg: "verification_method: (0: (controller: unable to split did into method, namespace and id.).)."}), + isValid: false, + errorMsg: "verification_method: (0: (controller: unable to split did into method, namespace and id.).).", + }), Entry( - "List of DIDs in cotroller is allowed", + "List of DIDs in cotroller is allowed", TestCaseDIDStruct{ did: &Did{ Id: ValidTestDID, @@ -149,10 +154,11 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: true, - errorMsg: ""}), + isValid: true, + errorMsg: "", + }), Entry( - "List of DIDs in cotroller is not allowed", + "List of DIDs in cotroller is not allowed", TestCaseDIDStruct{ did: &Did{ Context: nil, @@ -167,10 +173,11 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: false, - errorMsg: "controller: (1: unable to split did into method, namespace and id.)."}), + isValid: false, + errorMsg: "controller: (1: unable to split did into method, namespace and id.).", + }), Entry( - "Namespace in controler is not in list of allowed", + "Namespace in controler is not in list of allowed", TestCaseDIDStruct{ did: &Did{ Id: ValidTestDID, @@ -185,10 +192,11 @@ var _ = Describe("DID Validation tests", func() { }, }, allowedNamespaces: []string{"mainnet"}, - isValid: false, - errorMsg: "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).)."}), + isValid: false, + errorMsg: "controller: (0: did namespace must be one of: mainnet.); id: did namespace must be one of: mainnet; verification_method: (0: (controller: did namespace must be one of: mainnet; id: did namespace must be one of: mainnet.).).", + }), Entry( - "Controller is duplicated", + "Controller is duplicated", TestCaseDIDStruct{ did: &Did{ Id: ValidTestDID, @@ -202,8 +210,9 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: false, - errorMsg: "controller: there should be no duplicates."}), + isValid: false, + errorMsg: "controller: there should be no duplicates.", + }), Entry( "Verification method is duplicated", TestCaseDIDStruct{ @@ -224,7 +233,8 @@ var _ = Describe("DID Validation tests", func() { }, }, }, - isValid: false, - errorMsg: "verification_method: there are verification method duplicates."}), + isValid: false, + errorMsg: "verification_method: there are verification method duplicates.", + }), ) }) diff --git a/x/cheqd/types/did_service_test.go b/x/cheqd/types/did_service_test.go index 6fdf18fe6..b7f2d4ff8 100644 --- a/x/cheqd/types/did_service_test.go +++ b/x/cheqd/types/did_service_test.go @@ -9,11 +9,11 @@ import ( var _ = Describe("Service tests", func() { type TestCaseServiceStruct struct { - service *Service - baseDid string + service *Service + baseDid string allowedNamespaces []string - isValid bool - errorMsg string + isValid bool + errorMsg string } DescribeTable("Service Validation tests", func(testCase TestCaseServiceStruct) { @@ -27,44 +27,44 @@ var _ = Describe("Service tests", func() { } }, - Entry( - "Positive case", - TestCaseServiceStruct{ - service: &Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - }, - baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", - allowedNamespaces: []string{""}, - isValid: true, - errorMsg: "", - }), + Entry( + "Positive case", + TestCaseServiceStruct{ + service: &Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + }, + baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", + allowedNamespaces: []string{""}, + isValid: true, + errorMsg: "", + }), - Entry( - "Namespace is not allowed", - TestCaseServiceStruct{ - service: &Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - }, - allowedNamespaces: []string{"mainnet"}, - isValid: false, - errorMsg: "id: did namespace must be one of: mainnet.", - }), + Entry( + "Namespace is not allowed", + TestCaseServiceStruct{ + service: &Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + }, + allowedNamespaces: []string{"mainnet"}, + isValid: false, + errorMsg: "id: did namespace must be one of: mainnet.", + }), - Entry( - "Base DID is not the same as in id", - TestCaseServiceStruct{ - service: &Service{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Type: "DIDCommMessaging", - ServiceEndpoint: "endpoint", - }, - baseDid: "did:cheqd:baaaaaaaaaaaaaab", - isValid: false, - errorMsg: "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab.", - }), + Entry( + "Base DID is not the same as in id", + TestCaseServiceStruct{ + service: &Service{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Type: "DIDCommMessaging", + ServiceEndpoint: "endpoint", + }, + baseDid: "did:cheqd:baaaaaaaaaaaaaab", + isValid: false, + errorMsg: "id: must have prefix: did:cheqd:baaaaaaaaaaaaaab.", + }), ) -}) \ No newline at end of file +}) diff --git a/x/cheqd/types/did_verification_method_test.go b/x/cheqd/types/did_verification_method_test.go index e2210402a..91d4f9cf6 100644 --- a/x/cheqd/types/did_verification_method_test.go +++ b/x/cheqd/types/did_verification_method_test.go @@ -18,15 +18,14 @@ import ( var _ = Describe("Verification Method tests", func() { type TestCaseVerificationMethodStruct struct { - vm VerificationMethod - baseDid string + vm VerificationMethod + baseDid string allowedNamespaces []string - isValid bool - errorMsg string + isValid bool + errorMsg string } DescribeTable("Verification Method Validation tests", func(testCase TestCaseVerificationMethodStruct) { - err := testCase.vm.Validate(testCase.baseDid, testCase.allowedNamespaces) if testCase.isValid { @@ -37,130 +36,130 @@ var _ = Describe("Verification Method tests", func() { } }, - Entry( - "Verification method with expected multibase key", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: nil, - PublicKeyMultibase: ValidEd25519PubKey, - }, - isValid: true, - errorMsg: "", - }), - - Entry( - "Verification method with expected jwk key", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, - isValid: true, - errorMsg: "", - }), - - Entry( - "Id has expected DID as a base", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, - baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", - isValid: true, - errorMsg: "", - }), - - Entry( - "Id does not have expected DID as a base", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, - baseDid: "did:cheqd:bbbbbbbbbbbbbbbb", - isValid: false, - errorMsg: "id: must have prefix: did:cheqd:bbbbbbbbbbbbbbbb.", - }), - - Entry( - "Namespace is allowed", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, - allowedNamespaces: []string{"mainnet", ""}, - isValid: true, - }), - - Entry( - "Namespace is not allowed", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, - allowedNamespaces: []string{"testnet"}, - isValid: false, - errorMsg: "controller: did namespace must be one of: testnet; id: did namespace must be one of: testnet.", - }), - Entry( - "JWK key has expected format", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: ValidPublicKeyJWK, - PublicKeyMultibase: "", - }, - isValid: true, - }), - Entry( - "JWK key has unexpected format", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: NotValidPublicKeyJWK, - PublicKeyMultibase: "", - }, - isValid: false, - errorMsg: "public_key_jwk: can't parse jwk: failed to parse key: invalid key type from JSON (SomeOtherKeyType).", - }), - Entry( - "Not all keys and valuesin JWK have expected format", - TestCaseVerificationMethodStruct{ - vm: VerificationMethod{ - Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", - Type: "JsonWebKey2020", - Controller: "did:cheqd:bbbbbbbbbbbbbbbb", - PublicKeyJwk: append(ValidPublicKeyJWK, &KeyValuePair{Key: "", Value: ""}), - PublicKeyMultibase: "", - }, - isValid: false, - errorMsg: "public_key_jwk: (6: (key: cannot be blank; value: cannot be blank.).).", - }), + Entry( + "Verification method with expected multibase key", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: nil, + PublicKeyMultibase: ValidEd25519PubKey, + }, + isValid: true, + errorMsg: "", + }), + + Entry( + "Verification method with expected jwk key", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, + isValid: true, + errorMsg: "", + }), + + Entry( + "Id has expected DID as a base", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, + baseDid: "did:cheqd:aaaaaaaaaaaaaaaa", + isValid: true, + errorMsg: "", + }), + + Entry( + "Id does not have expected DID as a base", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#rty", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, + baseDid: "did:cheqd:bbbbbbbbbbbbbbbb", + isValid: false, + errorMsg: "id: must have prefix: did:cheqd:bbbbbbbbbbbbbbbb.", + }), + + Entry( + "Namespace is allowed", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, + allowedNamespaces: []string{"mainnet", ""}, + isValid: true, + }), + + Entry( + "Namespace is not allowed", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:mainnet:aaaaaaaaaaaaaaaa#rty", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, + allowedNamespaces: []string{"testnet"}, + isValid: false, + errorMsg: "controller: did namespace must be one of: testnet; id: did namespace must be one of: testnet.", + }), + Entry( + "JWK key has expected format", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: ValidPublicKeyJWK, + PublicKeyMultibase: "", + }, + isValid: true, + }), + Entry( + "JWK key has unexpected format", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: NotValidPublicKeyJWK, + PublicKeyMultibase: "", + }, + isValid: false, + errorMsg: "public_key_jwk: can't parse jwk: failed to parse key: invalid key type from JSON (SomeOtherKeyType).", + }), + Entry( + "Not all keys and valuesin JWK have expected format", + TestCaseVerificationMethodStruct{ + vm: VerificationMethod{ + Id: "did:cheqd:aaaaaaaaaaaaaaaa#qwe", + Type: "JsonWebKey2020", + Controller: "did:cheqd:bbbbbbbbbbbbbbbb", + PublicKeyJwk: append(ValidPublicKeyJWK, &KeyValuePair{Key: "", Value: ""}), + PublicKeyMultibase: "", + }, + isValid: false, + errorMsg: "public_key_jwk: (6: (key: cannot be blank; value: cannot be blank.).).", + }), ) }) diff --git a/x/cheqd/types/tx_msg_create_did_test.go b/x/cheqd/types/tx_msg_create_did_test.go index b54d5a01b..e9b25fe21 100644 --- a/x/cheqd/types/tx_msg_create_did_test.go +++ b/x/cheqd/types/tx_msg_create_did_test.go @@ -9,8 +9,8 @@ import ( var _ = Describe("Message for DID creation", func() { type TestCaseMsgCreateDID struct { - msg *MsgCreateDid - isValid bool + msg *MsgCreateDid + isValid bool errorMsg string } @@ -25,46 +25,47 @@ var _ = Describe("Message for DID creation", func() { } }, - Entry( - "All fields are set properly", - TestCaseMsgCreateDID{ - msg: &MsgCreateDid{ - Payload: &MsgCreateDidPayload{ - Id: "did:cheqd:testnet:123456789abcdefg", - VerificationMethod: []*VerificationMethod{ - { - Id: "did:cheqd:testnet:123456789abcdefg#key1", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:testnet:123456789abcdefg", - PublicKeyMultibase: ValidEd25519PubKey, + Entry( + "All fields are set properly", + TestCaseMsgCreateDID{ + msg: &MsgCreateDid{ + Payload: &MsgCreateDidPayload{ + Id: "did:cheqd:testnet:123456789abcdefg", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:testnet:123456789abcdefg#key1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:testnet:123456789abcdefg", + PublicKeyMultibase: ValidEd25519PubKey, + }, }, + Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, }, - Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, + Signatures: nil, }, - Signatures: nil, - }, - isValid: true}), + isValid: true, + }), - Entry( - "IDs are duplicated", - TestCaseMsgCreateDID{ - msg: &MsgCreateDid{ - Payload: &MsgCreateDidPayload{ - Id: "did:cheqd:testnet:123456789abcdefg", - VerificationMethod: []*VerificationMethod{ - { - Id: "did:cheqd:testnet:123456789abcdefg#key1", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:testnet:123456789abcdefg", - PublicKeyMultibase: ValidEd25519PubKey, + Entry( + "IDs are duplicated", + TestCaseMsgCreateDID{ + msg: &MsgCreateDid{ + Payload: &MsgCreateDidPayload{ + Id: "did:cheqd:testnet:123456789abcdefg", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:testnet:123456789abcdefg#key1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:testnet:123456789abcdefg", + PublicKeyMultibase: ValidEd25519PubKey, + }, }, + Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#key1"}, }, - Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#key1"}, + Signatures: nil, }, - Signatures: nil, - }, - isValid: false, - errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", - }), + isValid: false, + errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", + }), ) }) diff --git a/x/cheqd/types/tx_msg_update_did_test.go b/x/cheqd/types/tx_msg_update_did_test.go index 0a24f35c3..a09267032 100644 --- a/x/cheqd/types/tx_msg_update_did_test.go +++ b/x/cheqd/types/tx_msg_update_did_test.go @@ -9,8 +9,8 @@ import ( var _ = Describe("Message for DID updating", func() { type TestCaseMsgUpdateDID struct { - msg *MsgUpdateDid - isValid bool + msg *MsgUpdateDid + isValid bool errorMsg string } @@ -25,70 +25,70 @@ var _ = Describe("Message for DID updating", func() { } }, - Entry( - "All fields are set properly", - TestCaseMsgUpdateDID{ - msg: &MsgUpdateDid{ - Payload: &MsgUpdateDidPayload{ - Id: "did:cheqd:testnet:123456789abcdefg", - VerificationMethod: []*VerificationMethod{ - { - Id: "did:cheqd:testnet:123456789abcdefg#key1", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:testnet:123456789abcdefg", - PublicKeyMultibase: ValidEd25519PubKey, + Entry( + "All fields are set properly", + TestCaseMsgUpdateDID{ + msg: &MsgUpdateDid{ + Payload: &MsgUpdateDidPayload{ + Id: "did:cheqd:testnet:123456789abcdefg", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:testnet:123456789abcdefg#key1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:testnet:123456789abcdefg", + PublicKeyMultibase: ValidEd25519PubKey, + }, }, + Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, + VersionId: "version1", }, - Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, - VersionId: "version1", + Signatures: nil, }, - Signatures: nil, - }, - isValid: true, - }), + isValid: true, + }), - Entry( - "IDs are duplicated", - TestCaseMsgUpdateDID{ - msg: &MsgUpdateDid{ - Payload: &MsgUpdateDidPayload{ - Id: "did:cheqd:testnet:123456789abcdefg", - VerificationMethod: []*VerificationMethod{ - { - Id: "did:cheqd:testnet:123456789abcdefg#key1", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:testnet:123456789abcdefg", - PublicKeyMultibase: ValidEd25519PubKey, + Entry( + "IDs are duplicated", + TestCaseMsgUpdateDID{ + msg: &MsgUpdateDid{ + Payload: &MsgUpdateDidPayload{ + Id: "did:cheqd:testnet:123456789abcdefg", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:testnet:123456789abcdefg#key1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:testnet:123456789abcdefg", + PublicKeyMultibase: ValidEd25519PubKey, + }, }, + Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#key1"}, + VersionId: "version1", }, - Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#key1"}, - VersionId: "version1", + Signatures: nil, }, - Signatures: nil, - }, - isValid: false, - errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", - }), - Entry( - "VersionId is empty", - TestCaseMsgUpdateDID{ - msg: &MsgUpdateDid{ - Payload: &MsgUpdateDidPayload{ - Id: "did:cheqd:testnet:123456789abcdefg", - VerificationMethod: []*VerificationMethod{ - { - Id: "did:cheqd:testnet:123456789abcdefg#key1", - Type: "Ed25519VerificationKey2020", - Controller: "did:cheqd:testnet:123456789abcdefg", - PublicKeyMultibase: ValidEd25519PubKey, + isValid: false, + errorMsg: "payload: (authentication: there should be no duplicates.).: basic validation failed", + }), + Entry( + "VersionId is empty", + TestCaseMsgUpdateDID{ + msg: &MsgUpdateDid{ + Payload: &MsgUpdateDidPayload{ + Id: "did:cheqd:testnet:123456789abcdefg", + VerificationMethod: []*VerificationMethod{ + { + Id: "did:cheqd:testnet:123456789abcdefg#key1", + Type: "Ed25519VerificationKey2020", + Controller: "did:cheqd:testnet:123456789abcdefg", + PublicKeyMultibase: ValidEd25519PubKey, + }, }, + Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, }, - Authentication: []string{"did:cheqd:testnet:123456789abcdefg#key1", "did:cheqd:testnet:123456789abcdefg#aaa"}, + Signatures: nil, }, - Signatures: nil, - }, - isValid: false, - errorMsg: "payload: (version_id: cannot be blank.).: basic validation failed", - }), + isValid: false, + errorMsg: "payload: (version_id: cannot be blank.).: basic validation failed", + }), ) }) diff --git a/x/cheqd/types/tx_sign_ingo_test.go b/x/cheqd/types/tx_sign_ingo_test.go index d78293eec..c3b154776 100644 --- a/x/cheqd/types/tx_sign_ingo_test.go +++ b/x/cheqd/types/tx_sign_ingo_test.go @@ -9,10 +9,10 @@ import ( var _ = Describe("SignInfo tests", func() { type TestCaseSignInfoStruct struct { - si SignInfo + si SignInfo allowedNamespaces []string - isValid bool - errorMsg string + isValid bool + errorMsg string } DescribeTable("SignInfo validation tests", func(testCase TestCaseSignInfoStruct) { @@ -26,46 +26,46 @@ var _ = Describe("SignInfo tests", func() { } }, - Entry( - "Positive case", - TestCaseSignInfoStruct{ - si: SignInfo{ - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", - }, - isValid: true, - errorMsg: "", - }), + Entry( + "Positive case", + TestCaseSignInfoStruct{ + si: SignInfo{ + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, + isValid: true, + errorMsg: "", + }), - Entry( - "Namespace is not allowed", - TestCaseSignInfoStruct{ - si: SignInfo{ - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Signature: "DIDCommMessaging", - }, - allowedNamespaces: []string{"mainnet"}, - isValid: false, - errorMsg: "verification_method_id: did namespace must be one of: mainnet.", - }), + Entry( + "Namespace is not allowed", + TestCaseSignInfoStruct{ + si: SignInfo{ + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Signature: "DIDCommMessaging", + }, + allowedNamespaces: []string{"mainnet"}, + isValid: false, + errorMsg: "verification_method_id: did namespace must be one of: mainnet.", + }), - Entry( - "Signature is not valid base64 string", - TestCaseSignInfoStruct{ - si: SignInfo{ - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", - Signature: "!@#", - }, - isValid: false, - errorMsg: "signature: must be encoded in Base64.", - }), + Entry( + "Signature is not valid base64 string", + TestCaseSignInfoStruct{ + si: SignInfo{ + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#service1", + Signature: "!@#", + }, + isValid: false, + errorMsg: "signature: must be encoded in Base64.", + }), ) }) var _ = Describe("Full SignInfo duplicates tests", func() { type TestCaseSignInfosStruct struct { - signInfos []*SignInfo - isValid bool + signInfos []*SignInfo + isValid bool } DescribeTable("SignInfo duplicates tests", func(testCase TestCaseSignInfosStruct) { @@ -73,72 +73,72 @@ var _ = Describe("Full SignInfo duplicates tests", func() { Expect(res_).To(Equal(testCase.isValid)) }, - Entry( - "Signatures are different", - TestCaseSignInfosStruct{ - signInfos: []*SignInfo{ - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", + Entry( + "Signatures are different", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "bbb=", + }, }, - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "bbb=", - }, - }, - isValid: true, - }), + isValid: true, + }), - Entry( - "All fields are different", - TestCaseSignInfosStruct{ - signInfos: []*SignInfo{ - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", - }, - { - VerificationMethodId: "did:cheqd:bbbbbbbbbbbbbbbb#method1", - Signature: "bbb=", + Entry( + "All fields are different", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, + { + VerificationMethodId: "did:cheqd:bbbbbbbbbbbbbbbb#method1", + Signature: "bbb=", + }, }, - }, - isValid: true, - }), + isValid: true, + }), - Entry( - "All fields are the same", - TestCaseSignInfosStruct{ - signInfos: []*SignInfo{ - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", - }, - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", + Entry( + "All fields are the same", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, }, - }, - isValid: false, - }), + isValid: false, + }), - Entry( - "All fields are the same and more elments", - TestCaseSignInfosStruct{ - signInfos: []*SignInfo{ - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", - }, - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", - }, - { - VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", - Signature: "aaa=", + Entry( + "All fields are the same and more elments", + TestCaseSignInfosStruct{ + signInfos: []*SignInfo{ + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, + { + VerificationMethodId: "did:cheqd:aaaaaaaaaaaaaaaa#method1", + Signature: "aaa=", + }, }, - }, - isValid: false, - }), + isValid: false, + }), ) }) From ad69f94029be0b15e158210d228b7a4b7c26aa3c Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 18 Oct 2022 17:02:53 +0300 Subject: [PATCH 51/76] Fix tests running command --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ba106cd2..595e045b1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: go get github.com/onsi/gomega/... - name: Run Ginkgo tests - run: go run ./ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml + run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml # - uses: mikepenz/action-junit-report@v3 # if: success() || failure() # run this step even if previous step failed From 09de4ee8bc022e8a242e7628f9378ca85945edd8 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 18 Oct 2022 17:17:47 +0300 Subject: [PATCH 52/76] debug --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 595e045b1..b93862f5e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,9 @@ jobs: go get github.com/onsi/ginkgo/v2/ginkgo go get github.com/onsi/gomega/... + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - name: Run Ginkgo tests run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml From 43f1f3e8baffc6f7b95154626ff5a902170b83e7 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Tue, 18 Oct 2022 17:41:03 +0300 Subject: [PATCH 53/76] Change ginkgo for installing --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b93862f5e..7242e93dc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: - name: Install ginkgo run: | - go get github.com/onsi/ginkgo/v2/ginkgo + go install github.com/onsi/ginkgo/v2/ginkgo go get github.com/onsi/gomega/... - name: Setup tmate session From d2350f82cfccb905a4841fde49c263d224fb67d5 Mon Sep 17 00:00:00 2001 From: Alexander Kolesov Date: Wed, 19 Oct 2022 12:28:50 +0300 Subject: [PATCH 54/76] Update dispatch.yml --- .github/workflows/dispatch.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 39f23005f..6844091db 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -25,7 +25,6 @@ jobs: call-release: name: "Release" needs: call-test - # needs: call-build if: ${{ github.ref_protected == true }} uses: ./.github/workflows/release.yml secrets: inherit From b4feefe30d1e37f22aa965e063fa3408beb731f2 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 13:29:14 +0300 Subject: [PATCH 55/76] Review comments --- .github/workflows/test.yml | 17 ++++++++--------- x/cheqd/tests/setup/config.go | 2 +- x/cheqd/tests/tests_suite_test.go | 2 +- x/cheqd/types/stateValue_test.go | 2 +- x/cheqd/utils/encoding_test.go | 12 ++++++------ x/resource/keeper/msg_server_create_resource.go | 3 +-- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1290bdc7c..d5740fbed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,14 +24,13 @@ jobs: cache: true - name: Install ginkgo - run: | - go install github.com/onsi/ginkgo/v2/ginkgo - go get github.com/onsi/gomega/... + working-directory: ./.. + run: go install github.com/onsi/ginkgo/v2/ginkgo@latest - # - name: Run Ginkgo tests - # run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml + - name: Run Ginkgo tests + run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml - # - uses: mikepenz/action-junit-report@v3 - # if: success() || failure() # run this step even if previous step failed - # with: - # report_paths: 'report.xml' + - uses: mikepenz/action-junit-report@v3 + if: success() || failure() # run this step even if previous step failed + with: + report_paths: 'report.xml' diff --git a/x/cheqd/tests/setup/config.go b/x/cheqd/tests/setup/config.go index 1cde54f21..debef10b7 100644 --- a/x/cheqd/tests/setup/config.go +++ b/x/cheqd/tests/setup/config.go @@ -1,3 +1,3 @@ package setup -const DID_NAMESPACE = "test" +const DID_NAMESPACE = "testnet" diff --git a/x/cheqd/tests/tests_suite_test.go b/x/cheqd/tests/tests_suite_test.go index eab13e53b..fb621a35f 100644 --- a/x/cheqd/tests/tests_suite_test.go +++ b/x/cheqd/tests/tests_suite_test.go @@ -9,5 +9,5 @@ import ( func TestTestsGeneral(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Cheqd Module") + RunSpecs(t, "Cheqd DID Module") } diff --git a/x/cheqd/types/stateValue_test.go b/x/cheqd/types/stateValue_test.go index eb2bbf477..8879a6d1a 100644 --- a/x/cheqd/types/stateValue_test.go +++ b/x/cheqd/types/stateValue_test.go @@ -15,7 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var _ = Describe(`StaeValue tests`, func() { +var _ = Describe(`StateValue tests`, func() { Context("Pack/unpack functionality", func() { It("should pack and unpack withour any errors", func() { original := &Did{ diff --git a/x/cheqd/utils/encoding_test.go b/x/cheqd/utils/encoding_test.go index 30edbd93b..b473dab4f 100644 --- a/x/cheqd/utils/encoding_test.go +++ b/x/cheqd/utils/encoding_test.go @@ -46,9 +46,9 @@ var _ = Describe("Encoding checks", func() { func(data string, isValid bool) { _err := ValidateMultibase(data) if isValid { - Ω(_err).ShouldNot(HaveOccurred()) + Expect(_err).ShouldNot(HaveOccurred()) } else { - Ω(_err).Should(HaveOccurred()) + Expect(_err).Should(HaveOccurred()) } }, @@ -64,9 +64,9 @@ var _ = Describe("Encoding checks", func() { func(data string, isValid bool) { _err := ValidateBase58(data) if isValid { - Ω(_err).ShouldNot(HaveOccurred()) + Expect(_err).ShouldNot(HaveOccurred()) } else { - Ω(_err).Should(HaveOccurred()) + Expect(_err).Should(HaveOccurred()) } }, @@ -80,9 +80,9 @@ var _ = Describe("Encoding checks", func() { func(data string, isValid bool) { _err := ValidateJWK(data) if isValid { - Ω(_err).ShouldNot(HaveOccurred()) + Expect(_err).ShouldNot(HaveOccurred()) } else { - Ω(_err).Should(HaveOccurred()) + Expect(_err).Should(HaveOccurred()) } }, diff --git a/x/resource/keeper/msg_server_create_resource.go b/x/resource/keeper/msg_server_create_resource.go index 14a3d1bad..211f10184 100644 --- a/x/resource/keeper/msg_server_create_resource.go +++ b/x/resource/keeper/msg_server_create_resource.go @@ -46,8 +46,7 @@ func (k msgServer) CreateResource(goCtx context.Context, msg *types.MsgCreateRes // Build Resource resource := msg.Payload.ToResource() - checksum := sha256.Sum256([]byte(resource.Data)) - resource.Header.Checksum = checksum[:] + resource.Header.Checksum = sha256.New().Sum(resource.Data) resource.Header.Created = ctx.BlockTime().Format(time.RFC3339) resource.Header.MediaType = utils.DetectMediaType(resource.Data) From 1a2b7e40c868ea4c177c789f3673a4dac88b506d Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 13:39:52 +0300 Subject: [PATCH 56/76] Add workaround for installing ginkgo --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5740fbed..89a10ca10 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,9 @@ jobs: - name: Install ginkgo working-directory: ./.. - run: go install github.com/onsi/ginkgo/v2/ginkgo@latest + run: | + cp cheqd-node/go.mod ./ + go install github.com/onsi/ginkgo/v2/ginkgo@latest - name: Run Ginkgo tests run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml From c9d947a6a4caf9558e45df75434f34d19ce69330 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 13:48:33 +0300 Subject: [PATCH 57/76] debug --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89a10ca10..37638a824 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,10 @@ jobs: working-directory: ./.. run: | cp cheqd-node/go.mod ./ - go install github.com/onsi/ginkgo/v2/ginkgo@latest + go install github.com/onsi/ginkgo/v2/ginkgo + + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 - name: Run Ginkgo tests run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml From 999292e091edee1bb7ac470959fcd9c6c66c19ab Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 13:54:59 +0300 Subject: [PATCH 58/76] debug --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37638a824..f82cf6c04 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,7 @@ jobs: working-directory: ./.. run: | cp cheqd-node/go.mod ./ + cp cheqd-node/go.sum ./ go install github.com/onsi/ginkgo/v2/ginkgo - name: Setup tmate session From 39cfcb3e35af86bfff9c522521b859af0071b1c1 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 14:03:56 +0300 Subject: [PATCH 59/76] Fix the version of ginkgo for CLI --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f82cf6c04..f1fa1c8a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,9 +26,7 @@ jobs: - name: Install ginkgo working-directory: ./.. run: | - cp cheqd-node/go.mod ./ - cp cheqd-node/go.sum ./ - go install github.com/onsi/ginkgo/v2/ginkgo + go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.6 - name: Setup tmate session uses: mxschmitt/action-tmate@v3 From 856b2cabf2aa93b0fd92f9db8a44487643a36332 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 14:15:25 +0300 Subject: [PATCH 60/76] Update ginkgo to the latest version --- .github/workflows/test.yml | 5 +---- go.mod | 5 ++++- go.sum | 8 ++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f1fa1c8a7..f6ae70035 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,10 +26,7 @@ jobs: - name: Install ginkgo working-directory: ./.. run: | - go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.6 - - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 + go install github.com/onsi/ginkgo/v2/ginkgo@latest - name: Run Ginkgo tests run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml diff --git a/go.mod b/go.mod index 19fa8d9d1..f2c1af9ee 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/lestrrat-go/jwx v1.2.25 github.com/multiformats/go-multibase v0.1.1 - github.com/onsi/ginkgo/v2 v2.1.6 + github.com/onsi/ginkgo/v2 v2.3.1 github.com/onsi/gomega v1.22.0 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.5.0 @@ -63,6 +63,7 @@ require ( github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/gateway v1.1.0 // indirect @@ -70,6 +71,7 @@ require ( github.com/google/btree v1.0.0 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/google/orderedcode v0.0.1 // indirect + github.com/google/pprof v0.0.0-20221010195024-131d412537ea // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect @@ -135,6 +137,7 @@ require ( golang.org/x/sys v0.0.0-20220727055044-e65921a090b8 // indirect golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect golang.org/x/text v0.3.7 // indirect + golang.org/x/tools v0.1.12 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.6 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 6f0daedad..1ad706386 100644 --- a/go.sum +++ b/go.sum @@ -284,6 +284,8 @@ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= @@ -366,6 +368,8 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20221010195024-131d412537ea h1:R3VfsTXMMK4JCWZDdxScmnTzu9n9YRsDvguLis0U/b8= +github.com/google/pprof v0.0.0-20221010195024-131d412537ea/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -601,6 +605,8 @@ github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU= github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk= +github.com/onsi/ginkgo/v2 v2.3.1 h1:8SbseP7qM32WcvE6VaN6vfXxv698izmsJ1UQX9ve7T8= +github.com/onsi/ginkgo/v2 v2.3.1/go.mod h1:Sv4yQXwG5VmF7tm3Q5Z+RWUpPo24LF1mpnz2crUb8Ys= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= @@ -1114,6 +1120,8 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 4e3c8e79ab0a73838dea7b9bce7110598729afe4 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 14:28:40 +0300 Subject: [PATCH 61/76] Add token for JUnit --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6ae70035..22ccbc4c5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,3 +35,4 @@ jobs: if: success() || failure() # run this step even if previous step failed with: report_paths: 'report.xml' + token: ${{ secrets.GITHUB_TOKEN }} From 2a5dd07dc297a6b45d2bab33a9f8205f817c7ec5 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 18:59:45 +0300 Subject: [PATCH 62/76] Move to another access token --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 22ccbc4c5..f6090e270 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,4 +35,4 @@ jobs: if: success() || failure() # run this step even if previous step failed with: report_paths: 'report.xml' - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GH_PAT }} From 97da98b58d162356f9fa5dbc8b4ab5bc41ad86d1 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 19:31:17 +0300 Subject: [PATCH 63/76] Add template for report files --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6090e270..90e2da6d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,10 +29,10 @@ jobs: go install github.com/onsi/ginkgo/v2/ginkgo@latest - name: Run Ginkgo tests - run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml + run: ginkgo -r --race --randomize-all --randomize-suites --junit-report report.xml --json-report=report.json - uses: mikepenz/action-junit-report@v3 if: success() || failure() # run this step even if previous step failed with: - report_paths: 'report.xml' + report_paths: 'report*' token: ${{ secrets.GH_PAT }} From a0308c692680d41d5da560f064a6b10c31d8130c Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 19:44:26 +0300 Subject: [PATCH 64/76] Debug --- .github/workflows/dispatch.yml | 14 +++++++------- .github/workflows/test.yml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 15f64f143..7646bb1e5 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -7,14 +7,14 @@ concurrency: jobs: - call-lint: - name: "Lint" - uses: ./.github/workflows/lint.yml + # call-lint: + # name: "Lint" + # uses: ./.github/workflows/lint.yml - call-build: - name: "Build" - needs: call-lint - uses: ./.github/workflows/build.yml + # call-build: + # name: "Build" + # needs: call-lint + # uses: ./.github/workflows/build.yml call-test: name: "Test" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90e2da6d4..f751605cc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,5 +34,5 @@ jobs: - uses: mikepenz/action-junit-report@v3 if: success() || failure() # run this step even if previous step failed with: - report_paths: 'report*' + report_paths: 'report.xml' token: ${{ secrets.GH_PAT }} From f9bce78ca9a8a65bb48992a18b4ec91ab9917871 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 19:47:08 +0300 Subject: [PATCH 65/76] Debug --- .github/workflows/dispatch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 7646bb1e5..9a960d597 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -18,7 +18,7 @@ jobs: call-test: name: "Test" - needs: call-build + # needs: call-build uses: ./.github/workflows/test.yml secrets: inherit From 6d412c6579ac0710e290b9b3001b8a8e12ff06ae Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Wed, 19 Oct 2022 20:03:59 +0300 Subject: [PATCH 66/76] Debug --- .github/workflows/dispatch.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 9a960d597..2107d062d 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -22,9 +22,9 @@ jobs: uses: ./.github/workflows/test.yml secrets: inherit - call-release: - name: "Release" - needs: [call-build, call-test] - if: ${{ github.ref_protected == true }} - uses: ./.github/workflows/release.yml - secrets: inherit + # call-release: + # name: "Release" + # needs: [call-build, call-test] + # if: ${{ github.ref_protected == true }} + # uses: ./.github/workflows/release.yml + # secrets: inherit From 9b0b6556ac760ff6bd43b9c4eac484170a3ce3b9 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 10:39:09 +0300 Subject: [PATCH 67/76] Debug --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f751605cc..4633de335 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,4 +35,4 @@ jobs: if: success() || failure() # run this step even if previous step failed with: report_paths: 'report.xml' - token: ${{ secrets.GH_PAT }} + token: ${{ secrets.GITHUB_TOKEN }} From 3e7d143670f7eda9fcf780349984ce49c105d38a Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 10:43:09 +0300 Subject: [PATCH 68/76] Add permissions for checks --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4633de335..5587b749d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,7 @@ env: permissions: contents: write packages: read + checks: write jobs: unit-tests: From e847ffc6a60249c65b1aed999679d679d3bbf4cb Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 10:47:21 +0300 Subject: [PATCH 69/76] Check fails --- x/cheqd/types/did_verification_method_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/cheqd/types/did_verification_method_test.go b/x/cheqd/types/did_verification_method_test.go index 91d4f9cf6..845082f05 100644 --- a/x/cheqd/types/did_verification_method_test.go +++ b/x/cheqd/types/did_verification_method_test.go @@ -47,7 +47,7 @@ var _ = Describe("Verification Method tests", func() { PublicKeyMultibase: ValidEd25519PubKey, }, isValid: true, - errorMsg: "", + errorMsg: "123", }), Entry( From 7f0138dd2e3de5ba6e287c4f3099ef4732ee6d42 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 10:52:43 +0300 Subject: [PATCH 70/76] Check failure case --- x/cheqd/types/did_verification_method_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/cheqd/types/did_verification_method_test.go b/x/cheqd/types/did_verification_method_test.go index 845082f05..ce12e03e1 100644 --- a/x/cheqd/types/did_verification_method_test.go +++ b/x/cheqd/types/did_verification_method_test.go @@ -46,7 +46,7 @@ var _ = Describe("Verification Method tests", func() { PublicKeyJwk: nil, PublicKeyMultibase: ValidEd25519PubKey, }, - isValid: true, + isValid: false, errorMsg: "123", }), From d612273164520e9fb276bb96641650e16123846a Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 11:04:20 +0300 Subject: [PATCH 71/76] MAke it more verbose --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5587b749d..8ba41ca79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,3 +37,6 @@ jobs: with: report_paths: 'report.xml' token: ${{ secrets.GITHUB_TOKEN }} + suite_regex: '*' + include_passed: true + detailed_summary: true From 4755fa0744747e1d6c3b7f792f1271d408c53319 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 11:11:49 +0300 Subject: [PATCH 72/76] Move test back --- x/cheqd/types/did_verification_method_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/cheqd/types/did_verification_method_test.go b/x/cheqd/types/did_verification_method_test.go index ce12e03e1..91d4f9cf6 100644 --- a/x/cheqd/types/did_verification_method_test.go +++ b/x/cheqd/types/did_verification_method_test.go @@ -46,8 +46,8 @@ var _ = Describe("Verification Method tests", func() { PublicKeyJwk: nil, PublicKeyMultibase: ValidEd25519PubKey, }, - isValid: false, - errorMsg: "123", + isValid: true, + errorMsg: "", }), Entry( From 6a8f772149a54ede79220b7cfec120cb51023bff Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 11:31:52 +0300 Subject: [PATCH 73/76] Try JSON reporter --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ba41ca79..aa01ddec9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,3 +40,11 @@ jobs: suite_regex: '*' include_passed: true detailed_summary: true + + - uses: dorny/test-reporter@v1 + if: success() || failure() # run this step even if previous step failed + with: + name: JSON reports # Name of the check run which will be created + path: 'report.json' # Path to test results + reporter: mocha-json + token: ${{ secrets.GITHUB_TOKEN }} From 264555ae4d71ad601acf51550965a53521e6e3dc Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 11:36:35 +0300 Subject: [PATCH 74/76] Try flutter reporter --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa01ddec9..2463df2fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,5 +46,5 @@ jobs: with: name: JSON reports # Name of the check run which will be created path: 'report.json' # Path to test results - reporter: mocha-json + reporter: flutter-json token: ${{ secrets.GITHUB_TOKEN }} From ff71c576088166b482848cf1221a530f38135c1b Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 11:40:22 +0300 Subject: [PATCH 75/76] Try dart JSON reporter --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2463df2fc..caabb0fea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,5 +46,5 @@ jobs: with: name: JSON reports # Name of the check run which will be created path: 'report.json' # Path to test results - reporter: flutter-json + reporter: dart-json token: ${{ secrets.GITHUB_TOKEN }} From bd20ed8ab482f532a86648b946f866d7eee2f713 Mon Sep 17 00:00:00 2001 From: Andrew Nikitin Date: Thu, 20 Oct 2022 11:46:55 +0300 Subject: [PATCH 76/76] Keep only JUnit reports --- .github/workflows/dispatch.yml | 28 ++++++++++++++-------------- .github/workflows/test.yml | 8 -------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 2107d062d..15f64f143 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -7,24 +7,24 @@ concurrency: jobs: - # call-lint: - # name: "Lint" - # uses: ./.github/workflows/lint.yml + call-lint: + name: "Lint" + uses: ./.github/workflows/lint.yml - # call-build: - # name: "Build" - # needs: call-lint - # uses: ./.github/workflows/build.yml + call-build: + name: "Build" + needs: call-lint + uses: ./.github/workflows/build.yml call-test: name: "Test" - # needs: call-build + needs: call-build uses: ./.github/workflows/test.yml secrets: inherit - # call-release: - # name: "Release" - # needs: [call-build, call-test] - # if: ${{ github.ref_protected == true }} - # uses: ./.github/workflows/release.yml - # secrets: inherit + call-release: + name: "Release" + needs: [call-build, call-test] + if: ${{ github.ref_protected == true }} + uses: ./.github/workflows/release.yml + secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index caabb0fea..8ba41ca79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,11 +40,3 @@ jobs: suite_regex: '*' include_passed: true detailed_summary: true - - - uses: dorny/test-reporter@v1 - if: success() || failure() # run this step even if previous step failed - with: - name: JSON reports # Name of the check run which will be created - path: 'report.json' # Path to test results - reporter: dart-json - token: ${{ secrets.GITHUB_TOKEN }}