Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Jul 3, 2020
1 parent 12b8df8 commit 13125fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions x/upgrade/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (k Keeper) CurrentPlan(c context.Context, req *types.QueryCurrentPlanReques

plan, found := k.GetUpgradePlan(ctx)
if !found {
return nil, nil
return &types.QueryCurrentPlanResponse{}, nil
}

return &types.QueryCurrentPlanResponse{Plan: &plan}, nil
Expand All @@ -27,7 +27,7 @@ func (k Keeper) AppliedPlan(c context.Context, req *types.QueryAppliedPlanReques

applied := k.GetDoneHeight(ctx, req.Name)
if applied == 0 {
return nil, nil
return &types.QueryAppliedPlanResponse{}, nil
}

return &types.QueryAppliedPlanResponse{Height: applied}, nil
Expand Down
40 changes: 26 additions & 14 deletions x/upgrade/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,41 @@ import (
gocontext "context"
"testing"

"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"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
)

func TestGRPCQueryParams(t *testing.T) {
// TODO Setup tests - create queryClient
func TestGRPCQueryUpgrade(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{})

// No current plan
res, err := queryClient.Parameters(gocontext.Background(), &types.QueryCurrentPlanRequest{})
require.NoError(t, err)
require.Nil(t, res.Plan)
queryHelper := baseapp.NewQueryServerTestHelper(ctx)
types.RegisterQueryServer(queryHelper, app.UpgradeKeeper)
queryClient := types.NewQueryClient(queryHelper)

t.Log("Verify that the scheduled upgrade plan can be queried")
plan := types.Plan{Name: "test-plan", Height: 5}
app.UpgradeKeeper.ScheduleUpgrade(ctx, plan)

// TODO Create upgrade plan. Does it need to go through gov & upgrade proposal?
res, err := queryClient.Parameters(gocontext.Background(), &types.QueryCurrentPlanRequest{})
res, err := queryClient.CurrentPlan(gocontext.Background(), &types.QueryCurrentPlanRequest{})
require.NoError(t, err)
require.Equal(t, res.Plan, plan)
require.Equal(t, res.Plan, &plan)

// TODO Wait for plan to be applied. Possible to advance N blocks programmatically in test so that plan gets applied?
res, err := queryClient.Parameters(gocontext.Background(), &types.QueryCurrentPlanRequest{})
t.Log("Verify that the upgrade plan can be successfully applied and queried")
ctx = ctx.WithBlockHeight(5)
app.UpgradeKeeper.SetUpgradeHandler("test-plan", func(ctx sdk.Context, plan types.Plan) {})
app.UpgradeKeeper.ApplyUpgrade(ctx, plan)

res, err = queryClient.CurrentPlan(gocontext.Background(), &types.QueryCurrentPlanRequest{})
require.NoError(t, err)
require.Nil(t, res.Plan)

res, err := queryClient.Parameters(gocontext.Background(), &types.QueryAppliedPlanRequest{Name: "test-plan"})
require.NoError(t, err)
require.Equal(t, res.Height, 1234)
appliedRes, appliedErr := queryClient.AppliedPlan(gocontext.Background(), &types.QueryAppliedPlanRequest{Name: "test-plan"})

require.NoError(t, appliedErr)
require.Equal(t, int64(5), appliedRes.Height)
}

0 comments on commit 13125fa

Please sign in to comment.