Skip to content

Commit

Permalink
test: remove some deps from testutil/network
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jul 2, 2024
1 parent 7b23e52 commit 819e55e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 78 deletions.
3 changes: 2 additions & 1 deletion client/grpc/cmtservice/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"cosmossdk.io/depinject"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/server"
Expand All @@ -14,7 +15,7 @@ import (
func TestStatusCommand(t *testing.T) {
t.Skip() // https://github.com/cosmos/cosmos-sdk/issues/17446

cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
cfg, err := network.DefaultConfigWithAppConfig(depinject.Configs() /* TODO, test skipped anyway */)
require.NoError(t, err)

network, err := network.New(t, t.TempDir(), cfg)
Expand Down
73 changes: 20 additions & 53 deletions client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,34 @@ import (
"testing"

abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

_ "cosmossdk.io/x/accounts"

"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/client"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/address"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
)

type IntegrationTestSuite struct {
suite.Suite

network network.NetworkI
}

func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
func TestCLIQueryConn(t *testing.T) {
t.Skip("data race in comet is causing this to fail")

s.NoError(err)

s.network, err = network.New(s.T(), s.T().TempDir(), cfg)
s.Require().NoError(err)

s.Require().NoError(s.network.WaitForNextBlock())
}

func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
s.network.Cleanup()
}

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.GetValidators()[0].GetClientCtx())
testClient := testdata.NewQueryClient(client.Context{})
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}, grpc.Header(&header))
s.NoError(err)
require.NoError(t, err)

blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
height, err := strconv.Atoi(blockHeight[0])
s.Require().NoError(err)
s.Require().GreaterOrEqual(height, 1) // at least the 1st block

s.Equal("hello", res.Message)
require.NoError(t, err)
require.GreaterOrEqual(t, height, 1) // at least the 1st block
require.Equal(t, "hello", res.Message)
}

func (s *IntegrationTestSuite) TestQueryABCIHeight() {
func TestQueryABCIHeight(t *testing.T) {
testCases := []struct {
name string
reqHeight int64
Expand Down Expand Up @@ -86,30 +61,22 @@ func (s *IntegrationTestSuite) TestQueryABCIHeight() {
}

for _, tc := range testCases {
s.Run(tc.name, func() {
_, err := s.network.WaitForHeight(tc.expHeight)
s.Require().NoError(err)

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

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

t.Run(tc.name, func(t *testing.T) {
req := abci.QueryRequest{
Path: "store/bank/key",
Height: tc.reqHeight,
Data: address.MustLengthPrefix(val.GetAddress()),
Data: address.MustLengthPrefix([]byte{}),
Prove: true,
}

res, err := clientCtx.QueryABCI(req)
s.Require().NoError(err)
clientCtx := client.Context{}.WithHeight(tc.ctxHeight).
WithClient(clitestutil.NewMockCometRPC(abci.QueryResponse{
Height: tc.expHeight,
}))

s.Require().Equal(tc.expHeight, res.Height)
res, err := clientCtx.QueryABCI(req)
require.NoError(t, err)
require.Equal(t, tc.expHeight, res.Height)
})
}
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
5 changes: 2 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/testutil/network"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -319,7 +318,7 @@ func TestAddressCodecFactory(t *testing.T) {

err := depinject.Inject(
depinject.Configs(
network.MinimumAppConfig(),
AppConfig(),
depinject.Supply(log.NewNopLogger()),
),
&addrCodec, &valAddressCodec, &consAddressCodec)
Expand All @@ -337,7 +336,7 @@ func TestAddressCodecFactory(t *testing.T) {
// Set the address codec to the custom one
err = depinject.Inject(
depinject.Configs(
network.MinimumAppConfig(),
AppConfig(),
depinject.Supply(
log.NewNopLogger(),
func() address.Codec { return customAddressCodec{} },
Expand Down
17 changes: 16 additions & 1 deletion tests/integration/server/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

_ "cosmossdk.io/x/accounts"
_ "cosmossdk.io/x/auth"
authclient "cosmossdk.io/x/auth/client"
_ "cosmossdk.io/x/auth/tx/config"
_ "cosmossdk.io/x/bank"
banktypes "cosmossdk.io/x/bank/types"
_ "cosmossdk.io/x/consensus"
_ "cosmossdk.io/x/staking"
stakingtypes "cosmossdk.io/x/staking/types"

"github.com/cosmos/cosmos-sdk/client"
reflectionv1 "github.com/cosmos/cosmos-sdk/client/grpc/reflection"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
reflectionv2 "github.com/cosmos/cosmos-sdk/server/grpc/reflection/v2alpha1"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -41,7 +48,15 @@ func (s *IntegrationTestSuite) SetupSuite() {
var err error
s.T().Log("setting up integration test suite")

s.cfg, err = network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
s.cfg, err = network.DefaultConfigWithAppConfig(configurator.NewAppConfig(
configurator.AccountsModule(),
configurator.AuthModule(),
configurator.BankModule(),
configurator.GenutilModule(),
configurator.StakingModule(),
configurator.ConsensusModule(),
configurator.TxModule(),
))
s.NoError(err)
s.cfg.NumValidators = 1

Expand Down
20 changes: 0 additions & 20 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ import (
sdkmath "cosmossdk.io/math"
"cosmossdk.io/math/unsafe"
pruningtypes "cosmossdk.io/store/pruning/types"
_ "cosmossdk.io/x/accounts"
_ "cosmossdk.io/x/auth" // import auth as a blank
_ "cosmossdk.io/x/auth/tx/config" // import auth tx config as a blank
authtypes "cosmossdk.io/x/auth/types"
_ "cosmossdk.io/x/bank" // import bank as a blank
banktypes "cosmossdk.io/x/bank/types"
_ "cosmossdk.io/x/consensus" // import consensus as a blank
_ "cosmossdk.io/x/staking" // import staking as a blank
stakingtypes "cosmossdk.io/x/staking/types"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -55,7 +49,6 @@ import (
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
Expand Down Expand Up @@ -170,19 +163,6 @@ func DefaultConfig(factory TestFixtureFactory) Config {
}
}

// MinimumAppConfig defines the minimum of modules required for a call to New to succeed
func MinimumAppConfig() depinject.Config {
return configurator.NewAppConfig(
configurator.AccountsModule(),
configurator.AuthModule(),
configurator.BankModule(),
configurator.GenutilModule(),
configurator.StakingModule(),
configurator.ConsensusModule(),
configurator.TxModule(),
)
}

func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
var (
appBuilder *runtime.AppBuilder
Expand Down

0 comments on commit 819e55e

Please sign in to comment.