Skip to content

Commit

Permalink
refactor(tests): testutil.Network as an interface (#18389)
Browse files Browse the repository at this point in the history
Co-authored-by: Anmol <[email protected]>
  • Loading branch information
tac0turtle and Anmol1696 authored Nov 8, 2023
1 parent 8fbf616 commit 03c3f8e
Show file tree
Hide file tree
Showing 28 changed files with 959 additions and 863 deletions.
6 changes: 3 additions & 3 deletions client/grpc/cmtservice/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func TestStatusCommand(t *testing.T) {
require.NoError(t, err)
require.NoError(t, network.WaitForNextBlock())

val0 := network.Validators[0]
val0 := network.GetValidators()[0]
cmd := server.StatusCommand()

out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{})
out, err := clitestutil.ExecTestCLICmd(val0.GetClientCtx(), cmd, []string{})
require.NoError(t, err)

// Make sure the output has the validator moniker.
require.Contains(t, out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.Moniker))
require.Contains(t, out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.GetMoniker()))
}
10 changes: 5 additions & 5 deletions client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type IntegrationTestSuite struct {
suite.Suite

network *network.Network
network network.NetworkI
}

func (s *IntegrationTestSuite) SetupSuite() {
Expand All @@ -47,7 +47,7 @@ func (s *IntegrationTestSuite) TestCLIQueryConn() {
s.T().Skip("data race in comet is causing this to fail")
var header metadata.MD

testClient := testdata.NewQueryClient(s.network.Validators[0].ClientCtx)
testClient := testdata.NewQueryClient(s.network.GetValidators()[0].GetClientCtx())
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}, grpc.Header(&header))
s.NoError(err)

Expand Down Expand Up @@ -91,15 +91,15 @@ func (s *IntegrationTestSuite) TestQueryABCIHeight() {
_, err := s.network.WaitForHeight(tc.expHeight)
s.Require().NoError(err)

val := s.network.Validators[0]
val := s.network.GetValidators()[0]

clientCtx := val.ClientCtx
clientCtx := val.GetClientCtx()
clientCtx = clientCtx.WithHeight(tc.ctxHeight)

req := abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", banktypes.StoreKey),
Height: tc.reqHeight,
Data: address.MustLengthPrefix(val.Address),
Data: address.MustLengthPrefix(val.GetAddress()),
Prove: true,
}

Expand Down
10 changes: 5 additions & 5 deletions server/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type GRPCWebTestSuite struct {
suite.Suite

cfg network.Config
network *network.Network
network network.NetworkI
protoCdc *codec.ProtoCodec
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func (s *GRPCWebTestSuite) TearDownSuite() {
}

func (s *GRPCWebTestSuite) Test_Latest_Validators() {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
for _, contentType := range []string{grpcWebContentType} {
headers, trailers, responses, err := s.makeGrpcRequest(
"/cosmos.base.tendermint.v1beta1.Service/GetLatestValidatorSet",
Expand All @@ -84,7 +84,7 @@ func (s *GRPCWebTestSuite) Test_Latest_Validators() {
s.Require().NoError(err)
pubKey, ok := valsSet.Validators[0].PubKey.GetCachedValue().(cryptotypes.PubKey)
s.Require().Equal(true, ok)
s.Require().Equal(pubKey, val.PubKey)
s.Require().Equal(pubKey, val.GetPubKey())
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ func serializeProtoMessages(messages []proto.Message) [][]byte {
func (s *GRPCWebTestSuite) makeRequest(
verb, method string, headers http.Header, body io.Reader, isText bool,
) (*http.Response, error) {
val := s.network.Validators[0]
val := s.network.GetValidators()[0]
contentType := "application/grpc-web"
if isText {
// base64 encode the body
Expand All @@ -146,7 +146,7 @@ func (s *GRPCWebTestSuite) makeRequest(
contentType = "application/grpc-web-text"
}

url := fmt.Sprintf("http://%s%s", strings.TrimPrefix(val.AppConfig.API.Address, "tcp://"), method)
url := fmt.Sprintf("http://%s%s", strings.TrimPrefix(val.GetAppConfig().API.Address, "tcp://"), method)
req, err := http.NewRequest(verb, url, body)
s.Require().NoError(err, "failed creating a request")
req.Header = headers
Expand Down
2 changes: 1 addition & 1 deletion simapp/testutil_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type IntegrationTestSuite struct {
suite.Suite

network *network.Network
network network.NetworkI
}

func (s *IntegrationTestSuite) SetupSuite() {
Expand Down
Loading

0 comments on commit 03c3f8e

Please sign in to comment.