-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathgrpc_query_test.go
More file actions
64 lines (49 loc) · 1.91 KB
/
grpc_query_test.go
File metadata and controls
64 lines (49 loc) · 1.91 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
package keeper_test
import (
gocontext "context"
"testing"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
)
type UpgradeTestSuite struct {
suite.Suite
app *simapp.SimApp
ctx sdk.Context
queryClient types.QueryClient
}
func (suite *UpgradeTestSuite) SetupTest() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{})
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.UpgradeKeeper)
queryClient := types.NewQueryClient(queryHelper)
suite.app = app
suite.ctx = ctx
suite.queryClient = queryClient
}
func (suite *UpgradeTestSuite) TestGRPCQuery() {
queryClient := suite.queryClient
suite.T().Log("Verify that the scheduled upgrade plan can be queried")
plan := types.Plan{Name: "test-plan", Height: 5}
suite.app.UpgradeKeeper.ScheduleUpgrade(suite.ctx, plan)
res, err := queryClient.CurrentPlan(gocontext.Background(), &types.QueryCurrentPlanRequest{})
suite.NoError(err)
suite.Equal(res.Plan, &plan)
suite.T().Log("Verify that the upgrade plan can be successfully applied and queried")
suite.ctx = suite.ctx.WithBlockHeight(5)
suite.app.UpgradeKeeper.SetUpgradeHandler("test-plan", func(ctx sdk.Context, plan types.Plan) {})
suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, plan)
res, err = queryClient.CurrentPlan(gocontext.Background(), &types.QueryCurrentPlanRequest{})
suite.NoError(err)
suite.Nil(res.Plan)
appliedRes, appliedErr := queryClient.AppliedPlan(gocontext.Background(), &types.QueryAppliedPlanRequest{Name: "test-plan"})
suite.NoError(appliedErr)
suite.Equal(int64(5), appliedRes.Height)
}
func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}