From f8d067570f5ce036c713906a76a8db243bdb9ca0 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 13 Dec 2023 18:33:58 -0500 Subject: [PATCH] refactor(tests): use grpc instead of cli for all network testing (backport #301) (#302) * refactor(tests): use grpc instead of cli for all network testing (#301) * update * use grpc (cherry picked from commit af3bb52d57addc90859db90f5cae299c0636ac69) # Conflicts: # go.mod # go.sum # tests/integration/network_test.go # testutils/networksuite/networksuite.go * fix --------- Co-authored-by: Alex Johnson --- go.mod | 2 +- go.sum | 4 ++-- tests/integration/network_test.go | 20 +++++++++++++------- testutils/networksuite/networksuite.go | 6 +++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index dcb56533..53904901 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 9341cd67..889f03ca 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/tests/integration/network_test.go b/tests/integration/network_test.go index 682c62de..4c1f119e 100644 --- a/tests/integration/network_test.go +++ b/tests/integration/network_test.go @@ -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" ) @@ -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), } @@ -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{}) +} diff --git a/testutils/networksuite/networksuite.go b/testutils/networksuite/networksuite.go index d095d37b..c14a3682 100644 --- a/testutils/networksuite/networksuite.go +++ b/testutils/networksuite/networksuite.go @@ -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 } @@ -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 {