diff --git a/codec/types/interface_registry.go b/codec/types/interface_registry.go index 0f9eb760be..fe3fbd0ff6 100644 --- a/codec/types/interface_registry.go +++ b/codec/types/interface_registry.go @@ -10,11 +10,11 @@ import ( ) // AnyUnpacker is an interface which allows safely unpacking types packed -// in Any's against a whitelist of registered types +// in Any's against a allowlist of registered types type AnyUnpacker interface { // UnpackAny unpacks the value in any to the interface pointer passed in as // iface. Note that the type in any must have been registered in the - // underlying whitelist registry as a concrete type for that interface + // underlying allowlist registry as a concrete type for that interface // Ex: // var msg sdk.Msg // err := cdc.UnpackAny(any, &msg) @@ -67,7 +67,7 @@ type InterfaceRegistry interface { // UnpackInterfacesMessage is meant to extend protobuf types (which implement // proto.Message) to support a post-deserialization phase which unpacks -// types packed within Any's using the whitelist provided by AnyUnpacker +// types packed within Any's using the allowlist provided by AnyUnpacker type UnpackInterfacesMessage interface { // UnpackInterfaces is implemented in order to unpack values packed within // Any's using the AnyUnpacker. It should generally be implemented as diff --git a/x/airdrop/abci.go b/x/airdrop/abci.go index b9d44560f0..1be75851f3 100644 --- a/x/airdrop/abci.go +++ b/x/airdrop/abci.go @@ -1,11 +1,12 @@ package airdrop import ( + "time" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/airdrop/keeper" "github.com/cosmos/cosmos-sdk/x/airdrop/types" - "time" ) func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { diff --git a/x/airdrop/client/cli/query.go b/x/airdrop/client/cli/query.go index ea0eec4fb0..c41dd14577 100644 --- a/x/airdrop/client/cli/query.go +++ b/x/airdrop/client/cli/query.go @@ -2,12 +2,13 @@ package cli import ( "fmt" + "strings" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/airdrop/types" "github.com/spf13/cobra" - "strings" ) func GetQueryCmd() *cobra.Command { diff --git a/x/airdrop/client/cli/tx.go b/x/airdrop/client/cli/tx.go index 1dec797153..82d5fc41ab 100644 --- a/x/airdrop/client/cli/tx.go +++ b/x/airdrop/client/cli/tx.go @@ -2,6 +2,8 @@ package cli import ( "fmt" + "strings" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -10,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/airdrop/types" "github.com/spf13/cobra" - "strings" ) func GetTxCmd() *cobra.Command { diff --git a/x/airdrop/keeper/grpc_query.go b/x/airdrop/keeper/grpc_query.go index aea5437db8..63f1855935 100644 --- a/x/airdrop/keeper/grpc_query.go +++ b/x/airdrop/keeper/grpc_query.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" diff --git a/x/airdrop/keeper/grpc_query_test.go b/x/airdrop/keeper/grpc_query_test.go index 9aa3e6dbce..8c7014d59b 100644 --- a/x/airdrop/keeper/grpc_query_test.go +++ b/x/airdrop/keeper/grpc_query_test.go @@ -3,6 +3,8 @@ package keeper_test import ( gocontext "context" "fmt" + "testing" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -10,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/airdrop/types" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "testing" ) var ( diff --git a/x/airdrop/keeper/keeper.go b/x/airdrop/keeper/keeper.go index 557df45ff8..2393ef461a 100644 --- a/x/airdrop/keeper/keeper.go +++ b/x/airdrop/keeper/keeper.go @@ -48,7 +48,7 @@ func (k Keeper) AddFund(ctx sdk.Context, sender sdk.AccAddress, fund types.Fund) if !params.IsAllowedSender(sender) { return sdkerrors.Wrapf( sdkerrors.ErrConflict, - "Non-whitelist sender %s", sender.String(), + "Non-allowlist sender %s", sender.String(), ) } diff --git a/x/airdrop/keeper/keeper_test.go b/x/airdrop/keeper/keeper_test.go index 37e9f51a5c..08c9b82f5a 100644 --- a/x/airdrop/keeper/keeper_test.go +++ b/x/airdrop/keeper/keeper_test.go @@ -1,11 +1,12 @@ package keeper_test import ( - "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/x/airdrop/types" "testing" "time" + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/airdrop/types" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/suite" diff --git a/x/airdrop/keeper/msg_server.go b/x/airdrop/keeper/msg_server.go index 3660e1a453..a30cba8966 100644 --- a/x/airdrop/keeper/msg_server.go +++ b/x/airdrop/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/airdrop/types" ) diff --git a/x/airdrop/keeper/params.go b/x/airdrop/keeper/params.go index 0ccf156afd..2d32c69d5d 100644 --- a/x/airdrop/keeper/params.go +++ b/x/airdrop/keeper/params.go @@ -5,15 +5,15 @@ import ( "github.com/cosmos/cosmos-sdk/x/airdrop/types" ) -func (k Keeper) GetWhiteListClients(ctx sdk.Context) []string { +func (k Keeper) GetAllowListClients(ctx sdk.Context) []string { var res []string - k.paramSpace.GetIfExists(ctx, types.KeyWhiteList, &res) + k.paramSpace.Get(ctx, types.KeyAllowList, &res) return res } // GetParams returns the total set of ibc-transfer parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams(k.GetWhiteListClients(ctx)...) + return types.NewParams(k.GetAllowListClients(ctx)...) } // SetParams sets the total set of ibc-transfer parameters. diff --git a/x/airdrop/module.go b/x/airdrop/module.go index 5b5ec2e87b..2fc0314c9d 100644 --- a/x/airdrop/module.go +++ b/x/airdrop/module.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/x/airdrop/types/airdrop.pb.go b/x/airdrop/types/airdrop.pb.go index d92faf136e..fcc8c4c5c8 100644 --- a/x/airdrop/types/airdrop.pb.go +++ b/x/airdrop/types/airdrop.pb.go @@ -5,14 +5,15 @@ package types import ( fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" _ "github.com/regen-network/cosmos-proto" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/airdrop/types/genesis.go b/x/airdrop/types/genesis.go index 8ffe5c4596..7cdcd83a0e 100644 --- a/x/airdrop/types/genesis.go +++ b/x/airdrop/types/genesis.go @@ -1,8 +1,9 @@ package types import ( - sdk "github.com/cosmos/cosmos-sdk/types" "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" ) func DefaultGenesisState() *GenesisState { @@ -14,14 +15,11 @@ func NewGenesisState(params Params, funds []ActiveFund) *GenesisState { } func (gs *GenesisState) Validate() error { - whiteListAddresses := []sdk.AccAddress{} - for _, address := range gs.Params.AllowList { - accAddress, err := sdk.AccAddressFromBech32(strings.TrimSpace(address)) + _, err := sdk.AccAddressFromBech32(strings.TrimSpace(address)) if err != nil { return err } - whiteListAddresses = append(whiteListAddresses, accAddress) } return nil diff --git a/x/airdrop/types/genesis.pb.go b/x/airdrop/types/genesis.pb.go index c390336d28..14f9227735 100644 --- a/x/airdrop/types/genesis.pb.go +++ b/x/airdrop/types/genesis.pb.go @@ -5,11 +5,12 @@ package types import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/airdrop/types/params.go b/x/airdrop/types/params.go index 51eb62de3a..4946a5eeb0 100644 --- a/x/airdrop/types/params.go +++ b/x/airdrop/types/params.go @@ -2,19 +2,20 @@ package types import ( "fmt" + "strings" + sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "strings" ) var ( - // KeyWhiteList is store's key for WhiteList Params - KeyWhiteList = []byte("AllowList") + // KeyAllowList is store's key for AllowList Params + KeyAllowList = []byte("AllowList") ) -func NewParams(whiteListClients ...string) Params { +func NewParams(allowListClients ...string) Params { return Params{ - AllowList: whiteListClients, + AllowList: allowListClients, } } @@ -24,11 +25,11 @@ func ParamKeyTable() paramtypes.KeyTable { func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyWhiteList, &p.AllowList, validateWhiteList), + paramtypes.NewParamSetPair(KeyAllowList, &p.AllowList, validateAllowList), } } -func validateWhiteList(i interface{}) error { +func validateAllowList(i interface{}) error { clients, ok := i.([]string) if !ok { return fmt.Errorf("invalid parameter type: %T", i) diff --git a/x/airdrop/types/params_test.go b/x/airdrop/types/params_test.go new file mode 100644 index 0000000000..e990b9636e --- /dev/null +++ b/x/airdrop/types/params_test.go @@ -0,0 +1,55 @@ +package types_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/airdrop/types" + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/tendermint/tendermint/types/time" +) + +var ( + allowedAddress = sdk.AccAddress([]byte("allowed_____________")) + blockedAddress1 = sdk.AccAddress([]byte("blocked_____________")) + blockedAddress2 = sdk.AccAddress([]byte("")) +) + +type ParamsTestSuite struct { + suite.Suite + app *simapp.SimApp + ctx sdk.Context +} + +func (s *ParamsTestSuite) SetupTest() { + app := simapp.Setup(false) + s.app = app + s.ctx = app.BaseApp.NewContext(false, tmproto.Header{ + Time: time.Now(), + Height: 10, + }) +} + +func (s *ParamsTestSuite) TestIsAllowedSender() { + correct := types.NewParams(allowedAddress.String()) // New set of parameters with a new AllowList + s.Require().True(correct.IsAllowedSender(allowedAddress)) // Address is in AllowList and has correct format + s.Require().False(correct.IsAllowedSender(blockedAddress1)) // Address is not in AllowList and has correct format + s.Require().False(correct.IsAllowedSender(blockedAddress2)) // Address is not in AllowList and has incorrect format +} + +func (s *ParamsTestSuite) TestValidateAllowList() { + correct := types.NewParams(allowedAddress.String()) // Allow list contains address with correct format + incorrect := types.NewParams(allowedAddress.String(), blockedAddress2.String()) // Allow list contains address with incorrect format + for _, paramPairs := range correct.ParamSetPairs() { + s.Require().NoError(paramPairs.ValidatorFn(correct.AllowList)) + } + for _, paramPairs := range incorrect.ParamSetPairs() { + s.Require().Error(paramPairs.ValidatorFn(incorrect.AllowList)) + } +} + +func TestParamsTestSuite(t *testing.T) { + suite.Run(t, new(ParamsTestSuite)) +} diff --git a/x/airdrop/types/query.pb.go b/x/airdrop/types/query.pb.go index 782aabf26c..9df8650bd1 100644 --- a/x/airdrop/types/query.pb.go +++ b/x/airdrop/types/query.pb.go @@ -6,6 +6,10 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + query "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" @@ -14,9 +18,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/airdrop/types/tx.pb.go b/x/airdrop/types/tx.pb.go index 748f1dbc5a..b4c18b2a0b 100644 --- a/x/airdrop/types/tx.pb.go +++ b/x/airdrop/types/tx.pb.go @@ -6,15 +6,16 @@ package types import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used.