From 635e11050022d3b9313170634f04b8b8e321ed60 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 21 Jun 2024 17:11:31 -0400 Subject: [PATCH] add changelog --- changelog.md | 1 + docs/openapi/openapi.swagger.yaml | 1 + proto/zetachain/zetacore/observer/query.proto | 1 + .../client/cli/query_tss_fund_migrator.go | 11 ++++++++-- .../grpc_query_tss_funds_migrator_info.go | 5 +++++ .../grpc_query_tss_funds_migrator_test.go | 21 +++++++++++++++---- x/observer/types/query.pb.go | 2 ++ 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index ba3c0ed790..a661ddfcef 100644 --- a/changelog.md +++ b/changelog.md @@ -28,6 +28,7 @@ * [2319](https://github.com/zeta-chain/node/pull/2319) - use `CheckAuthorization` function in all messages * [2325](https://github.com/zeta-chain/node/pull/2325) - revert telemetry server changes * [2339](https://github.com/zeta-chain/node/pull/2339) - add binaries related question to syncing issue form +* [2372](https://github.com/zeta-chain/node/pull/2372) - add queries for tss fund migration info ### Refactor diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 90421a8b14..d85b3cec73 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -30172,6 +30172,7 @@ paths: - Query /zeta-chain/observer/get_all_tss_fund_migrators: get: + summary: Queries all TssFundMigratorInfo operationId: Query_TssFundsMigratorInfoAll responses: "200": diff --git a/proto/zetachain/zetacore/observer/query.proto b/proto/zetachain/zetacore/observer/query.proto index 79254de2d0..beb59ce6dd 100644 --- a/proto/zetachain/zetacore/observer/query.proto +++ b/proto/zetachain/zetacore/observer/query.proto @@ -157,6 +157,7 @@ service Query { option (google.api.http).get = "/zeta-chain/observer/get_tss_fund_migrator"; } + // Queries all TssFundMigratorInfo rpc TssFundsMigratorInfoAll(QueryTssFundsMigratorInfoAllRequest) returns (QueryTssFundsMigratorInfoAllResponse) { option (google.api.http).get = diff --git a/x/observer/client/cli/query_tss_fund_migrator.go b/x/observer/client/cli/query_tss_fund_migrator.go index 5dc77fb263..c4072d9560 100644 --- a/x/observer/client/cli/query_tss_fund_migrator.go +++ b/x/observer/client/cli/query_tss_fund_migrator.go @@ -2,6 +2,7 @@ package cli import ( "context" + "strconv" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -14,12 +15,18 @@ func CmdGetTssFundsMigrator() *cobra.Command { cmd := &cobra.Command{ Use: "show-tss-funds-migrator [chain-id]", Short: "show the tss funds migrator for a chain", - RunE: func(cmd *cobra.Command, _ []string) error { + RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - params := &types.QueryTssFundsMigratorInfoRequest{} + chainId, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return err + } + params := &types.QueryTssFundsMigratorInfoRequest{ + ChainId: chainId, + } res, err := queryClient.TssFundsMigratorInfo(context.Background(), params) if err != nil { diff --git a/x/observer/keeper/grpc_query_tss_funds_migrator_info.go b/x/observer/keeper/grpc_query_tss_funds_migrator_info.go index b008df0070..7a2ab7e357 100644 --- a/x/observer/keeper/grpc_query_tss_funds_migrator_info.go +++ b/x/observer/keeper/grpc_query_tss_funds_migrator_info.go @@ -7,6 +7,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -21,6 +22,10 @@ func (k Keeper) TssFundsMigratorInfo( ctx := sdk.UnwrapSDKContext(goCtx) + if chains.GetChainFromChainID(req.ChainId) == nil { + return nil, status.Error(codes.InvalidArgument, "invalid chain id") + } + fm, found := k.GetFundMigrator(ctx, req.ChainId) if !found { return nil, status.Error(codes.NotFound, "tss fund migrator not found") diff --git a/x/observer/keeper/grpc_query_tss_funds_migrator_test.go b/x/observer/keeper/grpc_query_tss_funds_migrator_test.go index 8f431b9122..3882079f5d 100644 --- a/x/observer/keeper/grpc_query_tss_funds_migrator_test.go +++ b/x/observer/keeper/grpc_query_tss_funds_migrator_test.go @@ -18,7 +18,18 @@ func TestKeeper_TssFundsMigratorInfo(t *testing.T) { wctx := sdk.WrapSDKContext(ctx) res, err := k.TssFundsMigratorInfo(wctx, nil) - require.Error(t, err) + require.ErrorContains(t, err, "invalid request") + require.Nil(t, res) + }) + + t.Run("should error if chain id is invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + + res, err := k.TssFundsMigratorInfo(wctx, &types.QueryTssFundsMigratorInfoRequest{ + ChainId: 0, + }) + require.ErrorContains(t, err, "invalid chain id") require.Nil(t, res) }) @@ -26,8 +37,10 @@ func TestKeeper_TssFundsMigratorInfo(t *testing.T) { k, ctx, _, _ := keepertest.ObserverKeeper(t) wctx := sdk.WrapSDKContext(ctx) - res, err := k.TssFundsMigratorInfo(wctx, &types.QueryTssFundsMigratorInfoRequest{}) - require.Error(t, err) + res, err := k.TssFundsMigratorInfo(wctx, &types.QueryTssFundsMigratorInfoRequest{ + ChainId: chains.Ethereum.ChainId, + }) + require.ErrorContains(t, err, "tss fund migrator not found") require.Nil(t, res) }) @@ -56,7 +69,7 @@ func TestKeeper_TssFundsMigratorInfoAll(t *testing.T) { wctx := sdk.WrapSDKContext(ctx) res, err := k.TssFundsMigratorInfoAll(wctx, nil) - require.Error(t, err) + require.ErrorContains(t, err, "invalid request") require.Nil(t, res) }) diff --git a/x/observer/types/query.pb.go b/x/observer/types/query.pb.go index 59f340b65a..2257104ee3 100644 --- a/x/observer/types/query.pb.go +++ b/x/observer/types/query.pb.go @@ -2499,6 +2499,7 @@ type QueryClient interface { ChainNoncesAll(ctx context.Context, in *QueryAllChainNoncesRequest, opts ...grpc.CallOption) (*QueryAllChainNoncesResponse, error) // Queries the TssFundMigratorInfo for a specific chain TssFundsMigratorInfo(ctx context.Context, in *QueryTssFundsMigratorInfoRequest, opts ...grpc.CallOption) (*QueryTssFundsMigratorInfoResponse, error) + // Queries all TssFundMigratorInfo TssFundsMigratorInfoAll(ctx context.Context, in *QueryTssFundsMigratorInfoAllRequest, opts ...grpc.CallOption) (*QueryTssFundsMigratorInfoAllResponse, error) } @@ -2768,6 +2769,7 @@ type QueryServer interface { ChainNoncesAll(context.Context, *QueryAllChainNoncesRequest) (*QueryAllChainNoncesResponse, error) // Queries the TssFundMigratorInfo for a specific chain TssFundsMigratorInfo(context.Context, *QueryTssFundsMigratorInfoRequest) (*QueryTssFundsMigratorInfoResponse, error) + // Queries all TssFundMigratorInfo TssFundsMigratorInfoAll(context.Context, *QueryTssFundsMigratorInfoAllRequest) (*QueryTssFundsMigratorInfoAllResponse, error) }