Skip to content

Commit

Permalink
rename policy address
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Mar 5, 2024
1 parent 4fc7c5e commit a922576
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 125 deletions.
4 changes: 2 additions & 2 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ then
# set admin account
zetacored add-genesis-account zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk 100000000000000000000000000azeta
zetacored add-genesis-account zeta1n0rn6sne54hv7w2uu93fl48ncyqz97d3kty6sh 100000000000000000000000000azeta # Funds the localnet_gov_admin account
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["policy_addresses"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["policy_addresses"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json

Expand Down
6 changes: 3 additions & 3 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53483,13 +53483,13 @@ definitions:
authorityPolicies:
type: object
properties:
policy_addresses:
items:
type: array
items:
type: object
$ref: '#/definitions/authorityPolicyAddress'
$ref: '#/definitions/authorityPolicy'
title: Policy contains info about authority policies
authorityPolicyAddress:
authorityPolicy:
type: object
properties:
policy_type:
Expand Down
4 changes: 2 additions & 2 deletions proto/authority/policies.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ enum PolicyType {
groupAdmin = 1;
}

message PolicyAddress {
message Policy {
PolicyType policy_type = 1;
string address = 2;
}

// Policy contains info about authority policies
message Policies {
repeated PolicyAddress policy_addresses = 1;
repeated Policy items = 1;
}
2 changes: 1 addition & 1 deletion testutil/sample/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"

func Policies() authoritytypes.Policies {
return authoritytypes.Policies{
PolicyAddresses: []*authoritytypes.PolicyAddress{
Items: []*authoritytypes.Policy{
{
Address: AccAddress(),
PolicyType: authoritytypes.PolicyType_groupEmergency,
Expand Down
20 changes: 10 additions & 10 deletions typescript/authority/policies_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export declare enum PolicyType {
}

/**
* @generated from message zetachain.zetacore.authority.PolicyAddress
* @generated from message zetachain.zetacore.authority.Policy
*/
export declare class PolicyAddress extends Message<PolicyAddress> {
export declare class Policy extends Message<Policy> {
/**
* @generated from field: zetachain.zetacore.authority.PolicyType policy_type = 1;
*/
Expand All @@ -37,19 +37,19 @@ export declare class PolicyAddress extends Message<PolicyAddress> {
*/
address: string;

constructor(data?: PartialMessage<PolicyAddress>);
constructor(data?: PartialMessage<Policy>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.authority.PolicyAddress";
static readonly typeName = "zetachain.zetacore.authority.Policy";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): PolicyAddress;
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Policy;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): PolicyAddress;
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Policy;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): PolicyAddress;
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Policy;

static equals(a: PolicyAddress | PlainMessage<PolicyAddress> | undefined, b: PolicyAddress | PlainMessage<PolicyAddress> | undefined): boolean;
static equals(a: Policy | PlainMessage<Policy> | undefined, b: Policy | PlainMessage<Policy> | undefined): boolean;
}

/**
Expand All @@ -59,9 +59,9 @@ export declare class PolicyAddress extends Message<PolicyAddress> {
*/
export declare class Policies extends Message<Policies> {
/**
* @generated from field: repeated zetachain.zetacore.authority.PolicyAddress policy_addresses = 1;
* @generated from field: repeated zetachain.zetacore.authority.Policy items = 1;
*/
policyAddresses: PolicyAddress[];
items: Policy[];

constructor(data?: PartialMessage<Policies>);

Expand Down
2 changes: 1 addition & 1 deletion x/authority/keeper/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (k Keeper) IsAuthorized(ctx sdk.Context, address string, policyType types.P
if !found {
return false

Check warning on line 31 in x/authority/keeper/policies.go

View check run for this annotation

Codecov / codecov/patch

x/authority/keeper/policies.go#L31

Added line #L31 was not covered by tests
}
for _, policy := range policies.PolicyAddresses {
for _, policy := range policies.Items {
if policy.Address == address && policy.PolicyType == policyType {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion x/authority/keeper/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestKeeper_IsAuthorized(t *testing.T) {
require.Equal(t, policies, got)

// Check policy is authorized
for _, policy := range policies.PolicyAddresses {
for _, policy := range policies.Items {
require.True(t, k.IsAuthorized(ctx, policy.Address, policy.PolicyType))
}

Expand Down
8 changes: 1 addition & 7 deletions x/authority/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := types.RegisterClientCtx(clientCtx)
if err != nil {
fmt.Println("RegisterQueryHandlerClient err: %w", err)
}

err = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err != nil {
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
fmt.Println("RegisterQueryHandlerClient err: %w", err)
}
}
Expand Down
14 changes: 0 additions & 14 deletions x/authority/types/client_ctx.go

This file was deleted.

2 changes: 1 addition & 1 deletion x/authority/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestGenesisState_Validate(t *testing.T) {
name: "invalid if policies is invalid",
gs: &types.GenesisState{
Policies: types.Policies{
PolicyAddresses: []*types.PolicyAddress{
Items: []*types.Policy{
{
Address: "invalid",
PolicyType: types.PolicyType_groupEmergency,
Expand Down
2 changes: 1 addition & 1 deletion x/authority/types/message_update_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestMsgUpdatePolicies_ValidateBasic(t *testing.T) {
{
name: "invalid policies",
msg: types.NewMsgUpdatePolicies(sample.AccAddress(), types.Policies{
PolicyAddresses: []*types.PolicyAddress{
Items: []*types.Policy{
{
Address: "invalid",
PolicyType: types.PolicyType_groupEmergency,
Expand Down
4 changes: 2 additions & 2 deletions x/authority/types/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
// DefaultPolicies returns the default value for policies
func DefaultPolicies() Policies {
return Policies{
PolicyAddresses: []*PolicyAddress{
Items: []*Policy{
{
Address: DefaultPolicyAddress,
PolicyType: PolicyType_groupEmergency,
Expand All @@ -32,7 +32,7 @@ func (p Policies) Validate() error {
policyTypeMap := make(map[PolicyType]bool)

// for each policy, check address, policy type, and ensure no duplicate policy types
for _, policy := range p.PolicyAddresses {
for _, policy := range p.Items {
_, err := sdk.AccAddressFromBech32(policy.Address)
if err != nil {
return fmt.Errorf("invalid address: %s", err)
Expand Down
Loading

0 comments on commit a922576

Please sign in to comment.