Skip to content

Commit

Permalink
Improved profiles params structure
Browse files Browse the repository at this point in the history
See PR #546
  • Loading branch information
leobragaz authored Jul 12, 2021
1 parent fba1f05 commit 5378bac
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 1,136 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Improved pagination ([#544](https://github.com/desmos-labs/desmos/pull/544))
- Renamed `PollData` and `PollAnswer` to `Poll` and `ProvidedAnswer` ([#536]((https://github.com/desmos-labs/desmos/issues/536)))
- Enabled snapshot by default ([#529](https://github.com/desmos-labs/desmos/pull/529))
- Improved `x/profiles` params structure [#538](https://github.com/desmos-labs/desmos/issues/538)

## Version 0.17.0
### Changes
Expand Down
3 changes: 2 additions & 1 deletion proto/desmos/posts/v1beta1/polls.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import "google/protobuf/timestamp.proto";

option go_package = "github.com/desmos-labs/desmos/x/staging/posts/types";

// ProvidedAnswer contains the data of a single poll answer inserted by the creator
// ProvidedAnswer contains the data of a single poll answer inserted by the
// creator
message ProvidedAnswer {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;
Expand Down
48 changes: 28 additions & 20 deletions proto/desmos/profiles/v1beta1/models_params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,35 @@ option go_package = "github.com/desmos-labs/desmos/x/profiles/types";
message Params {
option (gogoproto.goproto_getters) = false;

NicknameParams nickname_params = 1 [
NicknameParams nickname = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"nickname_params\""
(gogoproto.moretags) = "yaml:\"nickname\""
];

DTagParams dtag_params = 2 [
DTagParams dtag = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"dtag_params\"",
(gogoproto.customname) = "DTagParams"
(gogoproto.moretags) = "yaml:\"dtag\"",
(gogoproto.customname) = "DTag"
];

bytes max_bio_length = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max_bio_length\""
];
BioParams bio = 3
[ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"bio\"" ];
}

// NicknameParams defines the parameters related to the profiles nicknames
message NicknameParams {
option (gogoproto.goproto_getters) = false;

bytes min_nickname_length = 1 [
bytes min_length = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_nickname_length\""
(gogoproto.moretags) = "yaml:\"min_length\""
];

bytes max_nickname_length = 2 [
bytes max_length = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max_nickname_length\""
(gogoproto.moretags) = "yaml:\"max_length\""
];
}

Expand All @@ -50,17 +47,28 @@ message DTagParams {

string reg_ex = 1 [ (gogoproto.moretags) = "yaml:\"reg_ex\"" ];

bytes min_dtag_length = 2 [
bytes min_length = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_length\"",
(gogoproto.customname) = "MinLength"
];

bytes max_length = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_dtag_length\"",
(gogoproto.customname) = "MinDTagLength"
(gogoproto.moretags) = "yaml:\"max_length\"",
(gogoproto.customname) = "MaxLength"
];
}

// BioParams defines the parameters related to profile biography
message BioParams {
option (gogoproto.goproto_getters) = false;

bytes max_dtag_length = 3 [
bytes max_length = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max_dtag_length\"",
(gogoproto.customname) = "MaxDTagLength"
(gogoproto.moretags) = "yaml:\"max_length\""
];
}
12 changes: 6 additions & 6 deletions proto/desmos/profiles/v1beta1/msgs_dtag_requests.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ message MsgCancelDTagTransferRequest {
string sender = 2 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
}

// MsgCancelDTagTransferRequestResponse represents the Msg/CancelDTagTransferRequest
// response type.
// MsgCancelDTagTransferRequestResponse represents the
// Msg/CancelDTagTransferRequest response type.
message MsgCancelDTagTransferRequestResponse {}

// ___________________________________________________________________________________________________________________
Expand All @@ -71,8 +71,8 @@ message MsgAcceptDTagTransferRequest {
string receiver = 3 [ (gogoproto.moretags) = "yaml:\"receiver\"" ];
}

// MsgAcceptDTagTransferRequestResponse defines the Msg/AcceptDTagTransferRequest
// response.
// MsgAcceptDTagTransferRequestResponse defines the
// Msg/AcceptDTagTransferRequest response.
message MsgAcceptDTagTransferRequestResponse {}

// ___________________________________________________________________________________________________________________
Expand All @@ -90,6 +90,6 @@ message MsgRefuseDTagTransferRequest {
string receiver = 2 [ (gogoproto.moretags) = "yaml:\"receiver\"" ];
}

// MsgRefuseDTagTransferRequestResponse defines the Msg/RefuseDTagTransferRequest
// response.
// MsgRefuseDTagTransferRequestResponse defines the
// Msg/RefuseDTagTransferRequest response.
message MsgRefuseDTagTransferRequestResponse {}
8 changes: 4 additions & 4 deletions x/profiles/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) Test_ExportGenesis() {
params := types.NewParams(
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
types.NewBioParams(sdk.NewInt(1000)),
)
suite.k.SetParams(ctx, params)
suite.k.SetPort(ctx, "port-id")
Expand Down Expand Up @@ -168,7 +168,7 @@ func (suite *KeeperTestSuite) Test_ExportGenesis() {
types.NewParams(
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
types.NewBioParams(sdk.NewInt(1000)),
),
"port-id",
[]types.ChainLink{
Expand Down Expand Up @@ -360,7 +360,7 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {
types.NewParams(
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
types.NewBioParams(sdk.NewInt(1000)),
),
"profiles-port-id",
[]types.ChainLink{
Expand Down Expand Up @@ -432,7 +432,7 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {
params := types.NewParams(
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
types.NewBioParams(sdk.NewInt(1000)),
)
suite.Require().Equal(params, suite.k.GetParams(ctx))

Expand Down
12 changes: 6 additions & 6 deletions x/profiles/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func (k Keeper) RemoveProfile(ctx sdk.Context, address string) error {
func (k Keeper) ValidateProfile(ctx sdk.Context, profile *types.Profile) error {
params := k.GetParams(ctx)

minNicknameLen := params.NicknameParams.MinNicknameLength.Int64()
maxNicknameLen := params.NicknameParams.MaxNicknameLength.Int64()
minNicknameLen := params.Nickname.MinLength.Int64()
maxNicknameLen := params.Nickname.MaxLength.Int64()

if profile.Nickname != "" {
nameLen := int64(len(profile.Nickname))
Expand All @@ -181,9 +181,9 @@ func (k Keeper) ValidateProfile(ctx sdk.Context, profile *types.Profile) error {
}
}

dTagRegEx := regexp.MustCompile(params.DTagParams.RegEx)
minDTagLen := params.DTagParams.MinDTagLength.Int64()
maxDTagLen := params.DTagParams.MaxDTagLength.Int64()
dTagRegEx := regexp.MustCompile(params.DTag.RegEx)
minDTagLen := params.DTag.MinLength.Int64()
maxDTagLen := params.DTag.MaxLength.Int64()
dTagLen := int64(len(profile.DTag))

if !dTagRegEx.MatchString(profile.DTag) {
Expand All @@ -198,7 +198,7 @@ func (k Keeper) ValidateProfile(ctx sdk.Context, profile *types.Profile) error {
return fmt.Errorf("profile dtag cannot exceed %d characters", maxDTagLen)
}

maxBioLen := params.MaxBioLength.Int64()
maxBioLen := params.Bio.MaxLength.Int64()
if profile.Bio != "" && int64(len(profile.Bio)) > maxBioLen {
return fmt.Errorf("profile biography cannot exceed %d characters", maxBioLen)
}
Expand Down
6 changes: 3 additions & 3 deletions x/profiles/keeper/keeper_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func (suite *KeeperTestSuite) TestKeeper_SetParams() {
params := types.NewParams(
types.NewNicknameParams(sdk.NewInt(3), sdk.NewInt(1000)),
types.NewDTagParams("^[A-Za-z0-9_]+$", sdk.NewInt(3), sdk.NewInt(1000)),
sdk.NewInt(1000),
types.NewBioParams(sdk.NewInt(1000)),
)
suite.k.SetParams(suite.ctx, params)

Expand All @@ -31,15 +31,15 @@ func (suite *KeeperTestSuite) TestKeeper_GetParams() {
params := types.NewParams(
types.NewNicknameParams(sdk.NewInt(3), sdk.NewInt(1000)),
types.NewDTagParams("^[A-Za-z0-9_]+$", sdk.NewInt(3), sdk.NewInt(1000)),
sdk.NewInt(1000),
types.NewBioParams(sdk.NewInt(1000)),
)
suite.k.SetParams(ctx, params)
},
shouldErr: false,
expParams: types.NewParams(
types.NewNicknameParams(sdk.NewInt(3), sdk.NewInt(1000)),
types.NewDTagParams("^[A-Za-z0-9_]+$", sdk.NewInt(3), sdk.NewInt(1000)),
sdk.NewInt(1000),
types.NewBioParams(sdk.NewInt(1000)),
),
},
{
Expand Down
10 changes: 0 additions & 10 deletions x/profiles/legacy/v0160/params.go

This file was deleted.

Loading

0 comments on commit 5378bac

Please sign in to comment.