Skip to content

Commit

Permalink
refactor(tests): use grpc instead of cli for all network testing (bac…
Browse files Browse the repository at this point in the history
…kport #301) (#302)

* refactor(tests): use grpc instead of cli for all network testing (#301)

* update

* use grpc

(cherry picked from commit af3bb52)

# Conflicts:
#	go.mod
#	go.sum
#	tests/integration/network_test.go
#	testutils/networksuite/networksuite.go

* fix

---------

Co-authored-by: Alex Johnson <alex@skip.money>
  • Loading branch information
mergify[bot] and aljo242 committed Dec 13, 2023
1 parent d583032 commit f8d0675
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/huandu/skiplist v1.2.0
github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051
github.com/skip-mev/chaintestutil v0.0.0-20231213230652-c159341203f6
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@ github.com/sivchari/nosnakecase v1.7.0 h1:7QkpWIRMe8x25gckkFd2A5Pi6Ymo0qgr4JrhGt
github.com/sivchari/nosnakecase v1.7.0/go.mod h1:CwDzrzPea40/GB6uynrNLiorAlgFRvRbFSgJx2Gs+QY=
github.com/sivchari/tenv v1.7.1 h1:PSpuD4bu6fSmtWMxSGWcvqUUgIn7k3yOJhOIzVWn8Ak=
github.com/sivchari/tenv v1.7.1/go.mod h1:64yStXKSOxDfX47NlhVwND4dHwfZDdbp2Lyl018Icvg=
github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051 h1:ZTD4dFUTv+h+BgGTv4PtXnSxgMTUrCvGX+NQjNo/hqA=
github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051/go.mod h1:P7icBoBSf+Ci1b2moqSXQZTThtBs33eJ8dPajce2ViQ=
github.com/skip-mev/chaintestutil v0.0.0-20231213230652-c159341203f6 h1:aTqi6gmYxnzlTWep3zEaJfXXJTdMf4eoKjVyFWzut5I=
github.com/skip-mev/chaintestutil v0.0.0-20231213230652-c159341203f6/go.mod h1:P7icBoBSf+Ci1b2moqSXQZTThtBs33eJ8dPajce2ViQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down
20 changes: 13 additions & 7 deletions tests/integration/network_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package integration_test

import (
"context"
"fmt"
"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/block-sdk/testutils/networksuite"
auctioncli "github.com/skip-mev/block-sdk/x/auction/client/cli"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)

Expand All @@ -28,8 +27,6 @@ func TestNetworkTestSuite(t *testing.T) {
func (s *NetworkTestSuite) TestGetAuctionParams() {
s.T().Parallel()

val := s.Network.Validators[0]

common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
Expand All @@ -48,18 +45,27 @@ func (s *NetworkTestSuite) TestGetAuctionParams() {
} {
s.T().Run(tc.name, func(t *testing.T) {
tc := tc
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, auctioncli.CmdQueryParams(), tc.args)
resp, err := s.QueryAuctionParams()
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 auctiontypes.QueryParamsResponse
require.NoError(t, s.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp.Params))
require.NotNil(t, resp)
require.Equal(t, tc.obj, resp.Params)
}
})
}
}

func (s *NetworkTestSuite) QueryAuctionParams() (*auctiontypes.QueryParamsResponse, error) {
s.T().Helper()

cc, closeConn, err := s.NetworkSuite.GetGRPC()
s.Require().NoError(err)
defer closeConn()

client := auctiontypes.NewQueryClient(cc)
return client.Params(context.Background(), &auctiontypes.QueryParamsRequest{})
}
6 changes: 3 additions & 3 deletions testutils/networksuite/networksuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ var (
}
)

// NetworkTestSuite is a test suite for query tests that initializes a network instance.
// NetworkTestSuite is a test suite for tests that initializes a network instance.
type NetworkTestSuite struct {
suite.Suite

Network *network.Network
NetworkSuite *network.TestSuite
AuctionState auctiontypes.GenesisState
}

Expand All @@ -63,7 +63,7 @@ func (nts *NetworkTestSuite) SetupSuite() {
nts.AuctionState = populateAuction(r, nts.AuctionState)
updateGenesisConfigState(auctiontypes.ModuleName, &nts.AuctionState)

nts.Network = network.New(nts.T(), cfg)
nts.NetworkSuite = network.NewSuite(nts.T(), cfg)
}

func populateAuction(_ *rand.Rand, auctionState auctiontypes.GenesisState) auctiontypes.GenesisState {
Expand Down

0 comments on commit f8d0675

Please sign in to comment.