<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺ v ✰ Thanks for creating a PR! ✰ v Before smashing the submit button please review the checkboxes. v If a checkbox is n/a - please still include it but + a little note why ☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --> ## Description ref: #9183 After some more recent conversations w/ @aaronc, I decided to go back to his original proposal of setting up a subcommand for running in-process testnets. This PR splits the `simd testnet` command into two subcommands: - `simd testnet start` which starts an in-process n-node testnet - `simd testnet init-files` which sets up configuration & genesis files for an n-node testnet to be run as separate processes (one per node, most likely via Docker Compose) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - **n/a** - [ ] Wrote unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`) - **see #9411** - [x] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [x] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [x] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
// +build norace
|
|
|
|
package client_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
)
|
|
|
|
type IntegrationTestSuite struct {
|
|
suite.Suite
|
|
|
|
network *network.Network
|
|
}
|
|
|
|
func (s *IntegrationTestSuite) SetupSuite() {
|
|
s.T().Log("setting up integration test suite")
|
|
|
|
var err error
|
|
s.network, err = network.New(s.T(), s.T().TempDir(), network.DefaultConfig())
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.network.WaitForHeight(2)
|
|
s.Require().NoError(err)
|
|
}
|
|
|
|
func (s *IntegrationTestSuite) TearDownSuite() {
|
|
s.T().Log("tearing down integration test suite")
|
|
s.network.Cleanup()
|
|
}
|
|
|
|
func (s *IntegrationTestSuite) TestGRPCQuery() {
|
|
val0 := s.network.Validators[0]
|
|
|
|
// gRPC query to test service should work
|
|
testClient := testdata.NewQueryClient(val0.ClientCtx)
|
|
testRes, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
|
|
s.Require().NoError(err)
|
|
s.Require().Equal("hello", testRes.Message)
|
|
|
|
// gRPC query to bank service should work
|
|
denom := fmt.Sprintf("%stoken", val0.Moniker)
|
|
bankClient := banktypes.NewQueryClient(val0.ClientCtx)
|
|
var header metadata.MD
|
|
bankRes, err := bankClient.Balance(
|
|
context.Background(),
|
|
&banktypes.QueryBalanceRequest{Address: val0.Address.String(), Denom: denom},
|
|
grpc.Header(&header), // Also fetch grpc header
|
|
)
|
|
s.Require().NoError(err)
|
|
s.Require().Equal(
|
|
sdk.NewCoin(denom, s.network.Config.AccountTokens),
|
|
*bankRes.GetBalance(),
|
|
)
|
|
blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
|
|
s.Require().NotEmpty(blockHeight[0]) // Should contain the block height
|
|
|
|
// Request metadata should work
|
|
val0.ClientCtx = val0.ClientCtx.WithHeight(1) // We set clientCtx to height 1
|
|
bankClient = banktypes.NewQueryClient(val0.ClientCtx)
|
|
bankRes, err = bankClient.Balance(
|
|
context.Background(),
|
|
&banktypes.QueryBalanceRequest{Address: val0.Address.String(), Denom: denom},
|
|
grpc.Header(&header),
|
|
)
|
|
blockHeight = header.Get(grpctypes.GRPCBlockHeightHeader)
|
|
s.Require().Equal([]string{"1"}, blockHeight)
|
|
}
|
|
|
|
func TestIntegrationTestSuite(t *testing.T) {
|
|
suite.Run(t, new(IntegrationTestSuite))
|
|
}
|