forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathrpc_test.go
More file actions
125 lines (99 loc) · 3.05 KB
/
Copy pathrpc_test.go
File metadata and controls
125 lines (99 loc) · 3.05 KB
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
package rpc_test
import (
"context"
"fmt"
"strconv"
"testing"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"github.com/cosmos/cosmos-sdk/client/rpc"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
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")
cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
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) TestStatusCommand() {
val0 := s.network.Validators[0]
cmd := rpc.StatusCommand()
out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{})
s.Require().NoError(err)
// Make sure the output has the validator moniker.
s.Require().Contains(out.String(), fmt.Sprintf("\"moniker\":\"%s\"", val0.Moniker))
}
func (s *IntegrationTestSuite) TestCLIQueryConn() {
var header metadata.MD
testClient := testdata.NewQueryClient(s.network.Validators[0].ClientCtx)
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}, grpc.Header(&header))
s.NoError(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)
}
func (s *IntegrationTestSuite) TestQueryABCIHeight() {
testCases := []struct {
name string
reqHeight int64
ctxHeight int64
expHeight int64
}{
{
name: "non zero request height",
reqHeight: 3,
ctxHeight: 1, // query at height 1 or 2 would cause an error
expHeight: 3,
},
{
name: "empty request height - use context height",
reqHeight: 0,
ctxHeight: 3,
expHeight: 3,
},
{
name: "empty request height and context height - use latest height",
reqHeight: 0,
ctxHeight: 0,
expHeight: 4,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
s.network.WaitForHeight(tc.expHeight)
val := s.network.Validators[0]
clientCtx := val.ClientCtx
clientCtx = clientCtx.WithHeight(tc.ctxHeight)
req := abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", banktypes.StoreKey),
Height: tc.reqHeight,
Data: banktypes.CreateAccountBalancesPrefix(val.Address),
Prove: true,
}
res, err := clientCtx.QueryABCI(req)
s.Require().NoError(err)
s.Require().Equal(tc.expHeight, res.Height)
})
}
}
func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}