Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Dec 4, 2023
1 parent e6c2b69 commit f918b59
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 38 deletions.
26 changes: 22 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
push:
branches:
- main
paths-ignore:
- tests/**

permissions:
contents: read
Expand All @@ -16,7 +14,7 @@ concurrency:
cancel-in-progress: true

jobs:
test:
test-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -35,4 +33,24 @@ jobs:
- name: tests
if: env.GIT_DIFF
run: |
make test
make test-unit
test-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.21.4
cache: true
cache-dependency-path: go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
**/*.go
go.mod
go.sum
- name: tests
if: env.GIT_DIFF
run: |
make test-integration
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ test-e2e: $(TEST_E2E_DEPS)
@echo "Running e2e tests..."
@go test ./tests/e2e/e2e_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_E2E_TAGS)'

test:
test-unit:
@go test -v -race $(shell go list ./... | grep -v tests/)

## test-cover: Run the unit tests and create a coverage html report
test-integration:
@go test -v -race ./tests/integration

test-cover:
@echo Running unit tests and creating coverage report...
@go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE) -covermode=atomic $(shell go list ./... | grep -v tests/ | grep -v api/ | grep -v testutils/)
Expand All @@ -138,8 +140,9 @@ test-cover:
@go tool cover -html=$(COVER_FILE) -o $(COVER_HTML_FILE)
@rm $(COVER_FILE)

test-all: test-unit test-integration test-e2e

.PHONY: test test-e2e
.PHONY: test-unit test-e2e test-integration test-cover test-all

###############################################################################
### Protobuf ###
Expand Down
87 changes: 56 additions & 31 deletions tests/integration/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package integration_test

import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"strconv"
"testing"

tmcli "github.com/cometbft/cometbft/libs/cli"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc/status"

"github.com/skip-mev/feemarket/testutils/networksuite"
"github.com/skip-mev/feemarket/x/feemarket/client/cli"
"github.com/skip-mev/feemarket/x/feemarket/types"
)

// QueryTestSuite is a test suite for query tests
Expand All @@ -24,55 +25,79 @@ func TestNetworkTestSuite(t *testing.T) {
suite.Run(t, new(NetworkTestSuite))
}

func (suite *NetworkTestSuite) TestShowGenesisAccount() {
ctx := suite.Network.Validators[0].ClientCtx
func (s *NetworkTestSuite) TestGetParams() {
s.T().Parallel()

ctx := s.Network.Validators[0].ClientCtx

common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
desc string
idLaunchID string
idAddress string
name string

args []string
err error
obj types.GenesisAccount
obj types.Params
}{
{
desc: "should show an existing genesis account",
idLaunchID: strconv.Itoa(int(accs[0].LaunchID)),
idAddress: accs[0].Address,

name: "should return default params",
args: common,
obj: accs[0],
obj: types.DefaultParams(),
},
{
desc: "should send error for a non existing genesis account",
idLaunchID: strconv.Itoa(100000),
idAddress: strconv.Itoa(100000),
} {
s.T().Run(tc.name, func(t *testing.T) {
tc := tc
out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetParamsCmd(), tc.args)
if tc.err != nil {
stat, ok := status.FromError(tc.err)
require.True(t, ok)
require.ErrorIs(t, stat.Err(), tc.err)
} else {
require.NoError(t, err)
var resp types.ParamsResponse
require.NoError(t, s.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp.Params))
require.NotNil(t, resp.Params)
require.Equal(t, tc.obj, resp.Params)
}
})
}
}

func (s *NetworkTestSuite) TestGetState() {
s.T().Parallel()

ctx := s.Network.Validators[0].ClientCtx

common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
name string

args []string
err error
obj types.State
}{
{
name: "should return default state",
args: common,
err: status.Error(codes.NotFound, "not found"),
obj: types.DefaultState(),
},
} {
suite.T().Run(tc.desc, func(t *testing.T) {
args := []string{
tc.idLaunchID,
tc.idAddress,
}
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowGenesisAccount(), args)
s.T().Run(tc.name, func(t *testing.T) {
tc := tc
out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetStateCmd(), tc.args)
if tc.err != nil {
stat, ok := status.FromError(tc.err)
require.True(t, ok)
require.ErrorIs(t, stat.Err(), tc.err)
} else {
require.NoError(t, err)
var resp types.QueryGetGenesisAccountResponse
require.NoError(t, suite.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.GenesisAccount)
require.Equal(t, tc.obj, resp.GenesisAccount)
var resp types.StateResponse
require.NoError(t, s.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp.State))
require.NotNil(t, resp.State)
require.Equal(t, tc.obj, resp.State)
}
})
}
Expand Down

0 comments on commit f918b59

Please sign in to comment.