diff --git a/changelog.md b/changelog.md index 82d90197d2..dbf40ef8e3 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ * [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority * [2291](https://github.com/zeta-chain/node/pull/2291) - initialize cctx gateway interface * [2289](https://github.com/zeta-chain/node/pull/2289) - add an authorization list to keep track of all authorizations on the chain +* [2305](https://github.com/zeta-chain/node/pull/2305) - add new messages `MsgAddAuthorization` and `MsgRemoveAuthorization` that can be used to update the authorization list ### Refactor diff --git a/docs/cli/zetacored/zetacored_tx_authority.md b/docs/cli/zetacored/zetacored_tx_authority.md index 5a543e70b1..59a0ca9ffa 100644 --- a/docs/cli/zetacored/zetacored_tx_authority.md +++ b/docs/cli/zetacored/zetacored_tx_authority.md @@ -26,6 +26,8 @@ zetacored tx authority [flags] ### SEE ALSO * [zetacored tx](zetacored_tx.md) - Transactions subcommands +* [zetacored tx authority add-authorization](zetacored_tx_authority_add-authorization.md) - Add a new authorization or update the policy of an existing authorization. Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin. +* [zetacored tx authority remove-authorization](zetacored_tx_authority_remove-authorization.md) - removes an existing authorization * [zetacored tx authority update-chain-info](zetacored_tx_authority_update-chain-info.md) - Update the chain info -* [zetacored tx authority update-policies](zetacored_tx_authority_update-policies.md) - Update the policies +* [zetacored tx authority update-policies](zetacored_tx_authority_update-policies.md) - Update policies to values provided in the JSON file. diff --git a/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md b/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md new file mode 100644 index 0000000000..4ed717b2b6 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md @@ -0,0 +1,53 @@ +# tx authority add-authorization + +Add a new authorization or update the policy of an existing authorization. Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin. + +``` +zetacored tx authority add-authorization [msg-url] [authorized-policy] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for add-authorization + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx authority](zetacored_tx_authority.md) - authority transactions subcommands + diff --git a/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md new file mode 100644 index 0000000000..a29a02bb18 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md @@ -0,0 +1,53 @@ +# tx authority remove-authorization + +removes an existing authorization + +``` +zetacored tx authority remove-authorization [msg-url] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for remove-authorization + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx authority](zetacored_tx_authority.md) - authority transactions subcommands + diff --git a/docs/cli/zetacored/zetacored_tx_authority_update-policies.md b/docs/cli/zetacored/zetacored_tx_authority_update-policies.md index c26e3f0080..7e375d8d1e 100644 --- a/docs/cli/zetacored/zetacored_tx_authority_update-policies.md +++ b/docs/cli/zetacored/zetacored_tx_authority_update-policies.md @@ -1,6 +1,6 @@ # tx authority update-policies -Update the policies +Update policies to values provided in the JSON file. ``` zetacored tx authority update-policies [policies-json-file] [flags] diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index c9e758227f..8bb38c8a67 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -56730,6 +56730,14 @@ definitions: ChainInfo contains static information about the chains This structure is used to dynamically update these info on a live network before hardcoding the values in a upgrade + authorityMsgAddAuthorizationResponse: + type: object + description: MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. + authorityMsgRemoveAuthorizationResponse: + type: object + description: |- + MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse + service. authorityMsgUpdateChainInfoResponse: type: object description: MsgUpdateChainInfoResponse defines the MsgUpdateChainInfoResponse service. @@ -56758,6 +56766,7 @@ definitions: - groupEmergency - groupOperational - groupAdmin + - groupEmpty default: groupEmergency description: |- - groupEmergency: Used for emergency situations that require immediate action @@ -56765,6 +56774,9 @@ definitions: - groupAdmin: non-sensitive protocol parameters Used for administrative tasks like changing sensitive + - groupEmpty: protocol parameters or moving funds + + Used for empty policy, no action is allowed title: PolicyType defines the type of policy authorityQueryGetChainInfoResponse: type: object diff --git a/docs/spec/authority/messages.md b/docs/spec/authority/messages.md index 899a95b989..8ee4264bab 100644 --- a/docs/spec/authority/messages.md +++ b/docs/spec/authority/messages.md @@ -23,3 +23,27 @@ message MsgUpdateChainInfo { } ``` +## MsgAddAuthorization + +AddAuthorization defines a method to add an authorization.If the authorization already exists, it will be overwritten with the provided policy. +This should be called by the admin policy account. + +```proto +message MsgAddAuthorization { + string creator = 1; + string msg_url = 2; + PolicyType authorized_policy = 3; +} +``` + +## MsgRemoveAuthorization + +RemoveAuthorization removes the authorization from the list. It should be called by the admin policy account. + +```proto +message MsgRemoveAuthorization { + string creator = 1; + string msg_url = 2; +} +``` + diff --git a/proto/zetachain/zetacore/authority/policies.proto b/proto/zetachain/zetacore/authority/policies.proto index b02f448514..faefdbf2c7 100644 --- a/proto/zetachain/zetacore/authority/policies.proto +++ b/proto/zetachain/zetacore/authority/policies.proto @@ -14,6 +14,7 @@ enum PolicyType { // non-sensitive protocol parameters groupAdmin = 2; // Used for administrative tasks like changing sensitive // protocol parameters or moving funds + groupEmpty = 3; // Used for empty policy, no action is allowed } message Policy { diff --git a/proto/zetachain/zetacore/authority/tx.proto b/proto/zetachain/zetacore/authority/tx.proto index 55509e3172..29b1b44362 100644 --- a/proto/zetachain/zetacore/authority/tx.proto +++ b/proto/zetachain/zetacore/authority/tx.proto @@ -12,8 +12,35 @@ option go_package = "github.com/zeta-chain/zetacore/x/authority/types"; service Msg { rpc UpdatePolicies(MsgUpdatePolicies) returns (MsgUpdatePoliciesResponse); rpc UpdateChainInfo(MsgUpdateChainInfo) returns (MsgUpdateChainInfoResponse); + rpc AddAuthorization(MsgAddAuthorization) + returns (MsgAddAuthorizationResponse); + rpc RemoveAuthorization(MsgRemoveAuthorization) + returns (MsgRemoveAuthorizationResponse); } +// MsgAddAuthorization defines the MsgAddAuthorization service. +// Adds an authorization to the chain. If the authorization already exists, it +// will be updated. +message MsgAddAuthorization { + string creator = 1; + string msg_url = 2; + PolicyType authorized_policy = 3; +} + +// MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. +message MsgAddAuthorizationResponse {} + +// MsgRemoveAuthorization defines the MsgRemoveAuthorization service. +// Removes an authorization from the chain. +message MsgRemoveAuthorization { + string creator = 1; + string msg_url = 2; +} + +// MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse +// service. +message MsgRemoveAuthorizationResponse {} + // MsgUpdatePolicies defines the MsgUpdatePolicies service. message MsgUpdatePolicies { string creator = 1; diff --git a/testutil/keeper/authority.go b/testutil/keeper/authority.go index 3e7f98b506..be9101d1df 100644 --- a/testutil/keeper/authority.go +++ b/testutil/keeper/authority.go @@ -79,7 +79,7 @@ func MockIsAuthorized(m *mock.Mock, address string, policyType types.PolicyType, m.On("IsAuthorized", mock.Anything, address, policyType).Return(isAuthorized).Once() } -func SetAdminPolices(ctx sdk.Context, ak *keeper.Keeper) string { +func SetAdminPolicies(ctx sdk.Context, ak *keeper.Keeper) string { admin := sample.AccAddress() ak.SetPolicies(ctx, types.Policies{Items: []*types.Policy{ { diff --git a/typescript/zetachain/zetacore/authority/policies_pb.d.ts b/typescript/zetachain/zetacore/authority/policies_pb.d.ts index 21646f273a..8bf6b71c00 100644 --- a/typescript/zetachain/zetacore/authority/policies_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/policies_pb.d.ts @@ -34,6 +34,15 @@ export declare enum PolicyType { * @generated from enum value: groupAdmin = 2; */ groupAdmin = 2, + + /** + * protocol parameters or moving funds + * + * Used for empty policy, no action is allowed + * + * @generated from enum value: groupEmpty = 3; + */ + groupEmpty = 3, } /** diff --git a/typescript/zetachain/zetacore/authority/tx_pb.d.ts b/typescript/zetachain/zetacore/authority/tx_pb.d.ts index bd531ac2e5..827b942c9b 100644 --- a/typescript/zetachain/zetacore/authority/tx_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/tx_pb.d.ts @@ -5,9 +5,122 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import type { Policies } from "./policies_pb.js"; +import type { Policies, PolicyType } from "./policies_pb.js"; import type { ChainInfo } from "./chain_info_pb.js"; +/** + * MsgAddAuthorization defines the MsgAddAuthorization service. + * Adds an authorization to the chain. If the authorization already exists, it + * will be updated. + * + * @generated from message zetachain.zetacore.authority.MsgAddAuthorization + */ +export declare class MsgAddAuthorization extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: string msg_url = 2; + */ + msgUrl: string; + + /** + * @generated from field: zetachain.zetacore.authority.PolicyType authorized_policy = 3; + */ + authorizedPolicy: PolicyType; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgAddAuthorization"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddAuthorization; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddAuthorization; + + static fromJsonString(jsonString: string, options?: Partial): MsgAddAuthorization; + + static equals(a: MsgAddAuthorization | PlainMessage | undefined, b: MsgAddAuthorization | PlainMessage | undefined): boolean; +} + +/** + * MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. + * + * @generated from message zetachain.zetacore.authority.MsgAddAuthorizationResponse + */ +export declare class MsgAddAuthorizationResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgAddAuthorizationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddAuthorizationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddAuthorizationResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgAddAuthorizationResponse; + + static equals(a: MsgAddAuthorizationResponse | PlainMessage | undefined, b: MsgAddAuthorizationResponse | PlainMessage | undefined): boolean; +} + +/** + * MsgRemoveAuthorization defines the MsgRemoveAuthorization service. + * Removes an authorization from the chain. + * + * @generated from message zetachain.zetacore.authority.MsgRemoveAuthorization + */ +export declare class MsgRemoveAuthorization extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: string msg_url = 2; + */ + msgUrl: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgRemoveAuthorization"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgRemoveAuthorization; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgRemoveAuthorization; + + static fromJsonString(jsonString: string, options?: Partial): MsgRemoveAuthorization; + + static equals(a: MsgRemoveAuthorization | PlainMessage | undefined, b: MsgRemoveAuthorization | PlainMessage | undefined): boolean; +} + +/** + * MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse + * service. + * + * @generated from message zetachain.zetacore.authority.MsgRemoveAuthorizationResponse + */ +export declare class MsgRemoveAuthorizationResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgRemoveAuthorizationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgRemoveAuthorizationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgRemoveAuthorizationResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgRemoveAuthorizationResponse; + + static equals(a: MsgRemoveAuthorizationResponse | PlainMessage | undefined, b: MsgRemoveAuthorizationResponse | PlainMessage | undefined): boolean; +} + /** * MsgUpdatePolicies defines the MsgUpdatePolicies service. * diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 1455773bf5..8c1c1396db 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -20,8 +20,10 @@ func GetTxCmd() *cobra.Command { } cmd.AddCommand( - CmdUpdatePolices(), + CmdUpdatePolicies(), CmdUpdateChainInfo(), + CmdAddAuthorization(), + CmdRemoveAuthorization(), ) return cmd diff --git a/x/authority/client/cli/tx_add_authorization.go b/x/authority/client/cli/tx_add_authorization.go new file mode 100644 index 0000000000..5658d24e91 --- /dev/null +++ b/x/authority/client/cli/tx_add_authorization.go @@ -0,0 +1,61 @@ +package cli + +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func CmdAddAuthorization() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-authorization [msg-url] [authorized-policy]", + Short: "Add a new authorization or update the policy of an existing authorization. Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin.", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + authorizedPolicy, err := GetPolicyType(args[1]) + if err != nil { + return err + } + msg := &types.MsgAddAuthorization{ + MsgUrl: args[0], + AuthorizedPolicy: authorizedPolicy, + } + err = msg.ValidateBasic() + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func GetPolicyType(policyTypeString string) (types.PolicyType, error) { + policyType, err := strconv.ParseInt(policyTypeString, 10, 64) + if err != nil { + return types.PolicyType_groupEmpty, fmt.Errorf("failed to parse policy type: %w", err) + } + + switch policyType { + case 0: + return types.PolicyType_groupEmergency, nil + case 1: + return types.PolicyType_groupOperational, nil + case 2: + return types.PolicyType_groupAdmin, nil + default: + return types.PolicyType_groupEmpty, fmt.Errorf("invalid policy type value: %d", policyType) + } + +} diff --git a/x/authority/client/cli/tx_add_authorizations_test.go b/x/authority/client/cli/tx_add_authorizations_test.go new file mode 100644 index 0000000000..5c5042ee36 --- /dev/null +++ b/x/authority/client/cli/tx_add_authorizations_test.go @@ -0,0 +1,60 @@ +package cli_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/x/authority/client/cli" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func Test_GetPolicyType(t *testing.T) { + tt := []struct { + name string + policyTypeString string + expectedPolicyType types.PolicyType + expecterErrorString string + }{ + { + name: "groupEmergency", + policyTypeString: "0", + expectedPolicyType: types.PolicyType_groupEmergency, + expecterErrorString: "", + }, + { + name: "groupOperational", + policyTypeString: "1", + expectedPolicyType: types.PolicyType_groupOperational, + expecterErrorString: "", + }, + { + name: "groupAdmin", + policyTypeString: "2", + expectedPolicyType: types.PolicyType_groupAdmin, + expecterErrorString: "", + }, + { + name: "groupEmpty", + policyTypeString: "3", + expectedPolicyType: types.PolicyType_groupEmpty, + expecterErrorString: "invalid policy type value", + }, + { + name: "string literal for policy type not accepted", + policyTypeString: "groupEmergency", + expectedPolicyType: types.PolicyType_groupEmpty, + expecterErrorString: "failed to parse policy type", + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + policyType, err := cli.GetPolicyType(tc.policyTypeString) + require.Equal(t, tc.expectedPolicyType, policyType) + if tc.expectedPolicyType == types.PolicyType_groupEmpty { + require.ErrorContains(t, err, tc.expecterErrorString) + } + }) + } + +} diff --git a/x/authority/client/cli/tx_remove_authorization.go b/x/authority/client/cli/tx_remove_authorization.go new file mode 100644 index 0000000000..3fee09f12f --- /dev/null +++ b/x/authority/client/cli/tx_remove_authorization.go @@ -0,0 +1,34 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func CmdRemoveAuthorization() *cobra.Command { + cmd := &cobra.Command{ + Use: "remove-authorization [msg-url]", + Short: "removes an existing authorization", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + msg := &types.MsgRemoveAuthorization{ + MsgUrl: args[0], + } + err = msg.ValidateBasic() + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/authority/client/cli/tx_update_policies.go b/x/authority/client/cli/tx_update_policies.go index 19bfe6ab4f..69b8cd71f0 100644 --- a/x/authority/client/cli/tx_update_policies.go +++ b/x/authority/client/cli/tx_update_policies.go @@ -14,10 +14,10 @@ import ( "github.com/zeta-chain/zetacore/x/authority/types" ) -func CmdUpdatePolices() *cobra.Command { +func CmdUpdatePolicies() *cobra.Command { cmd := &cobra.Command{ Use: "update-policies [policies-json-file]", - Short: "Update the policies", + Short: "Update policies to values provided in the JSON file.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { policies, err := ReadPoliciesFromFile(os.DirFS("."), args[0]) diff --git a/x/authority/keeper/msg_server_add_authorization.go b/x/authority/keeper/msg_server_add_authorization.go new file mode 100644 index 0000000000..252884cd3f --- /dev/null +++ b/x/authority/keeper/msg_server_add_authorization.go @@ -0,0 +1,41 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +// AddAuthorization defines a method to add an authorization.If the authorization already exists, it will be overwritten with the provided policy. +// This should be called by the admin policy account. +func (k msgServer) AddAuthorization( + goCtx context.Context, + msg *types.MsgAddAuthorization, +) (*types.MsgAddAuthorizationResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { + return nil, errorsmod.Wrap( + types.ErrUnauthorized, + "AddAuthorization can only be executed by the admin policy account", + ) + } + + authorizationList, found := k.GetAuthorizationList(ctx) + if !found { + authorizationList = types.AuthorizationList{Authorizations: []types.Authorization{}} + } + authorizationList.SetAuthorization(types.Authorization{MsgUrl: msg.MsgUrl, AuthorizedPolicy: msg.AuthorizedPolicy}) + + // validate the authorization list after adding the authorization as a precautionary measure. + err := authorizationList.Validate() + if err != nil { + return nil, errorsmod.Wrap(err, "authorization list is invalid") + } + + k.SetAuthorizationList(ctx, authorizationList) + return &types.MsgAddAuthorizationResponse{}, nil +} diff --git a/x/authority/keeper/msg_server_add_authorization_test.go b/x/authority/keeper/msg_server_add_authorization_test.go new file mode 100644 index 0000000000..95c962951e --- /dev/null +++ b/x/authority/keeper/msg_server_add_authorization_test.go @@ -0,0 +1,219 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/keeper" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgServer_AddAuthorization(t *testing.T) { + const url = "/zetachain.zetacore.sample.ABC" + t.Run("successfully add authorization of type admin to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, prevLen+1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully add authorization of type operational to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupOperational, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupOperational, policy) + require.Equal(t, prevLen+1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully add authorization of type emergency to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupEmergency, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupEmergency, policy) + require.Equal(t, prevLen+1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully add authorization to empty authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.AuthorizationList{}) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, 1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully set authorization when list is not found ", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + msgServer := keeper.NewMsgServerImpl(*k) + authorizationList, found := k.GetAuthorizationList(ctx) + require.False(t, found) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, 1, len(authorizationList.Authorizations)) + }) + + t.Run("update existing authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "/zetachain.zetacore.sample.ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }, + } + k.SetAuthorizationList(ctx, authorizationList) + prevLen := len(authorizationList.Authorizations) + + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) + + t.Run("fail to add authorization with invalid policy as creator", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: sample.AccAddress(), + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrUnauthorized) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) + + // This scenario is not possible as the authorization list is always valid.But it is good to have in case the validation logic is changed in the future + t.Run("fail to set invalid authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + prevLen := len(authorizationList.Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrInvalidAuthorizationList) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) +} diff --git a/x/authority/keeper/msg_server_remove_authorization.go b/x/authority/keeper/msg_server_remove_authorization.go new file mode 100644 index 0000000000..f84e2fdffe --- /dev/null +++ b/x/authority/keeper/msg_server_remove_authorization.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "context" + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +// RemoveAuthorization defines a method to remove an authorization. +// This should be called by the admin policy account. +func (k msgServer) RemoveAuthorization( + goCtx context.Context, + msg *types.MsgRemoveAuthorization, +) (*types.MsgRemoveAuthorizationResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { + return nil, errorsmod.Wrap( + types.ErrUnauthorized, + "RemoveAuthorization can only be executed by the admin policy account", + ) + } + + // check if the authorization list exists, we can return early if there is no list. + authorizationList, found := k.GetAuthorizationList(ctx) + if !found { + return nil, types.ErrAuthorizationListNotFound + } + + // check if the authorization exists, we can return early if the authorization does not exist. + _, err := authorizationList.GetAuthorizedPolicy(msg.MsgUrl) + if err != nil { + return nil, errorsmod.Wrap(err, fmt.Sprintf("msg url %s", msg.MsgUrl)) + } + + // remove the authorization + authorizationList.RemoveAuthorization(msg.MsgUrl) + + // validate the authorization list after adding the authorization as a precautionary measure. + err = authorizationList.Validate() + if err != nil { + return nil, errorsmod.Wrap(err, "authorization list is invalid") + } + k.SetAuthorizationList(ctx, authorizationList) + + return &types.MsgRemoveAuthorizationResponse{}, nil +} diff --git a/x/authority/keeper/msg_server_remove_authorization_test.go b/x/authority/keeper/msg_server_remove_authorization_test.go new file mode 100644 index 0000000000..566369839a --- /dev/null +++ b/x/authority/keeper/msg_server_remove_authorization_test.go @@ -0,0 +1,204 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/keeper" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgServer_RemoveAuthorization(t *testing.T) { + t.Run("successfully remove operational policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + require.Equal(t, prevLen-1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully remove admin policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.AdminPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + require.Equal(t, prevLen-1, len(authorizationList.Authorizations)) + }) + + t.Run("successfully remove emergency policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.EmergencyPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + require.Equal(t, prevLen-1, len(authorizationList.Authorizations)) + }) + + t.Run("unable to remove authorization if creator is not the correct policy", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + prevLen := len(types.DefaultAuthorizationsList().Authorizations) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: sample.AccAddress(), + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrUnauthorized) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, types.DefaultAuthorizationsList(), authorizationList) + require.Equal(t, prevLen, len(authorizationList.Authorizations)) + }) + + t.Run("unable to remove authorization if authorization list does not exist", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + _, err := msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrAuthorizationListNotFound) + }) + + t.Run("unable to remove authorization if authorization does not exist", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + msgServer := keeper.NewMsgServerImpl(*k) + url := "invalid" + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + + authorizationListNew, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, authorizationList, authorizationListNew) + }) + + t.Run("unable to remove authorization if authorization list is invalid", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolicies(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: "ABC", + } + + _, err := msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrInvalidAuthorizationList) + + authorizationListNew, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, authorizationList, authorizationListNew) + }) +} diff --git a/x/authority/types/authorizations.go b/x/authority/types/authorizations.go index 0de98a768e..848b1da1d2 100644 --- a/x/authority/types/authorizations.go +++ b/x/authority/types/authorizations.go @@ -34,6 +34,8 @@ var ( "/zetachain.zetacore.fungible.MsgUpdateContractBytecode", "/zetachain.zetacore.fungible.MsgUpdateSystemContract", "/zetachain.zetacore.observer.MsgUpdateObserver", + "/zetachain.zetacore.authority.MsgAddAuthorization", + "/zetachain.zetacore.authority.MsgRemoveAuthorization", } // EmergencyPolicyMessages keeps track of the message URLs that can, by default, only be executed by emergency policy address EmergencyPolicyMessages = []string{ @@ -93,25 +95,24 @@ func (a *AuthorizationList) SetAuthorization(authorization Authorization) { a.Authorizations = append(a.Authorizations, authorization) } -// RemoveAuthorization removes the authorization from the list. It does not check if the authorization exists or not. -func (a *AuthorizationList) RemoveAuthorization(authorization Authorization) { +// RemoveAuthorization removes the authorization from the list. It should be called by the admin policy account. +func (a *AuthorizationList) RemoveAuthorization(msgURL string) { for i, auth := range a.Authorizations { - if auth.MsgUrl == authorization.MsgUrl { + if auth.MsgUrl == msgURL { a.Authorizations = append(a.Authorizations[:i], a.Authorizations[i+1:]...) + return } } } -// GetAuthorizedPolicy returns the policy for the given message url. If the message url is not found, - +// GetAuthorizedPolicy returns the policy for the given message url. If the message url is not found, it returns an error. func (a *AuthorizationList) GetAuthorizedPolicy(msgURL string) (PolicyType, error) { for _, auth := range a.Authorizations { if auth.MsgUrl == msgURL { return auth.AuthorizedPolicy, nil } } - // Returning first value of enum, can consider adding a default value of `EmptyPolicy` in the enum. - return PolicyType(0), ErrAuthorizationNotFound + return PolicyType_groupEmpty, ErrAuthorizationNotFound } // Validate checks if the authorization list is valid. It returns an error if the message url is duplicated with different policies. diff --git a/x/authority/types/authorizations_test.go b/x/authority/types/authorizations_test.go index 8bb7ed805a..009e958c15 100644 --- a/x/authority/types/authorizations_test.go +++ b/x/authority/types/authorizations_test.go @@ -176,21 +176,21 @@ func TestAuthorizationList_GetAuthorizations(t *testing.T) { }, }}, getPolicyMsgUrl: "XYZ", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, { name: "get authorizations fails when msg not found in list", authorizations: types.AuthorizationList{Authorizations: []types.Authorization{}}, getPolicyMsgUrl: "ABC", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, { name: "get authorizations fails when when queried for empty string", authorizations: types.AuthorizationList{Authorizations: []types.Authorization{}}, getPolicyMsgUrl: "", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, } @@ -275,10 +275,10 @@ func TestAuthorizationList_Validate(t *testing.T) { func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { tt := []struct { - name string - oldList types.AuthorizationList - removeAuthorization types.Authorization - expectedList types.AuthorizationList + name string + oldList types.AuthorizationList + removeMsgUrl string + expectedList types.AuthorizationList }{ { name: "remove authorization successfully", @@ -292,9 +292,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "ABC", - }, + removeMsgUrl: "ABC", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "XYZ", @@ -318,9 +316,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "ABC", @@ -333,11 +329,9 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { }}, }, { - name: "do not remove anything when trying to remove from an empty list", - oldList: types.AuthorizationList{Authorizations: []types.Authorization{}}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + name: "do not remove anything when trying to remove from an empty list", + oldList: types.AuthorizationList{Authorizations: []types.Authorization{}}, + removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{}}, }, { @@ -348,9 +342,28 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + removeMsgUrl: "XYZ", + expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }}, + }, + // The list is invalid, but this test case tries to assert the expected functionality + { + name: "return after removing first occurrence", + oldList: types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }}, + removeMsgUrl: "ABC", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "ABC", @@ -361,7 +374,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { - tc.oldList.RemoveAuthorization(tc.removeAuthorization) + tc.oldList.RemoveAuthorization(tc.removeMsgUrl) require.Equal(t, tc.expectedList, tc.oldList) }) } @@ -407,6 +420,8 @@ func TestDefaultAuthorizationsList(t *testing.T) { sdk.MsgTypeURL(&fungibletypes.MsgUpdateContractBytecode{}), sdk.MsgTypeURL(&fungibletypes.MsgUpdateSystemContract{}), sdk.MsgTypeURL(&observertypes.MsgUpdateObserver{}), + sdk.MsgTypeURL(&types.MsgAddAuthorization{}), + sdk.MsgTypeURL(&types.MsgRemoveAuthorization{}), } defaultList := types.DefaultAuthorizationsList() for _, msgUrl := range OperationalPolicyMessageList { diff --git a/x/authority/types/errors.go b/x/authority/types/errors.go index 88b44b9887..9d9509e9d4 100644 --- a/x/authority/types/errors.go +++ b/x/authority/types/errors.go @@ -3,7 +3,8 @@ package types import errorsmod "cosmossdk.io/errors" var ( - ErrUnauthorized = errorsmod.Register(ModuleName, 1102, "sender not authorized") - ErrInvalidAuthorizationList = errorsmod.Register(ModuleName, 1103, "invalid authorization list") - ErrAuthorizationNotFound = errorsmod.Register(ModuleName, 1104, "authorization not found") + ErrUnauthorized = errorsmod.Register(ModuleName, 1102, "sender not authorized") + ErrInvalidAuthorizationList = errorsmod.Register(ModuleName, 1103, "invalid authorization list") + ErrAuthorizationNotFound = errorsmod.Register(ModuleName, 1104, "authorization not found") + ErrAuthorizationListNotFound = errorsmod.Register(ModuleName, 1105, "authorization list not found") ) diff --git a/x/authority/types/message_add_authorization.go b/x/authority/types/message_add_authorization.go new file mode 100644 index 0000000000..0de3162a78 --- /dev/null +++ b/x/authority/types/message_add_authorization.go @@ -0,0 +1,65 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgAddAuthorization = "AddAuthorization" + +var _ sdk.Msg = &MsgAddAuthorization{} + +func NewMsgAddAuthorization(creator string, msgURL string, authorizedPolicy PolicyType) *MsgAddAuthorization { + return &MsgAddAuthorization{ + Creator: creator, + MsgUrl: msgURL, + AuthorizedPolicy: authorizedPolicy, + } +} + +func (msg *MsgAddAuthorization) Route() string { + return RouterKey +} + +func (msg *MsgAddAuthorization) Type() string { + return TypeMsgAddAuthorization +} + +func (msg *MsgAddAuthorization) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (msg *MsgAddAuthorization) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgAddAuthorization) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + // the authorized policy must be valid + if err := msg.AuthorizedPolicy.Validate(); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authorized policy: %s", err.Error()) + } + + // the message URL must be valid + if err := ValidateMsgURL(msg.MsgUrl); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) + } + + return nil +} + +func ValidateMsgURL(url string) error { + if len(url) == 0 { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "message URL cannot be empty") + } + return nil +} diff --git a/x/authority/types/message_add_authorizations_test.go b/x/authority/types/message_add_authorizations_test.go new file mode 100644 index 0000000000..dcc970adbd --- /dev/null +++ b/x/authority/types/message_add_authorizations_test.go @@ -0,0 +1,130 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgAddAuthorization_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg *types.MsgAddAuthorization + expectErr require.ErrorAssertionFunc + }{ + { + name: "invalid creator address", + msg: types.NewMsgAddAuthorization("invalid", "url", types.PolicyType_groupAdmin), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.ErrorContains(t, err, "invalid creator address") + }, + }, + { + name: "invalid authorized policy", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupEmpty), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "invalid authorized policy") + }, + }, + { + name: "invalid msg url", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "", types.PolicyType_groupAdmin), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "invalid msg url") + }, + }, + { + name: "valid message", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin), + expectErr: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.expectErr(t, tt.msg.ValidateBasic()) + }) + } +} + +func TestMsgAddAuthorization_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgAddAuthorization + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgAddAuthorization(signer, "url", types.PolicyType_groupAdmin), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgAddAuthorization("creator", "url", types.PolicyType_groupAdmin), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgAddAuthorization_Type(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.Equal(t, types.TypeMsgAddAuthorization, msg.Type()) +} + +func TestMsgAddAuthorization_Route(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgAddAuthorization_GetSignBytes(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} + +func TestValidateMsgUrl(t *testing.T) { + tests := []struct { + name string + url string + expectErr error + }{ + { + name: "empty url", + url: "", + expectErr: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid url", + url: "/zetachain.zetacore.crosschain.MsgRefundAbortedCCTX", + expectErr: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := types.ValidateMsgURL(tt.url) + require.ErrorIs(t, err, tt.expectErr) + }) + } +} diff --git a/x/authority/types/message_remove_authorization.go b/x/authority/types/message_remove_authorization.go new file mode 100644 index 0000000000..2404282088 --- /dev/null +++ b/x/authority/types/message_remove_authorization.go @@ -0,0 +1,51 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeRemoveAuthorization = "RemoveAuthorization" + +var _ sdk.Msg = &MsgRemoveAuthorization{} + +func NewMsgRemoveAuthorization(creator string, msgURL string) *MsgRemoveAuthorization { + return &MsgRemoveAuthorization{ + Creator: creator, + MsgUrl: msgURL, + } +} + +func (msg *MsgRemoveAuthorization) Route() string { + return RouterKey +} + +func (msg *MsgRemoveAuthorization) Type() string { + return TypeRemoveAuthorization +} + +func (msg *MsgRemoveAuthorization) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (msg *MsgRemoveAuthorization) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRemoveAuthorization) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if err := ValidateMsgURL(msg.MsgUrl); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) + } + + return nil +} diff --git a/x/authority/types/message_remove_authorizations_test.go b/x/authority/types/message_remove_authorizations_test.go new file mode 100644 index 0000000000..d9e35e45e0 --- /dev/null +++ b/x/authority/types/message_remove_authorizations_test.go @@ -0,0 +1,97 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgRemoveAuthorization_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg *types.MsgRemoveAuthorization + expectErr require.ErrorAssertionFunc + }{ + { + name: "invalid creator address", + msg: types.NewMsgRemoveAuthorization("invalid", "url"), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.ErrorContains(t, err, "invalid creator address") + }, + }, + { + name: "invalid msg url", + msg: types.NewMsgRemoveAuthorization(sample.AccAddress(), ""), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorContains(t, err, "invalid msg url") + }, + }, + { + name: "valid message", + msg: types.NewMsgRemoveAuthorization(sample.AccAddress(), "url"), + expectErr: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.expectErr(t, tt.msg.ValidateBasic()) + }) + } +} + +func TestMsgRemoveAuthorization_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgRemoveAuthorization + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgRemoveAuthorization(signer, "url"), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgRemoveAuthorization("creator", "url"), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgRemoveAuthorization_Type(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.Equal(t, types.TypeRemoveAuthorization, msg.Type()) +} + +func TestMsgRemoveAuthorization_Route(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgRemoveAuthorization_GetSignBytes(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/authority/types/policies.go b/x/authority/types/policies.go index 28a97594ce..af3642bfd7 100644 --- a/x/authority/types/policies.go +++ b/x/authority/types/policies.go @@ -42,9 +42,8 @@ func (p Policies) Validate() error { return fmt.Errorf("invalid address: %s", err) } - if policy.PolicyType != PolicyType_groupEmergency && policy.PolicyType != PolicyType_groupAdmin && - policy.PolicyType != PolicyType_groupOperational { - return fmt.Errorf("invalid policy type: %s", policy.PolicyType) + if err := policy.PolicyType.Validate(); err != nil { + return err } if policyTypeMap[policy.PolicyType] { diff --git a/x/authority/types/policies.pb.go b/x/authority/types/policies.pb.go index 3b2eda6564..c67621c996 100644 --- a/x/authority/types/policies.pb.go +++ b/x/authority/types/policies.pb.go @@ -31,18 +31,22 @@ const ( PolicyType_groupOperational PolicyType = 1 // non-sensitive protocol parameters PolicyType_groupAdmin PolicyType = 2 + // protocol parameters or moving funds + PolicyType_groupEmpty PolicyType = 3 ) var PolicyType_name = map[int32]string{ 0: "groupEmergency", 1: "groupOperational", 2: "groupAdmin", + 3: "groupEmpty", } var PolicyType_value = map[string]int32{ "groupEmergency": 0, "groupOperational": 1, "groupAdmin": 2, + "groupEmpty": 3, } func (x PolicyType) String() string { @@ -161,26 +165,27 @@ func init() { } var fileDescriptor_afa9e3e7b996ef74 = []byte{ - // 303 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xae, 0x4a, 0x2d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x13, 0x4b, 0x4b, 0x32, - 0xf2, 0x8b, 0x32, 0x4b, 0x2a, 0xf5, 0x0b, 0xf2, 0x73, 0x32, 0x93, 0x33, 0x53, 0x8b, 0xf5, 0x0a, - 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x64, 0xe0, 0x8a, 0xf5, 0x60, 0x8a, 0xf5, 0xe0, 0x8a, 0xa5, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x0a, 0xf5, 0x41, 0x2c, 0x88, 0x1e, 0xa5, 0x5c, 0x2e, 0xb6, 0x00, - 0x90, 0x29, 0x95, 0x42, 0x9e, 0x5c, 0xdc, 0x60, 0xf3, 0x2a, 0xe3, 0x4b, 0x2a, 0x0b, 0x52, 0x25, - 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x34, 0xf4, 0xf0, 0x99, 0xa9, 0x07, 0xd1, 0x1a, 0x52, 0x59, - 0x90, 0x1a, 0xc4, 0x55, 0x00, 0x67, 0x0b, 0x49, 0x70, 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, - 0x17, 0x4b, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x4a, 0x6e, 0x5c, 0x1c, 0x01, 0x50, - 0x47, 0x0b, 0x59, 0x71, 0xb1, 0x66, 0x96, 0xa4, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, - 0x1b, 0xa9, 0x10, 0x63, 0x55, 0x10, 0x44, 0x8b, 0x96, 0x0f, 0x17, 0x17, 0xc2, 0x6e, 0x21, 0x21, - 0x2e, 0xbe, 0xf4, 0xa2, 0xfc, 0xd2, 0x02, 0xd7, 0xdc, 0xd4, 0xa2, 0xf4, 0xd4, 0xbc, 0xe4, 0x4a, - 0x01, 0x06, 0x21, 0x11, 0x2e, 0x01, 0xb0, 0x98, 0x7f, 0x41, 0x6a, 0x51, 0x62, 0x49, 0x66, 0x7e, - 0x5e, 0x62, 0x8e, 0x00, 0xa3, 0x10, 0x1f, 0x17, 0x17, 0x58, 0xd4, 0x31, 0x25, 0x37, 0x33, 0x4f, - 0x80, 0x49, 0x8a, 0x65, 0xc5, 0x12, 0x39, 0x46, 0x27, 0xaf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, - 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, - 0x3c, 0x96, 0x63, 0x88, 0x32, 0x48, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x05, - 0x47, 0x80, 0x2e, 0x5a, 0x5c, 0x54, 0x20, 0xc5, 0x06, 0x28, 0xd8, 0x8a, 0x93, 0xd8, 0xc0, 0xe1, - 0x6a, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x91, 0xe5, 0xab, 0xba, 0x01, 0x00, 0x00, + // 310 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x51, 0xc1, 0x4a, 0x03, 0x31, + 0x14, 0xdc, 0xb4, 0x5a, 0xf5, 0x15, 0xca, 0x12, 0x7a, 0x58, 0x8a, 0x84, 0x52, 0x3c, 0x2c, 0x8a, + 0x59, 0xa9, 0x37, 0x6f, 0x0a, 0x15, 0xf4, 0x62, 0x29, 0x9e, 0x44, 0x90, 0x74, 0x1b, 0xb6, 0x81, + 0x66, 0x13, 0xb2, 0x29, 0x18, 0xbf, 0xc2, 0x8f, 0xf0, 0xe0, 0xa7, 0x78, 0xec, 0xd1, 0xa3, 0xb4, + 0x3f, 0x22, 0xcd, 0xda, 0x55, 0x3c, 0x88, 0xb7, 0x79, 0x8f, 0x99, 0x79, 0x8f, 0x19, 0x38, 0x7a, + 0xe2, 0x96, 0xa5, 0x53, 0x26, 0xf2, 0xc4, 0x23, 0x65, 0x78, 0xc2, 0xe6, 0x76, 0xaa, 0x8c, 0xb0, + 0x2e, 0xd1, 0x6a, 0x26, 0x52, 0xc1, 0x0b, 0xaa, 0x8d, 0xb2, 0x0a, 0xef, 0x57, 0x64, 0xba, 0x21, + 0xd3, 0x8a, 0xdc, 0x69, 0x67, 0x2a, 0x53, 0x9e, 0x98, 0xac, 0x51, 0xa9, 0xe9, 0x49, 0x68, 0x0c, + 0xd7, 0x2e, 0x0e, 0x5f, 0x41, 0xd3, 0xfb, 0xb9, 0x07, 0xeb, 0x34, 0x8f, 0x50, 0x17, 0xc5, 0xad, + 0x7e, 0x4c, 0xff, 0xf2, 0xa4, 0xa5, 0xf4, 0xd6, 0x69, 0x3e, 0x02, 0x5d, 0x61, 0x1c, 0xc1, 0x0e, + 0x9b, 0x4c, 0x0c, 0x2f, 0x8a, 0xa8, 0xd6, 0x45, 0xf1, 0xde, 0x68, 0x33, 0xf6, 0x2e, 0x61, 0x77, + 0xf8, 0xf5, 0x34, 0x3e, 0x83, 0x6d, 0x61, 0xb9, 0x2c, 0x22, 0xd4, 0xad, 0xc7, 0xcd, 0xfe, 0xc1, + 0x7f, 0x4e, 0x8d, 0x4a, 0xc9, 0xe1, 0x3d, 0xc0, 0xf7, 0x6d, 0x8c, 0xa1, 0x95, 0x19, 0x35, 0xd7, + 0x03, 0xc9, 0x4d, 0xc6, 0xf3, 0xd4, 0x85, 0x01, 0x6e, 0x43, 0xe8, 0x77, 0x37, 0x9a, 0x1b, 0x66, + 0x85, 0xca, 0xd9, 0x2c, 0x44, 0xb8, 0x05, 0xe0, 0xb7, 0xe7, 0x13, 0x29, 0xf2, 0xb0, 0x56, 0xcd, + 0x03, 0xa9, 0xad, 0x0b, 0xeb, 0x9d, 0xad, 0xd7, 0x17, 0x82, 0x2e, 0xae, 0xdf, 0x96, 0x04, 0x2d, + 0x96, 0x04, 0x7d, 0x2c, 0x09, 0x7a, 0x5e, 0x91, 0x60, 0xb1, 0x22, 0xc1, 0xfb, 0x8a, 0x04, 0x77, + 0x27, 0x99, 0xb0, 0xd3, 0xf9, 0x98, 0xa6, 0x4a, 0xfa, 0x42, 0x8e, 0x7f, 0x75, 0xf3, 0xf8, 0xa3, + 0x9d, 0x75, 0x8c, 0xc5, 0xb8, 0xe1, 0x73, 0x3e, 0xfd, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x37, 0x5d, + 0x49, 0x63, 0xca, 0x01, 0x00, 0x00, } func (m *Policy) Marshal() (dAtA []byte, err error) { diff --git a/x/authority/types/policy_type.go b/x/authority/types/policy_type.go new file mode 100644 index 0000000000..c3593e7fae --- /dev/null +++ b/x/authority/types/policy_type.go @@ -0,0 +1,13 @@ +package types + +import "fmt" + +// Validate PolicyType validates the policy type. +// Valid policy types are groupEmergency, groupOperational, and groupAdmin. +func (p PolicyType) Validate() error { + if p != PolicyType_groupEmergency && p != PolicyType_groupAdmin && + p != PolicyType_groupOperational { + return fmt.Errorf("invalid policy type: %s", p) + } + return nil +} diff --git a/x/authority/types/policy_type_test.go b/x/authority/types/policy_type_test.go new file mode 100644 index 0000000000..c6778c9200 --- /dev/null +++ b/x/authority/types/policy_type_test.go @@ -0,0 +1,58 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestPolicyType_Validate(t *testing.T) { + tests := []struct { + name string + policyType types.PolicyType + wantErr bool + }{ + { + name: "valid groupEmergency", + policyType: types.PolicyType_groupEmergency, + wantErr: false, + }, + { + name: "valid groupOperational", + policyType: types.PolicyType_groupOperational, + wantErr: false, + }, + { + name: "valid groupAdmin", + policyType: types.PolicyType_groupAdmin, + wantErr: false, + }, + { + name: "invalid policy type", + policyType: types.PolicyType(20), + wantErr: true, + }, + { + name: "invalid policy type more than max length", + policyType: types.PolicyType(len(types.PolicyType_name) + 1), + wantErr: true, + }, + { + name: "empty policy type", + policyType: types.PolicyType_groupEmpty, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.policyType.Validate() + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/authority/types/tx.pb.go b/x/authority/types/tx.pb.go index ac5c04416b..928353417f 100644 --- a/x/authority/types/tx.pb.go +++ b/x/authority/types/tx.pb.go @@ -28,6 +28,198 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgAddAuthorization defines the MsgAddAuthorization service. +// Adds an authorization to the chain. If the authorization already exists, it +// will be updated. +type MsgAddAuthorization struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + MsgUrl string `protobuf:"bytes,2,opt,name=msg_url,json=msgUrl,proto3" json:"msg_url,omitempty"` + AuthorizedPolicy PolicyType `protobuf:"varint,3,opt,name=authorized_policy,json=authorizedPolicy,proto3,enum=zetachain.zetacore.authority.PolicyType" json:"authorized_policy,omitempty"` +} + +func (m *MsgAddAuthorization) Reset() { *m = MsgAddAuthorization{} } +func (m *MsgAddAuthorization) String() string { return proto.CompactTextString(m) } +func (*MsgAddAuthorization) ProtoMessage() {} +func (*MsgAddAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{0} +} +func (m *MsgAddAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAuthorization.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAuthorization.Merge(m, src) +} +func (m *MsgAddAuthorization) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAuthorization proto.InternalMessageInfo + +func (m *MsgAddAuthorization) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgAddAuthorization) GetMsgUrl() string { + if m != nil { + return m.MsgUrl + } + return "" +} + +func (m *MsgAddAuthorization) GetAuthorizedPolicy() PolicyType { + if m != nil { + return m.AuthorizedPolicy + } + return PolicyType_groupEmergency +} + +// MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. +type MsgAddAuthorizationResponse struct { +} + +func (m *MsgAddAuthorizationResponse) Reset() { *m = MsgAddAuthorizationResponse{} } +func (m *MsgAddAuthorizationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAddAuthorizationResponse) ProtoMessage() {} +func (*MsgAddAuthorizationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{1} +} +func (m *MsgAddAuthorizationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAuthorizationResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddAuthorizationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAuthorizationResponse.Merge(m, src) +} +func (m *MsgAddAuthorizationResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAuthorizationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAuthorizationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAuthorizationResponse proto.InternalMessageInfo + +// MsgRemoveAuthorization defines the MsgRemoveAuthorization service. +// Removes an authorization from the chain. +type MsgRemoveAuthorization struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + MsgUrl string `protobuf:"bytes,2,opt,name=msg_url,json=msgUrl,proto3" json:"msg_url,omitempty"` +} + +func (m *MsgRemoveAuthorization) Reset() { *m = MsgRemoveAuthorization{} } +func (m *MsgRemoveAuthorization) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAuthorization) ProtoMessage() {} +func (*MsgRemoveAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{2} +} +func (m *MsgRemoveAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAuthorization.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAuthorization.Merge(m, src) +} +func (m *MsgRemoveAuthorization) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAuthorization proto.InternalMessageInfo + +func (m *MsgRemoveAuthorization) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgRemoveAuthorization) GetMsgUrl() string { + if m != nil { + return m.MsgUrl + } + return "" +} + +// MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse +// service. +type MsgRemoveAuthorizationResponse struct { +} + +func (m *MsgRemoveAuthorizationResponse) Reset() { *m = MsgRemoveAuthorizationResponse{} } +func (m *MsgRemoveAuthorizationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAuthorizationResponse) ProtoMessage() {} +func (*MsgRemoveAuthorizationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{3} +} +func (m *MsgRemoveAuthorizationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAuthorizationResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveAuthorizationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAuthorizationResponse.Merge(m, src) +} +func (m *MsgRemoveAuthorizationResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAuthorizationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAuthorizationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAuthorizationResponse proto.InternalMessageInfo + // MsgUpdatePolicies defines the MsgUpdatePolicies service. type MsgUpdatePolicies struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` @@ -38,7 +230,7 @@ func (m *MsgUpdatePolicies) Reset() { *m = MsgUpdatePolicies{} } func (m *MsgUpdatePolicies) String() string { return proto.CompactTextString(m) } func (*MsgUpdatePolicies) ProtoMessage() {} func (*MsgUpdatePolicies) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{0} + return fileDescriptor_42e081863c477116, []int{4} } func (m *MsgUpdatePolicies) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -89,7 +281,7 @@ func (m *MsgUpdatePoliciesResponse) Reset() { *m = MsgUpdatePoliciesResp func (m *MsgUpdatePoliciesResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdatePoliciesResponse) ProtoMessage() {} func (*MsgUpdatePoliciesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{1} + return fileDescriptor_42e081863c477116, []int{5} } func (m *MsgUpdatePoliciesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -128,7 +320,7 @@ func (m *MsgUpdateChainInfo) Reset() { *m = MsgUpdateChainInfo{} } func (m *MsgUpdateChainInfo) String() string { return proto.CompactTextString(m) } func (*MsgUpdateChainInfo) ProtoMessage() {} func (*MsgUpdateChainInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{2} + return fileDescriptor_42e081863c477116, []int{6} } func (m *MsgUpdateChainInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -179,7 +371,7 @@ func (m *MsgUpdateChainInfoResponse) Reset() { *m = MsgUpdateChainInfoRe func (m *MsgUpdateChainInfoResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateChainInfoResponse) ProtoMessage() {} func (*MsgUpdateChainInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{3} + return fileDescriptor_42e081863c477116, []int{7} } func (m *MsgUpdateChainInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -209,6 +401,10 @@ func (m *MsgUpdateChainInfoResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateChainInfoResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgAddAuthorization)(nil), "zetachain.zetacore.authority.MsgAddAuthorization") + proto.RegisterType((*MsgAddAuthorizationResponse)(nil), "zetachain.zetacore.authority.MsgAddAuthorizationResponse") + proto.RegisterType((*MsgRemoveAuthorization)(nil), "zetachain.zetacore.authority.MsgRemoveAuthorization") + proto.RegisterType((*MsgRemoveAuthorizationResponse)(nil), "zetachain.zetacore.authority.MsgRemoveAuthorizationResponse") proto.RegisterType((*MsgUpdatePolicies)(nil), "zetachain.zetacore.authority.MsgUpdatePolicies") proto.RegisterType((*MsgUpdatePoliciesResponse)(nil), "zetachain.zetacore.authority.MsgUpdatePoliciesResponse") proto.RegisterType((*MsgUpdateChainInfo)(nil), "zetachain.zetacore.authority.MsgUpdateChainInfo") @@ -220,29 +416,38 @@ func init() { } var fileDescriptor_42e081863c477116 = []byte{ - // 350 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xad, 0x4a, 0x2d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x13, 0x4b, 0x4b, 0x32, - 0xf2, 0x8b, 0x32, 0x4b, 0x2a, 0xf5, 0x4b, 0x2a, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x64, - 0xe0, 0xca, 0xf4, 0x60, 0xca, 0xf4, 0xe0, 0xca, 0xa4, 0xb4, 0xf1, 0x1a, 0x52, 0x90, 0x9f, 0x93, - 0x99, 0x9c, 0x99, 0x5a, 0x0c, 0x31, 0x4a, 0x4a, 0x17, 0xaf, 0x62, 0xb0, 0x44, 0x7c, 0x66, 0x5e, - 0x5a, 0x3e, 0x54, 0xb9, 0x01, 0x5e, 0xe5, 0x50, 0x56, 0x55, 0x62, 0x49, 0x66, 0x7e, 0x1e, 0x54, - 0x87, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0xca, 0xb9, 0x04, - 0x7d, 0x8b, 0xd3, 0x43, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0x03, 0xa0, 0x2e, 0x12, 0x92, 0xe0, 0x62, - 0x4f, 0x2e, 0x4a, 0x4d, 0x2c, 0xc9, 0x2f, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0x71, - 0x85, 0x3c, 0xb8, 0x38, 0x60, 0xee, 0x96, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd3, 0xc3, - 0x17, 0x06, 0x7a, 0x30, 0x33, 0x9d, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xeb, 0x56, 0x92, - 0xe6, 0x92, 0xc4, 0xb0, 0x38, 0x28, 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xa9, 0x86, 0x4b, - 0x08, 0x2e, 0xe9, 0x0c, 0x32, 0xda, 0x33, 0x2f, 0x2d, 0x1f, 0x8f, 0xb3, 0x7c, 0xb8, 0xb8, 0x10, - 0x21, 0x04, 0x75, 0x98, 0x3a, 0x7e, 0x87, 0xc1, 0x8d, 0x85, 0xba, 0x8c, 0x33, 0x19, 0x26, 0xa0, - 0x24, 0xc3, 0x25, 0x85, 0x69, 0x3b, 0xcc, 0x6d, 0x46, 0x0d, 0x4c, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, - 0x42, 0x55, 0x5c, 0x7c, 0x68, 0xc1, 0xa6, 0x8f, 0xdf, 0x46, 0x0c, 0xef, 0x4a, 0x99, 0x93, 0xa8, - 0x01, 0xe6, 0x06, 0xa1, 0x5a, 0x2e, 0x7e, 0xf4, 0xc0, 0x31, 0x20, 0xd2, 0x2c, 0xb8, 0x0e, 0x29, - 0x0b, 0x52, 0x75, 0xc0, 0xac, 0x77, 0xf2, 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, - 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, - 0x86, 0x28, 0x83, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x70, 0xba, 0xd4, - 0x45, 0x4b, 0xa2, 0x15, 0xc8, 0xb9, 0xa8, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x9c, 0x0e, 0x8d, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xeb, 0xa6, 0x40, 0x72, 0x03, 0x00, 0x00, + // 487 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4f, 0x6f, 0xd3, 0x30, + 0x14, 0xaf, 0xd9, 0xb4, 0xb1, 0x87, 0x34, 0xb6, 0x0c, 0x41, 0xc9, 0x46, 0xa8, 0x22, 0x01, 0x95, + 0xd0, 0x92, 0x52, 0x90, 0x00, 0x89, 0xcb, 0xc6, 0x85, 0x7f, 0x95, 0xa6, 0x88, 0x5e, 0xb8, 0x54, + 0x59, 0xea, 0xb9, 0x96, 0xda, 0x38, 0x8a, 0x5d, 0x58, 0x2b, 0x90, 0xb8, 0x72, 0x82, 0x6f, 0xc0, + 0xd7, 0xd9, 0x71, 0x47, 0x4e, 0x08, 0xb5, 0x5f, 0x04, 0xcd, 0x8d, 0xbd, 0x29, 0x89, 0xbc, 0x16, + 0x6e, 0x2f, 0xf6, 0xef, 0x9f, 0x9f, 0xe3, 0x07, 0xf7, 0xc6, 0x58, 0x84, 0x51, 0x2f, 0xa4, 0xb1, + 0x2f, 0x2b, 0x96, 0x62, 0x3f, 0x1c, 0x8a, 0x1e, 0x4b, 0xa9, 0x18, 0xf9, 0xe2, 0xd8, 0x4b, 0x52, + 0x26, 0x98, 0xb5, 0xa3, 0x61, 0x9e, 0x82, 0x79, 0x1a, 0x66, 0x3f, 0x34, 0x8a, 0x24, 0xac, 0x4f, + 0x23, 0x8a, 0xf9, 0x4c, 0xca, 0xde, 0x35, 0x82, 0xe5, 0x46, 0x87, 0xc6, 0x47, 0x2c, 0x83, 0x37, + 0x8c, 0xf0, 0xac, 0x1a, 0x87, 0x82, 0xb2, 0x38, 0x63, 0xdc, 0x20, 0x8c, 0x30, 0x59, 0xfa, 0x67, + 0xd5, 0x6c, 0xd5, 0xfd, 0x89, 0x60, 0xab, 0xc5, 0xc9, 0x5e, 0xb7, 0xbb, 0x77, 0x91, 0x63, 0x55, + 0x61, 0x35, 0x4a, 0x71, 0x28, 0x58, 0x5a, 0x45, 0x35, 0x54, 0x5f, 0x0b, 0xd4, 0xa7, 0x75, 0x0b, + 0x56, 0x07, 0x9c, 0x74, 0x86, 0x69, 0xbf, 0x7a, 0x45, 0xee, 0xac, 0x0c, 0x38, 0x69, 0xa7, 0x7d, + 0xab, 0x0d, 0x9b, 0xca, 0x17, 0x77, 0x3b, 0xf2, 0x78, 0xa3, 0xea, 0x52, 0x0d, 0xd5, 0xd7, 0x9b, + 0x75, 0xcf, 0xd4, 0x28, 0xef, 0x40, 0x62, 0xdf, 0x8f, 0x12, 0x1c, 0x6c, 0x9c, 0x4b, 0xcc, 0x56, + 0xdd, 0x3b, 0xb0, 0x5d, 0x12, 0x30, 0xc0, 0x3c, 0x61, 0x31, 0xc7, 0xee, 0x5b, 0xb8, 0xd9, 0xe2, + 0x24, 0xc0, 0x03, 0xf6, 0x11, 0xff, 0xef, 0x11, 0xdc, 0x1a, 0x38, 0xe5, 0x62, 0xda, 0xee, 0x13, + 0x6c, 0xb6, 0x38, 0x69, 0x27, 0xdd, 0x50, 0xe0, 0x83, 0xec, 0x06, 0x0d, 0x4e, 0xaf, 0xe0, 0xaa, + 0xba, 0x67, 0x69, 0x75, 0xad, 0x79, 0x7f, 0x8e, 0x56, 0x50, 0xcc, 0xf7, 0x97, 0x4f, 0x7e, 0xdf, + 0xad, 0x04, 0x9a, 0xed, 0x6e, 0xc3, 0xed, 0x82, 0xb1, 0x4e, 0xf5, 0x19, 0x2c, 0xbd, 0xf9, 0xf2, + 0x4c, 0xfa, 0x75, 0x7c, 0xc4, 0x0c, 0xb1, 0xde, 0x01, 0x9c, 0xff, 0x51, 0x59, 0xb0, 0x07, 0xe6, + 0x60, 0x5a, 0x36, 0x4b, 0xb6, 0x16, 0xa9, 0x05, 0x77, 0x07, 0xec, 0xa2, 0xbb, 0xca, 0xd6, 0xfc, + 0xbe, 0x0c, 0x4b, 0x2d, 0x4e, 0xac, 0x31, 0xac, 0xe7, 0xda, 0xe6, 0x9b, 0x1d, 0x0b, 0xc7, 0xb5, + 0x9f, 0x2e, 0x48, 0x50, 0x19, 0xac, 0x2f, 0x70, 0x3d, 0xdf, 0x9c, 0xc6, 0x9c, 0x5a, 0x9a, 0x61, + 0x3f, 0x5b, 0x94, 0xa1, 0xed, 0xbf, 0x22, 0xd8, 0x28, 0xbc, 0xb0, 0x47, 0x97, 0xca, 0xe5, 0x29, + 0xf6, 0xf3, 0x85, 0x29, 0x3a, 0xc2, 0x37, 0x04, 0x5b, 0x65, 0x8f, 0xe4, 0xc9, 0xa5, 0x92, 0x25, + 0x2c, 0xfb, 0xc5, 0xbf, 0xb0, 0x54, 0x96, 0xfd, 0x37, 0x27, 0x13, 0x07, 0x9d, 0x4e, 0x1c, 0xf4, + 0x67, 0xe2, 0xa0, 0x1f, 0x53, 0xa7, 0x72, 0x3a, 0x75, 0x2a, 0xbf, 0xa6, 0x4e, 0xe5, 0x43, 0x83, + 0x50, 0xd1, 0x1b, 0x1e, 0x7a, 0x11, 0x1b, 0xc8, 0xb1, 0xb6, 0x9b, 0x9b, 0x70, 0xc7, 0x17, 0x87, + 0xf0, 0x28, 0xc1, 0xfc, 0x70, 0x45, 0x8e, 0xb1, 0xc7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x33, + 0xb2, 0x7c, 0x5f, 0xb1, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -259,6 +464,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { UpdatePolicies(ctx context.Context, in *MsgUpdatePolicies, opts ...grpc.CallOption) (*MsgUpdatePoliciesResponse, error) UpdateChainInfo(ctx context.Context, in *MsgUpdateChainInfo, opts ...grpc.CallOption) (*MsgUpdateChainInfoResponse, error) + AddAuthorization(ctx context.Context, in *MsgAddAuthorization, opts ...grpc.CallOption) (*MsgAddAuthorizationResponse, error) + RemoveAuthorization(ctx context.Context, in *MsgRemoveAuthorization, opts ...grpc.CallOption) (*MsgRemoveAuthorizationResponse, error) } type msgClient struct { @@ -287,10 +494,30 @@ func (c *msgClient) UpdateChainInfo(ctx context.Context, in *MsgUpdateChainInfo, return out, nil } +func (c *msgClient) AddAuthorization(ctx context.Context, in *MsgAddAuthorization, opts ...grpc.CallOption) (*MsgAddAuthorizationResponse, error) { + out := new(MsgAddAuthorizationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Msg/AddAuthorization", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveAuthorization(ctx context.Context, in *MsgRemoveAuthorization, opts ...grpc.CallOption) (*MsgRemoveAuthorizationResponse, error) { + out := new(MsgRemoveAuthorizationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Msg/RemoveAuthorization", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { UpdatePolicies(context.Context, *MsgUpdatePolicies) (*MsgUpdatePoliciesResponse, error) UpdateChainInfo(context.Context, *MsgUpdateChainInfo) (*MsgUpdateChainInfoResponse, error) + AddAuthorization(context.Context, *MsgAddAuthorization) (*MsgAddAuthorizationResponse, error) + RemoveAuthorization(context.Context, *MsgRemoveAuthorization) (*MsgRemoveAuthorizationResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -303,6 +530,12 @@ func (*UnimplementedMsgServer) UpdatePolicies(ctx context.Context, req *MsgUpdat func (*UnimplementedMsgServer) UpdateChainInfo(ctx context.Context, req *MsgUpdateChainInfo) (*MsgUpdateChainInfoResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateChainInfo not implemented") } +func (*UnimplementedMsgServer) AddAuthorization(ctx context.Context, req *MsgAddAuthorization) (*MsgAddAuthorizationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddAuthorization not implemented") +} +func (*UnimplementedMsgServer) RemoveAuthorization(ctx context.Context, req *MsgRemoveAuthorization) (*MsgRemoveAuthorizationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveAuthorization not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -344,6 +577,42 @@ func _Msg_UpdateChainInfo_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Msg_AddAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAddAuthorization) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AddAuthorization(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Msg/AddAuthorization", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AddAuthorization(ctx, req.(*MsgAddAuthorization)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveAuthorization) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveAuthorization(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Msg/RemoveAuthorization", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveAuthorization(ctx, req.(*MsgRemoveAuthorization)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.authority.Msg", HandlerType: (*MsgServer)(nil), @@ -356,12 +625,20 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateChainInfo", Handler: _Msg_UpdateChainInfo_Handler, }, + { + MethodName: "AddAuthorization", + Handler: _Msg_AddAuthorization_Handler, + }, + { + MethodName: "RemoveAuthorization", + Handler: _Msg_RemoveAuthorization_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "zetachain/zetacore/authority/tx.proto", } -func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { +func (m *MsgAddAuthorization) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -371,26 +648,28 @@ func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdatePolicies) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddAuthorization) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - { - size, err := m.Policies.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + if m.AuthorizedPolicy != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.AuthorizedPolicy)) + i-- + dAtA[i] = 0x18 + } + if len(m.MsgUrl) > 0 { + i -= len(m.MsgUrl) + copy(dAtA[i:], m.MsgUrl) + i = encodeVarintTx(dAtA, i, uint64(len(m.MsgUrl))) + i-- + dAtA[i] = 0x12 } - i-- - dAtA[i] = 0x12 if len(m.Creator) > 0 { i -= len(m.Creator) copy(dAtA[i:], m.Creator) @@ -401,7 +680,7 @@ func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgAddAuthorizationResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -411,12 +690,12 @@ func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdatePoliciesResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -424,7 +703,7 @@ func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { +func (m *MsgRemoveAuthorization) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -434,18 +713,78 @@ func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateChainInfo) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgRemoveAuthorization) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgRemoveAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.MsgUrl) > 0 { + i -= len(m.MsgUrl) + copy(dAtA[i:], m.MsgUrl) + i = encodeVarintTx(dAtA, i, uint64(len(m.MsgUrl))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRemoveAuthorizationResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdatePolicies) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.ChainInfo.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Policies.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -464,7 +803,7 @@ func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -474,12 +813,12 @@ func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateChainInfoResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpdatePoliciesResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -487,17 +826,135 @@ func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ +func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateChainInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ChainInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateChainInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ } dAtA[offset] = uint8(v) return base } +func (m *MsgAddAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MsgUrl) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.AuthorizedPolicy != 0 { + n += 1 + sovTx(uint64(m.AuthorizedPolicy)) + } + return n +} + +func (m *MsgAddAuthorizationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MsgUrl) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveAuthorizationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgUpdatePolicies) Size() (n int) { if m == nil { return 0 @@ -552,6 +1009,353 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *MsgAddAuthorization) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MsgUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthorizedPolicy", wireType) + } + m.AuthorizedPolicy = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AuthorizedPolicy |= PolicyType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAddAuthorizationResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddAuthorizationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveAuthorization) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MsgUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveAuthorizationResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveAuthorizationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *MsgUpdatePolicies) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/crosschain/keeper/evm_hooks_test.go b/x/crosschain/keeper/evm_hooks_test.go index 3ec4b49e65..80f8c3b28b 100644 --- a/x/crosschain/keeper/evm_hooks_test.go +++ b/x/crosschain/keeper/evm_hooks_test.go @@ -470,7 +470,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000") @@ -516,7 +516,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { chainID := chain.ChainId setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) event, err := crosschainkeeper.ParseZetaSentEvent( @@ -538,7 +538,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { chain := chains.Ethereum SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000") @@ -570,7 +570,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { chainID := chain.ChainId setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000") @@ -634,7 +634,7 @@ func TestKeeper_ProcessZetaSentEvent(t *testing.T) { setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) zk.ObserverKeeper.SetChainNonces(ctx, observertypes.ChainNonces{ @@ -699,7 +699,7 @@ func TestKeeper_ProcessLogs(t *testing.T) { chainID := chain.ChainId setSupportedChain(ctx, zk, chainID) SetupStateForProcessLogs(t, ctx, k, zk, sdkk, chain) - admin := keepertest.SetAdminPolices(ctx, zk.AuthorityKeeper) + admin := keepertest.SetAdminPolicies(ctx, zk.AuthorityKeeper) SetupStateForProcessLogsZetaSent(t, ctx, k, zk, sdkk, chain, admin) amount, ok := sdkmath.NewIntFromString("20000000000000000000000")