-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x/upgrade gRPC query service (#6590)
* Add .proto and make proto-gen * Correct proto types * Update pseudo tests * Update tests * line break * Fix tests after merge * Update proto/cosmos/upgrade/query.proto Co-authored-by: Aaron Craelius <[email protected]> * Update proto/cosmos/upgrade/query.proto Co-authored-by: Aaron Craelius <[email protected]> * Update proto/cosmos/upgrade/query.proto Co-authored-by: Aaron Craelius <[email protected]> * Update proto/cosmos/upgrade/query.proto Co-authored-by: Aaron Craelius <[email protected]> Co-authored-by: Aaron Craelius <[email protected]>
- Loading branch information
1 parent
80e53a4
commit 4459201
Showing
5 changed files
with
1,041 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
syntax = "proto3"; | ||
package cosmos.upgrade; | ||
|
||
import "cosmos/upgrade/upgrade.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/upgrade/types"; | ||
|
||
// Query defines the gRPC upgrade querier service | ||
service Query { | ||
// CurrentPlan queries the current upgrade plan | ||
rpc CurrentPlan(QueryCurrentPlanRequest) returns (QueryCurrentPlanResponse) {} | ||
|
||
// AppliedPlan queries a previously applied upgrade plan by its name | ||
rpc AppliedPlan(QueryAppliedPlanRequest) returns (QueryAppliedPlanResponse) {} | ||
} | ||
|
||
// QueryCurrentPlanRequest is the request type for the Query/CurrentPlan RPC method | ||
message QueryCurrentPlanRequest {} | ||
|
||
// QueryCurrentPlanResponse is the response type for the Query/CurrentPlan RPC method | ||
message QueryCurrentPlanResponse { | ||
// plan is the current upgrade plan | ||
Plan plan = 1; | ||
} | ||
|
||
// QueryCurrentPlanRequest is the request type for the Query/AppliedPlan RPC method | ||
message QueryAppliedPlanRequest { | ||
// name is the name of the applied plan to query for | ||
string name = 1; | ||
} | ||
|
||
// QueryAppliedPlanResponse is the response type for the Query/AppliedPlan RPC method | ||
message QueryAppliedPlanResponse { | ||
// height is the block height at which the plan was applied | ||
int64 height = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
var _ types.QueryServer = Keeper{} | ||
|
||
// CurrentPlan implements the Query/CurrentPlan gRPC method | ||
func (k Keeper) CurrentPlan(c context.Context, req *types.QueryCurrentPlanRequest) (*types.QueryCurrentPlanResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
plan, found := k.GetUpgradePlan(ctx) | ||
if !found { | ||
return &types.QueryCurrentPlanResponse{}, nil | ||
} | ||
|
||
return &types.QueryCurrentPlanResponse{Plan: &plan}, nil | ||
} | ||
|
||
// AppliedPlan implements the Query/AppliedPlan gRPC method | ||
func (k Keeper) AppliedPlan(c context.Context, req *types.QueryAppliedPlanRequest) (*types.QueryAppliedPlanResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
applied := k.GetDoneHeight(ctx, req.Name) | ||
if applied == 0 { | ||
return &types.QueryAppliedPlanResponse{}, nil | ||
} | ||
|
||
return &types.QueryAppliedPlanResponse{Height: applied}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package keeper_test | ||
|
||
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 TestGRPCQueryUpgrade(t *testing.T) { | ||
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) | ||
|
||
t.Log("Verify that the scheduled upgrade plan can be queried") | ||
plan := types.Plan{Name: "test-plan", Height: 5} | ||
app.UpgradeKeeper.ScheduleUpgrade(ctx, plan) | ||
|
||
res, err := queryClient.CurrentPlan(gocontext.Background(), &types.QueryCurrentPlanRequest{}) | ||
require.NoError(t, err) | ||
require.Equal(t, res.Plan, &plan) | ||
|
||
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) | ||
|
||
appliedRes, appliedErr := queryClient.AppliedPlan(gocontext.Background(), &types.QueryAppliedPlanRequest{Name: "test-plan"}) | ||
require.NoError(t, appliedErr) | ||
require.Equal(t, int64(5), appliedRes.Height) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.