feat: add autocli app wiring + remote info support (#13281)
This commit is contained in:
+3
-1
@@ -15,6 +15,8 @@ require (
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/tendermint/tendermint v0.37.0-rc1
|
||||
github.com/tendermint/tm-db v0.6.7
|
||||
google.golang.org/protobuf v1.28.1
|
||||
gotest.tools/v3 v3.4.0
|
||||
pgregory.net/rapid v0.5.3
|
||||
)
|
||||
|
||||
@@ -74,6 +76,7 @@ require (
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/btree v1.1.2 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/orderedcode v0.0.1 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
|
||||
github.com/gorilla/handlers v1.5.1 // indirect
|
||||
@@ -149,7 +152,6 @@ require (
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a // indirect
|
||||
google.golang.org/grpc v1.50.1 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@@ -381,6 +381,7 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
@@ -1391,6 +1392,7 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
|
||||
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/module"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/bank"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/consensus"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/params"
|
||||
_ "github.com/cosmos/cosmos-sdk/x/staking"
|
||||
)
|
||||
|
||||
type fixture struct {
|
||||
ctx sdk.Context
|
||||
appQueryClient appv1alpha1.QueryClient
|
||||
autocliInfoClient autocliv1.QueryClient
|
||||
reflectionClient reflectionv1.ReflectionServiceClient
|
||||
}
|
||||
|
||||
func initFixture(t assert.TestingT) *fixture {
|
||||
f := &fixture{}
|
||||
|
||||
var interfaceRegistry codectypes.InterfaceRegistry
|
||||
|
||||
app, err := simtestutil.Setup(
|
||||
configurator.NewAppConfig(
|
||||
configurator.AuthModule(),
|
||||
configurator.TxModule(),
|
||||
configurator.ParamsModule(),
|
||||
configurator.ConsensusModule(),
|
||||
configurator.BankModule(),
|
||||
configurator.StakingModule(),
|
||||
),
|
||||
&interfaceRegistry,
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
f.ctx = app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
queryHelper := &baseapp.QueryServiceTestHelper{
|
||||
GRPCQueryRouter: app.BaseApp.GRPCQueryRouter(),
|
||||
Ctx: f.ctx,
|
||||
}
|
||||
f.appQueryClient = appv1alpha1.NewQueryClient(queryHelper)
|
||||
f.autocliInfoClient = autocliv1.NewQueryClient(queryHelper)
|
||||
f.reflectionClient = reflectionv1.NewReflectionServiceClient(queryHelper)
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func TestQueryAppConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
res, err := f.appQueryClient.Config(f.ctx, &appv1alpha1.QueryConfigRequest{})
|
||||
assert.NilError(t, err)
|
||||
// app config is not nil
|
||||
assert.Assert(t, res != nil && res.Config != nil)
|
||||
|
||||
moduleConfigs := map[string]*appv1alpha1.ModuleConfig{}
|
||||
for _, module := range res.Config.Modules {
|
||||
moduleConfigs[module.Name] = module
|
||||
}
|
||||
|
||||
// has all expected modules
|
||||
for _, modName := range []string{"auth", "bank", "tx", "consensus", "runtime", "params", "staking"} {
|
||||
modConfig := moduleConfigs[modName]
|
||||
if modConfig == nil {
|
||||
t.Fatalf("missing %s", modName)
|
||||
}
|
||||
assert.Assert(t, modConfig.Config != nil)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReflectionService(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
res, err := f.reflectionClient.FileDescriptors(f.ctx, &reflectionv1.FileDescriptorsRequest{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res != nil && res.Files != nil)
|
||||
|
||||
fdMap := map[string]*descriptorpb.FileDescriptorProto{}
|
||||
for _, descriptorProto := range res.Files {
|
||||
fdMap[*descriptorProto.Name] = descriptorProto
|
||||
}
|
||||
|
||||
// check all file descriptors from gogo are present
|
||||
for path := range proto.AllFileDescriptors() {
|
||||
if fdMap[path] == nil {
|
||||
t.Fatalf("missing %s", path)
|
||||
}
|
||||
}
|
||||
|
||||
// check all file descriptors from protoregistry are present
|
||||
protoregistry.GlobalFiles.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool {
|
||||
path := fileDescriptor.Path()
|
||||
if fdMap[path] == nil {
|
||||
t.Fatalf("missing %s", path)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func TestQueryAutoCLIAppOptions(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
res, err := f.autocliInfoClient.AppOptions(f.ctx, &autocliv1.AppOptionsRequest{})
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res != nil && res.ModuleOptions != nil)
|
||||
|
||||
// make sure we at least have x/auth autocli options
|
||||
authOpts := res.ModuleOptions["auth"]
|
||||
assert.Assert(t, authOpts != nil)
|
||||
assert.Assert(t, authOpts.Query != nil && authOpts.Query.Service != "")
|
||||
}
|
||||
Reference in New Issue
Block a user