-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into debug-trace-tx-changes
- Loading branch information
Showing
23 changed files
with
1,462 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
package zetachain.zetacore.authority; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "zetachain/zetacore/authority/policies.proto"; | ||
|
||
option go_package = "github.com/zeta-chain/zetacore/x/authority/types"; | ||
|
||
// Authorization defines the authorization required to access use a message | ||
// which needs special permissions | ||
message Authorization { | ||
// The URL of the message that needs to be authorized | ||
string msg_url = 1; | ||
// The policy that is authorized to access the message | ||
PolicyType authorized_policy = 2; | ||
} | ||
|
||
// AuthorizationList holds the list of authorizations on zetachain | ||
message AuthorizationList { | ||
repeated Authorization authorizations = 1 [ (gogoproto.nullable) = false ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
typescript/zetachain/zetacore/authority/authorization_pb.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" | ||
// @generated from file zetachain/zetacore/authority/authorization.proto (package zetachain.zetacore.authority, syntax proto3) | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
|
||
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; | ||
import { Message, proto3 } from "@bufbuild/protobuf"; | ||
import type { PolicyType } from "./policies_pb.js"; | ||
|
||
/** | ||
* Authorization defines the authorization required to access use a message | ||
* which needs special permissions | ||
* | ||
* @generated from message zetachain.zetacore.authority.Authorization | ||
*/ | ||
export declare class Authorization extends Message<Authorization> { | ||
/** | ||
* The URL of the message that needs to be authorized | ||
* | ||
* @generated from field: string msg_url = 1; | ||
*/ | ||
msgUrl: string; | ||
|
||
/** | ||
* The policy that is authorized to access the message | ||
* | ||
* @generated from field: zetachain.zetacore.authority.PolicyType authorized_policy = 2; | ||
*/ | ||
authorizedPolicy: PolicyType; | ||
|
||
constructor(data?: PartialMessage<Authorization>); | ||
|
||
static readonly runtime: typeof proto3; | ||
static readonly typeName = "zetachain.zetacore.authority.Authorization"; | ||
static readonly fields: FieldList; | ||
|
||
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Authorization; | ||
|
||
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): Authorization; | ||
|
||
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): Authorization; | ||
|
||
static equals(a: Authorization | PlainMessage<Authorization> | undefined, b: Authorization | PlainMessage<Authorization> | undefined): boolean; | ||
} | ||
|
||
/** | ||
* AuthorizationList holds the list of authorizations on zetachain | ||
* | ||
* @generated from message zetachain.zetacore.authority.AuthorizationList | ||
*/ | ||
export declare class AuthorizationList extends Message<AuthorizationList> { | ||
/** | ||
* @generated from field: repeated zetachain.zetacore.authority.Authorization authorizations = 1; | ||
*/ | ||
authorizations: Authorization[]; | ||
|
||
constructor(data?: PartialMessage<AuthorizationList>); | ||
|
||
static readonly runtime: typeof proto3; | ||
static readonly typeName = "zetachain.zetacore.authority.AuthorizationList"; | ||
static readonly fields: FieldList; | ||
|
||
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): AuthorizationList; | ||
|
||
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): AuthorizationList; | ||
|
||
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): AuthorizationList; | ||
|
||
static equals(a: AuthorizationList | PlainMessage<AuthorizationList> | undefined, b: AuthorizationList | PlainMessage<AuthorizationList> | undefined): boolean; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/zeta-chain/zetacore/x/authority/types" | ||
) | ||
|
||
// SetAuthorizationList sets the authorization list to the store.It returns an error if the list is invalid. | ||
func (k Keeper) SetAuthorizationList(ctx sdk.Context, list types.AuthorizationList) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AuthorizationListKey)) | ||
b := k.cdc.MustMarshal(&list) | ||
store.Set([]byte{0}, b) | ||
} | ||
|
||
// GetAuthorizationList returns the authorization list from the store | ||
func (k Keeper) GetAuthorizationList(ctx sdk.Context) (val types.AuthorizationList, found bool) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AuthorizationListKey)) | ||
b := store.Get([]byte{0}) | ||
if b == nil { | ||
return val, false | ||
} | ||
k.cdc.MustUnmarshal(b, &val) | ||
return val, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"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/types" | ||
) | ||
|
||
func TestKeeper_GetAuthorizationList(t *testing.T) { | ||
t.Run("successfully get authorizations list", func(t *testing.T) { | ||
k, ctx := keepertest.AuthorityKeeper(t) | ||
authorizationList := sample.AuthorizationList("sample") | ||
k.SetAuthorizationList(ctx, authorizationList) | ||
list, found := k.GetAuthorizationList(ctx) | ||
require.True(t, found) | ||
require.Equal(t, authorizationList, list) | ||
}) | ||
|
||
t.Run("get authorizations list not found", func(t *testing.T) { | ||
k, ctx := keepertest.AuthorityKeeper(t) | ||
list, found := k.GetAuthorizationList(ctx) | ||
require.False(t, found) | ||
require.Equal(t, types.AuthorizationList{}, list) | ||
}) | ||
} | ||
|
||
func TestKeeper_SetAuthorizationList(t *testing.T) { | ||
t.Run("successfully set authorizations list when a list already exists", func(t *testing.T) { | ||
k, ctx := keepertest.AuthorityKeeper(t) | ||
authorizationList := sample.AuthorizationList("sample") | ||
k.SetAuthorizationList(ctx, authorizationList) | ||
|
||
list, found := k.GetAuthorizationList(ctx) | ||
require.True(t, found) | ||
require.Equal(t, authorizationList, list) | ||
|
||
newAuthorizationList := sample.AuthorizationList("sample2") | ||
require.NotEqual(t, authorizationList, newAuthorizationList) | ||
k.SetAuthorizationList(ctx, newAuthorizationList) | ||
|
||
list, found = k.GetAuthorizationList(ctx) | ||
require.True(t, found) | ||
require.Equal(t, newAuthorizationList, list) | ||
}) | ||
} |
Oops, something went wrong.