-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathquery_test.go
127 lines (107 loc) · 3.9 KB
/
query_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package runtime
import (
"testing"
"github.com/cosmos/gogoproto/proto"
"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"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
_ "cosmossdk.io/x/accounts"
_ "cosmossdk.io/x/bank"
_ "cosmossdk.io/x/consensus"
_ "cosmossdk.io/x/staking"
"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/config"
)
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(
depinject.Configs(
configurator.NewAppConfig(
configurator.AccountsModule(),
configurator.AuthModule(),
configurator.TxModule(),
configurator.ValidateModule(),
configurator.ConsensusModule(),
configurator.BankModule(),
configurator.StakingModule(),
),
depinject.Supply(log.NewNopLogger()),
),
&interfaceRegistry,
)
assert.NilError(t, err)
f.ctx = app.BaseApp.NewContext(false)
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 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 have x/auth autocli options which were configured manually
authOpts := res.ModuleOptions["auth"]
assert.Assert(t, authOpts != nil)
assert.Assert(t, authOpts.Query != nil)
assert.Equal(t, "cosmos.auth.v1beta1.Query", authOpts.Query.Service)
// make sure we have some custom options
assert.Assert(t, len(authOpts.Query.RpcCommandOptions) != 0)
// make sure we have x/staking autocli options which should have been auto-discovered
stakingOpts := res.ModuleOptions["staking"]
assert.Assert(t, stakingOpts != nil)
assert.Assert(t, stakingOpts.Query != nil && stakingOpts.Tx != nil)
assert.Equal(t, "cosmos.staking.v1beta1.Query", stakingOpts.Query.Service)
assert.Equal(t, "cosmos.staking.v1beta1.Msg", stakingOpts.Tx.Service)
// make sure tx module has no autocli options because it has no services
assert.Assert(t, res.ModuleOptions["tx"] == nil)
}