Skip to content

Commit

Permalink
style: rename to allow list
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Mar 26, 2024
1 parent 17531fa commit b86b3a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (k Keeper) GetAppMetadata(ctx sdk.Context, portID, channelID string) (icaty
return k.getAppMetadata(ctx, portID, channelID)
}

// NewModuleQuerySafeWhitelist is a wrapper around newModuleQuerySafeWhitelist to allow the function to be directly called in tests.
func NewModuleQuerySafeWhitelist() []string {
return newModuleQuerySafeWhitelist()
// NewModuleQuerySafeAllowList is a wrapper around newModuleQuerySafeAllowList to allow the function to be directly called in tests.
func NewModuleQuerySafeAllowList() []string {
return newModuleQuerySafeAllowList()
}
16 changes: 8 additions & 8 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type Keeper struct {
msgRouter icatypes.MessageRouter
queryRouter icatypes.QueryRouter

// whitelist of module safe queries
mqsWhitelist []string
// mqsAllowList is a list of all module safe query paths
mqsAllowList []string

// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
Expand Down Expand Up @@ -80,7 +80,7 @@ func NewKeeper(
scopedKeeper: scopedKeeper,
msgRouter: msgRouter,
queryRouter: queryRouter,
mqsWhitelist: newModuleQuerySafeWhitelist(),
mqsAllowList: newModuleQuerySafeAllowList(),
authority: authority,
}
}
Expand Down Expand Up @@ -274,14 +274,14 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
store.Set([]byte(types.ParamsKey), bz)
}

// newModuleQuerySafeWhitelist returns a list of all query paths labeled with module_query_safe in the proto files.
func newModuleQuerySafeWhitelist() []string {
// newModuleQuerySafeAllowList returns a list of all query paths labeled with module_query_safe in the proto files.
func newModuleQuerySafeAllowList() []string {
protoFiles, err := gogoproto.MergedRegistry()
if err != nil {
panic(err)
}

whitelist := []string{}
allowList := []string{}
protoFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool {
for i := 0; i < fd.Services().Len(); i++ {
// Get the service descriptor
Expand All @@ -302,11 +302,11 @@ func newModuleQuerySafeWhitelist() []string {
}

// Add the method to the whitelist
whitelist = append(whitelist, fmt.Sprintf("/%s/%s", sd.FullName(), md.Name()))
allowList = append(allowList, fmt.Sprintf("/%s/%s", sd.FullName(), md.Name()))
}
}
return true
})

return whitelist
return allowList
}
34 changes: 17 additions & 17 deletions modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,29 +201,29 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
}
}

func (suite *KeeperTestSuite) TestNewModuleQuerySafeWhitelist() {
func (suite *KeeperTestSuite) TestNewModuleQuerySafeAllowList() {
// Currently, all queries in bank, staking, auth, and circuit are marked safe
// Notably, the gov and distribution modules are not marked safe

var whitelist []string
var allowList []string
suite.Require().NotPanics(func() {
whitelist = keeper.NewModuleQuerySafeWhitelist()
allowList = keeper.NewModuleQuerySafeAllowList()
})

suite.Require().NotEmpty(whitelist)
suite.Require().Contains(whitelist, "/cosmos.bank.v1beta1.Query/Balance")
suite.Require().Contains(whitelist, "/cosmos.bank.v1beta1.Query/AllBalances")
suite.Require().Contains(whitelist, "/cosmos.staking.v1beta1.Query/Validator")
suite.Require().Contains(whitelist, "/cosmos.staking.v1beta1.Query/Validators")
suite.Require().Contains(whitelist, "/cosmos.circuit.v1.Query/Account")
suite.Require().Contains(whitelist, "/cosmos.circuit.v1.Query/DisabledList")
suite.Require().Contains(whitelist, "/cosmos.auth.v1beta1.Query/Accounts")
suite.Require().Contains(whitelist, "/cosmos.auth.v1beta1.Query/ModuleAccountByName")
suite.Require().Contains(whitelist, "/ibc.core.client.v1.Query/VerifyMembership")
suite.Require().NotContains(whitelist, "/cosmos.gov.v1beta1.Query/Proposals")
suite.Require().NotContains(whitelist, "/cosmos.gov.v1.Query/Proposals")
suite.Require().NotContains(whitelist, "/cosmos.distribution.v1beta1.Query/Params")
suite.Require().NotContains(whitelist, "/cosmos.distribution.v1beta1.Query/DelegationRewards")
suite.Require().NotEmpty(allowList)
suite.Require().Contains(allowList, "/cosmos.bank.v1beta1.Query/Balance")
suite.Require().Contains(allowList, "/cosmos.bank.v1beta1.Query/AllBalances")
suite.Require().Contains(allowList, "/cosmos.staking.v1beta1.Query/Validator")
suite.Require().Contains(allowList, "/cosmos.staking.v1beta1.Query/Validators")
suite.Require().Contains(allowList, "/cosmos.circuit.v1.Query/Account")
suite.Require().Contains(allowList, "/cosmos.circuit.v1.Query/DisabledList")
suite.Require().Contains(allowList, "/cosmos.auth.v1beta1.Query/Accounts")
suite.Require().Contains(allowList, "/cosmos.auth.v1beta1.Query/ModuleAccountByName")
suite.Require().Contains(allowList, "/ibc.core.client.v1.Query/VerifyMembership")
suite.Require().NotContains(allowList, "/cosmos.gov.v1beta1.Query/Proposals")
suite.Require().NotContains(allowList, "/cosmos.gov.v1.Query/Proposals")
suite.Require().NotContains(allowList, "/cosmos.distribution.v1beta1.Query/Params")
suite.Require().NotContains(allowList, "/cosmos.distribution.v1beta1.Query/DelegationRewards")
}

func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (m msgServer) ModuleQuerySafe(goCtx context.Context, msg *types.MsgModuleQu

responses := make([][]byte, len(msg.Requests))
for i, query := range msg.Requests {
isModuleQuerySafe := slices.Contains(m.mqsWhitelist, query.Path)
isModuleQuerySafe := slices.Contains(m.mqsAllowList, query.Path)
if !isModuleQuerySafe {
return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "not module query safe: %s", query.Path)
}
Expand Down

0 comments on commit b86b3a4

Please sign in to comment.