diff --git a/.github/workflows/actions.yaml b/.github/workflows/actions.yaml index cd3897a..c7490f9 100644 --- a/.github/workflows/actions.yaml +++ b/.github/workflows/actions.yaml @@ -30,3 +30,19 @@ jobs: uses: golangci/golangci-lint-action@v2 with: args: --timeout 300s + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v2 + with: + go-version: '1.21.3' + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Run tests + run: go test -coverpkg=./... -coverprofile coverage.txt -v ./... + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: QuokkaStake/cosmos-validators-exporter diff --git a/.gitignore b/.gitignore index 47e626f..1bf2b5f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ config*.toml cosmos-validators-exporter .idea/ dist/ +cover.out diff --git a/Makefile b/Makefile index b5cdca7..d81865f 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,9 @@ install: lint: golangci-lint run --fix ./... + +test: + go test -coverpkg=./... -coverprofile cover.out -v ./... + +coverage: + go tool cover -html=cover.out diff --git a/pkg/generators/balance_test.go b/pkg/generators/balance_test.go new file mode 100644 index 0000000..80f88fb --- /dev/null +++ b/pkg/generators/balance_test.go @@ -0,0 +1,40 @@ +package generators + +import ( + "main/pkg/constants" + "main/pkg/fetchers" + statePkg "main/pkg/state" + "main/pkg/types" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBalanceGeneratorNoState(t *testing.T) { + t.Parallel() + + state := statePkg.NewState() + generator := NewBalanceGenerator() + results := generator.Generate(state) + assert.Empty(t, results) +} + +func TestBlockSetValidators(t *testing.T) { + t.Parallel() + + state := statePkg.NewState() + state.Set(constants.FetcherNameBalance, fetchers.BalanceData{ + Balances: map[string]map[string][]types.Amount{ + "chain": { + "validator": { + {Amount: 100, Denom: "uatom"}, + {Amount: 200, Denom: "ustake"}, + }, + }, + }, + }) + + generator := NewBalanceGenerator() + results := generator.Generate(state) + assert.NotEmpty(t, results) +}