diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..61a8dfa --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,24 @@ +# +# This codecov.yml is the default configuration for +# all repositories on Codecov. You may adjust the settings +# below in your own codecov.yml in your repository. +# +coverage: + precision: 2 + round: down + range: 70...100 + + status: + # Learn more at https://codecov.io/docs#yaml_default_commit_status + status: #Code coverage status will be posted to pull requests based on targets defined below. + diff: #diff coverage is code coverage only for the lines changed in a pull request. + target: 20% + + project: + default: + threshold: 1% # allow this much decrease on project + changes: false + +comment: + layout: "header, diff, flags" + behavior: default # update if exists else create new diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..cf9018e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,50 @@ +name: Lint +on: + pull_request: +permissions: + contents: read +env: + GOPRIVATE: "github.com/allinbits/*" + +jobs: + setup-matrix: + runs-on: self-hosted + steps: + - uses: actions/checkout@v2 + - name: Setup matrix combinations + id: setup-matrix-combinations + run: | + MATRIX_PARAMS_COMBINATIONS="$(make versions-json)" + echo ::set-output name=matrix-combinations::{\"include\":$MATRIX_PARAMS_COMBINATIONS} + outputs: + matrix-combinations: ${{ steps.setup-matrix-combinations.outputs.matrix-combinations }} + + golangci: + name: lint + runs-on: self-hosted + needs: setup-matrix + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix-combinations) }} + timeout-minutes: 10 + steps: + - uses: actions/checkout@v2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Configure git for private modules + env: + GIT_TOKEN: ${{ secrets.TENDERBOT_GIT_TOKEN }} + run: git config --global url."https://git:${GIT_TOKEN}@github.com".insteadOf "https://github.com" + + - name: Setup multisdk + run: make setup-${{ matrix.versions }} + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3.1.0 + with: + version: v1.43 + args: --timeout 10m --build-tags sdk_${{ matrix.versions }} + github-token: ${{ secrets.TENDERBOT_GIT_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2a2c24a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,55 @@ +name: Tests + +on: + workflow_dispatch: + pull_request: + push: + +env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} +jobs: + setup-matrix: + runs-on: self-hosted + steps: + - uses: actions/checkout@v2 + - name: Setup matrix combinations + id: setup-matrix-combinations + run: | + MATRIX_PARAMS_COMBINATIONS="$(make versions-json)" + echo ::set-output name=matrix-combinations::{\"include\":$MATRIX_PARAMS_COMBINATIONS} + outputs: + matrix-combinations: ${{ steps.setup-matrix-combinations.outputs.matrix-combinations }} + + code_cov: + runs-on: self-hosted + needs: setup-matrix + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix-combinations) }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 2 + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Setup token for pulling from allinbits private repos + run: | + go env -w GOPRIVATE=github.com/allinbits/* + go env -w GOPROXY=direct + git config --global url."https://git:${{ secrets.TENDERBOT_GIT_TOKEN }}@github.com".insteadOf "https://github.com" + - name: Setup multisdk + run: make setup-${{ matrix.versions }} + + - name: Run Tests + run: make test-${{ matrix.versions }} + + - name: Run coverage + run: make coverage-${{ matrix.versions }} + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + file: coverage.out \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..8e36312 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,58 @@ +run: + tests: false + timeout: 5m + skip-dirs: + - github.com/allinbits/starport-operator/* + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + - errcheck + - goconst + - gocritic + - gofmt + - goimports + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nakedret + - prealloc + - exportloopref + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unused + - varcheck + +issues: + exclude-rules: + - text: "ST1003:" + linters: + - stylecheck + +linters-settings: + dogsled: + max-blank-identifiers: 3 + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0 + prealloc: + # XXX: we don't recommend using this linter before doing performance profiling. + # For most programs usage of prealloc will be a premature optimization. + + # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. + # True by default. + simple: false + range-loops: true # Report preallocation suggestions on range loops, true by default + for-loops: true # Report preallocation suggestions on for loops, false by default \ No newline at end of file diff --git a/Makefile b/Makefile index 7b445d8..799b080 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ SHELL := /usr/bin/env bash SETUP_VERSIONS := $(shell jq -r '.versions|map("setup-\(.)")[]' ${TARGETS}) BUILD_VERSIONS := $(shell jq -r '.versions|map("build-\(.)")[]' ${TARGETS}) STORE_MOD_VERSIONS := $(shell jq -r '.versions|map("store-mod-\(.)")[]' ${TARGETS}) +TEST_VERSIONS = $(shell jq -r '.versions|map("test-\(.)")[]' ${TARGETS}) +COVERAGE_VERSIONS = $(shell jq -r '.versions|map("coverage-\(.)")[]' ${TARGETS}) BRANCH := $(shell git rev-parse --abbrev-ref HEAD) COMMIT := $(shell git log -1 --format='%H') @@ -51,3 +53,15 @@ versions-json: $(STORE_MOD_VERSIONS): cp ./go.mod mods/go.mod.$(shell echo $@ | sed 's/store-mod-//g') cp ./go.sum mods/go.sum.$(shell echo $@ | sed 's/store-mod-//g') + +$(TEST_VERSIONS): + go test -v -failfast -race -count=1 \ + -tags $(shell echo $@ | sed -e 's/test-/sdk_/g' -e 's/-/_/g'),muslc \ + ./... + +$(COVERAGE_VERSIONS): + go test -v -failfast -coverprofile=coverage.out -covermode=atomic -count=1\ + -tags $(shell echo $@ | sed -e 's/coverage-/sdk_/g' -e 's/-/_/g'),muslc \ + ./... +lint: + golangci-lint run ./... diff --git a/README.md b/README.md new file mode 100644 index 0000000..9d920f5 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# sdk-service + +[![codecov](https://codecov.io/gh/allinbits/sdk-service/branch/main/graph/badge.svg?token=AXDASRALWG)](https://codecov.io/gh/allinbits/sdk-service) +[![Build status](https://github.com/allinbits/sdk-service/workflows/Build/badge.svg)](https://github.com/allinbits/sdk-service/commits/main) +[![Tests status](https://github.com/allinbits/sdk-service/workflows/Tests/badge.svg)](https://github.com/allinbits/sdk-service/commits/main) +[![Lint](https://github.com/allinbits/sdk-service/workflows/Lint/badge.svg?token)](https://github.com/allinbits/sdk-service/commits/main) \ No newline at end of file diff --git a/cmd/sdk_utilities-cli/main.go b/cmd/sdk_utilities-cli/main.go index d6c0bcc..fd368ba 100644 --- a/cmd/sdk_utilities-cli/main.go +++ b/cmd/sdk_utilities-cli/main.go @@ -118,5 +118,5 @@ func indent(s string) string { if s == "" { return "" } - return " " + strings.Replace(s, "\n", "\n ", -1) + return " " + strings.ReplaceAll(s, "\n", "\n ") } diff --git a/grpc_cosmos_sdk_v42.go b/grpc_cosmos_sdk_v42.go index d1875c1..12f2863 100644 --- a/grpc_cosmos_sdk_v42.go +++ b/grpc_cosmos_sdk_v42.go @@ -40,7 +40,10 @@ var ( ) const ( - transferMsgType = "transfer" + // TODO : this can be used used once relvant code was uncommented + // transferMsgType = "transfer" + + emoneyChainName = "emoney" ) func initCodec() { @@ -328,7 +331,7 @@ func LiquidityPools(chainName string, port *int) (sdkutilities.LiquidityPools2, } func MintInflation(chainName string, port *int) (sdkutilities.MintInflation2, error) { - if chainName == "emoney" { + if chainName == emoneyChainName { // emoney inflation is different from the traditional cosmos sdk inflation, // and does not have an annualprovisions endpoint. Instead it uses a flat inflation // rate provided in the endpoint. @@ -368,7 +371,7 @@ func MintInflation(chainName string, port *int) (sdkutilities.MintInflation2, er } func MintParams(chainName string, port *int) (sdkutilities.MintParams2, error) { - if chainName == "emoney" { + if chainName == emoneyChainName { // emoney inflation is different from the traditional cosmos sdk inflation, // and does not have an annualprovisions endpoint. Instead it uses a flat inflation // rate provided in the endpoint. @@ -407,7 +410,7 @@ func MintParams(chainName string, port *int) (sdkutilities.MintParams2, error) { } func MintAnnualProvision(chainName string, port *int) (sdkutilities.MintAnnualProvision2, error) { - if chainName == "emoney" { + if chainName == emoneyChainName { // emoney inflation is different from the traditional cosmos sdk inflation, // and does not have an annualprovisions endpoint. Instead it uses a flat inflation // rate provided in the endpoint. diff --git a/grpc_cosmos_sdk_v44.go b/grpc_cosmos_sdk_v44.go index ac6da3d..7dc8b64 100644 --- a/grpc_cosmos_sdk_v44.go +++ b/grpc_cosmos_sdk_v44.go @@ -46,7 +46,10 @@ var ( ) const ( - transferMsgType = "transfer" + // TODO : this can be used used once relvant code was uncommented + // transferMsgType = "transfer" + + junoChainName = "juno" ) func initCodec() { @@ -361,7 +364,7 @@ func MintInflation(chainName string, port *int) (sdkutilities.MintInflation2, er }() // Juno has a custom mint module - if chainName == "juno" { + if chainName == junoChainName { mq := junomint.NewQueryClient(grpcConn) resp, err := mq.Inflation(context.Background(), &junomint.QueryInflationRequest{}) @@ -463,7 +466,7 @@ func MintParams(chainName string, port *int) (sdkutilities.MintParams2, error) { }() // Juno has a custom mint module - if chainName == "juno" { + if chainName == junoChainName { mq := junomint.NewQueryClient(grpcConn) resp, err := mq.Params(context.Background(), &junomint.QueryParamsRequest{}) @@ -557,7 +560,7 @@ func MintAnnualProvision(chainName string, port *int) (sdkutilities.MintAnnualPr _ = grpcConn.Close() }() - if chainName == "juno" { + if chainName == junoChainName { mq := junomint.NewQueryClient(grpcConn) resp, err := mq.AnnualProvisions(context.Background(), &junomint.QueryAnnualProvisionsRequest{}) @@ -880,7 +883,8 @@ func computeTax(endpointName string, txBytes []byte) ([]*sdkutilities.Coin, erro return nil, fmt.Errorf("cannot decode terra computeTax response, %w", err) } - var coins []*sdkutilities.Coin + coins := make([]*sdkutilities.Coin, len(rawTax.TaxAmount)) + for _, coin := range rawTax.TaxAmount { coins = append(coins, &sdkutilities.Coin{ Denom: coin.Denom,