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

* update

* use grpc
This commit is contained in:
Alex Johnson
2023-12-13 15:49:50 -05:00
committed by GitHub
parent b48073d3eb
commit af3bb52d57
4 changed files with 31 additions and 19 deletions
+25 -13
View File
@@ -1,19 +1,17 @@
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"
blocksdkcli "github.com/skip-mev/block-sdk/x/blocksdk/client/cli"
blocksdktypes "github.com/skip-mev/block-sdk/x/blocksdk/types"
)
@@ -30,8 +28,6 @@ func TestNetworkTestSuite(t *testing.T) {
func (s *NetworkTestSuite) TestGetLanes() {
s.T().Parallel()
val := s.Network.Validators[0]
common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
@@ -50,15 +46,13 @@ func (s *NetworkTestSuite) TestGetLanes() {
} {
s.T().Run(tc.name, func(t *testing.T) {
tc := tc
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, blocksdkcli.CmdQueryLanes(), tc.args)
resp, err := s.QueryBlockSDKLanes()
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 blocksdktypes.QueryLanesResponse
require.NoError(t, s.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.Lanes)
require.ElementsMatch(t, tc.obj, resp.Lanes)
}
@@ -69,8 +63,6 @@ func (s *NetworkTestSuite) TestGetLanes() {
func (s *NetworkTestSuite) TestGetAuctionParams() {
s.T().Parallel()
val := s.Network.Validators[0]
common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
@@ -89,18 +81,38 @@ 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{})
}
func (s *NetworkTestSuite) QueryBlockSDKLanes() (*blocksdktypes.QueryLanesResponse, error) {
s.T().Helper()
cc, closeConn, err := s.NetworkSuite.GetGRPC()
s.Require().NoError(err)
defer closeConn()
client := blocksdktypes.NewQueryClient(cc)
return client.Lanes(context.Background(), &blocksdktypes.QueryLanesRequest{})
}