Skip to content

Commit

Permalink
add testv cov action (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrathyushaLakkireddy authored Apr 11, 2022
1 parent b3b9e0d commit f1ee310
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 10 deletions.
24 changes: 24 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
version: v1.43
args: --timeout 10m --build-tags sdk_${{ matrix.versions }}
github-token: ${{ secrets.TENDERBOT_GIT_TOKEN }}
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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 ./...
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion cmd/sdk_utilities-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
}
11 changes: 7 additions & 4 deletions grpc_cosmos_sdk_v42.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 9 additions & 5 deletions grpc_cosmos_sdk_v44.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f1ee310

Please sign in to comment.