diff --git a/.github/workflows/automated-tests.yml b/.github/workflows/automated-tests.yml deleted file mode 100644 index f7d9988bad..0000000000 --- a/.github/workflows/automated-tests.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: Automated Tests -on: - push: - branches: - - main - - release/v* - - feat/* - pull_request: - branches: - - main - - release/v* - - feat/* -jobs: - Automated_Tests: - runs-on: ubuntu-latest - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 - with: - lfs: true - - name: Checkout LFS objects - run: git lfs checkout - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" # The Go version to download (if necessary) and use. - - name: Proto Check - run: make proto-check - - name: Unit, integration and difference tests - run: go test ./... - E2E_Tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - lfs: true - - name: Checkout LFS objects - run: git lfs checkout - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - name: E2E tests - run: make test-e2e-short - Cometmock_Tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - lfs: true - - name: Checkout LFS objects - run: git lfs checkout - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - name: E2E tests - run: make test-e2e-short-cometmock - Trace-Tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - lfs: true - - name: Checkout LFS objects - run: git lfs checkout - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - - name: E2E tests - run: make test-trace diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index a812b9fcf2..0000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Build -on: - push: - branches: - - main - - feat/* - pull_request: - types: [opened, synchronize, reopened] -jobs: - sonarcloud: - # skip this on forks or dependabot PRs - name: SonarCloud - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - lfs: true - - name: Checkout LFS objects - run: git lfs checkout - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" # The Go version to download (if necessary) and use. - - name: Test with coverage - run: go test -coverpkg=./x/... -coverprofile=coverage.out ./... - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - if: env.SONAR_TOKEN != null diff --git a/.github/workflows/gosec.yml b/.github/workflows/gosec.yml index 80dc4a3689..d01bfd37f4 100644 --- a/.github/workflows/gosec.yml +++ b/.github/workflows/gosec.yml @@ -9,7 +9,7 @@ on: - main - feat/* jobs: - tests: + Gosec: runs-on: ubuntu-latest env: GO111MODULE: on diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..efd2860398 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,239 @@ +name: Test +on: + workflow_call: + pull_request: + push: + branches: + - main + - release/v* + - feat/* + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }}-tests + cancel-in-progress: true + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + check-latest: true + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.proto + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + **/Makefile + Makefile + - uses: actions/cache@v3.3.2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }} + restore-keys: | + ${{ runner.os }}-go- + - name: proto check + run: make proto-check + - name: test & coverage report creation + if: env.GIT_DIFF + run: | + make test-unit-cov + - uses: actions/upload-artifact@v3 + if: env.GIT_DIFF + with: + name: "${{ github.sha }}-coverage" + path: ./profile.out + + test-integration: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + check-latest: true + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + **/Makefile + Makefile + - name: integration tests + if: env.GIT_DIFF + run: | + make test-integration-cov + - uses: actions/upload-artifact@v3 + if: env.GIT_DIFF + with: + name: "${{ github.sha }}-integration-coverage" + path: ./integration-profile.out + + test-difference: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + check-latest: true + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + **/Makefile + Makefile + - name: difference tests + if: env.GIT_DIFF + run: | + make test-difference-cov + - uses: actions/upload-artifact@v3 + if: env.GIT_DIFF + with: + name: "${{ github.sha }}-difference-coverage" + path: ./difference-profile.out + + repo-analysis: + runs-on: ubuntu-latest + needs: [tests, test-integration, test-difference] + steps: + - uses: actions/checkout@v4 + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + - uses: actions/download-artifact@v3 + if: env.GIT_DIFF + with: + name: "${{ github.sha }}-coverage" + - uses: actions/download-artifact@v3 + if: env.GIT_DIFF + with: + name: "${{ github.sha }}-integration-coverage" + - uses: actions/download-artifact@v3 + if: env.GIT_DIFF + with: + name: "${{ github.sha }}-difference-coverage" + continue-on-error: true + - name: sonarcloud + if: ${{ env.GIT_DIFF && !github.event.pull_request.draft }} + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + test-e2e: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: checkout LFS objects + run: git lfs checkout + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + check-latest: true + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + **/Makefile + Makefile + - name: e2e tests + run: make test-e2e-short + + test-cometmock: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: checkout LFS objects + run: git lfs checkout + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + check-latest: true + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + **/Makefile + Makefile + - name: cometmock tests + run: make test-e2e-short-cometmock + + test-trace: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: checkout LFS objects + run: git lfs checkout + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + check-latest: true + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + **/Makefile + Makefile + - name: trace-e2e tests + run: make test-trace diff --git a/Makefile b/Makefile index a614e3bea0..33420f4c4e 100644 --- a/Makefile +++ b/Makefile @@ -10,25 +10,36 @@ install: go.sum go install $(BUILD_FLAGS) ./cmd/interchain-security-sd # run all tests: unit, integration, diff, and E2E -test: - go test ./... && go run ./tests/e2e/... +test: test-unit test-integration test-difference test-e2e -# run all unit tests +# shortcut for local development +test-dev: test-unit test-integration test-difference + +# run unit tests test-unit: - go test ./... + go test ./x/... ./app/... + +test-unit-cov: + go test ./x/... ./app/... -coverpkg=./... -coverprofile=profile.out -covermode=atomic # run unit and integration tests -test-short: - go test ./x/... ./app/... ./tests/integration/... +test-integration: + go test ./tests/integration/... -timeout 30m + +test-integration-cov: + go test ./tests/integration/... -timeout 30m -coverpkg=./... -coverprofile=integration-profile.out -covermode=atomic + +# run difference tests +test-difference: + go test ./tests/difference/... -timeout 30m + +test-difference-cov: + go test ./tests/difference/... -timeout 30m -coverpkg=./... -coverprofile=difference-profile.out -covermode=atomic # run E2E tests test-e2e: go run ./tests/e2e/... -# run difference tests -test-diff: - go test ./tests/difference/... - # run only happy path E2E tests test-e2e-short: go run ./tests/e2e/... --tc happy-path diff --git a/TESTING.md b/TESTING.md index 4c288f5136..40117f9127 100644 --- a/TESTING.md +++ b/TESTING.md @@ -29,15 +29,24 @@ Tests can be run using `make`: # run unit, integration, diff, and E2E tests make test -# run unit and integration tests - prefer this for local development -make test-short +# run unit tests +make test-unit + +# run integration tests +make test-integration # run difference tests -make test-diff +make test-difference + +# run unit, integration, and difference tests - shortcut for local development +mate test-dev # run E2E tests make test-e2e +# run only happy path E2E tests +make test-e2e-short + # equivalent to make test with caching disabled make test-no-cache ``` diff --git a/sonar-project.properties b/sonar-project.properties index 34d8d28397..d845247826 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=cosmos_interchain-security sonar.organization=cosmos # This is the name and version displayed in the SonarCloud UI. -#sonar.projectName=interchain-security +sonar.projectName=Interchain Security #sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. @@ -14,10 +14,10 @@ sonar.organization=cosmos # All golang artifacts sonar.sources=. # Do not calculate coverage metrics for statements in these files -sonar.exclusions=**/vendor/**,**/*.pb.go,**/*.pb.gw.go,proto,**/*_test.go,tests/**,testutil/**,legacy_ibc_testing/**,docs/**,app/**,cmd/**, +sonar.exclusions=**/vendor/**,**/*.pb.go,**/*.pb.gw.go,proto,**/*_test.go,tests/**,testutil/**,docs/**,app/**,cmd/**, sonar.tests=. # Run unit and integration tests, but not E2E tests sonar.test.inclusions=**/*_test.go # Do not run any vendor tests sonar.test.exclusions=**/vendor/** -sonar.go.coverage.reportPaths=coverage.out +sonar.go.coverage.reportPaths=coverage.out,*profile.out