Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiles fixes #415

Merged
merged 10 commits into from
May 10, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Bug fixes
- Fixed failing transactions performed by a `Profile` continuously depleting
funds ([\#416](https://github.com/desmos-labs/desmos/issues/416))
- Renamed `profile` `moniker` field into `nickname` to fix a `--moniker` flag bug ([#413](https://github.com/desmos-labs/desmos/issues/413))

# Version 0.16.1
## Changes
Expand Down
6 changes: 3 additions & 3 deletions docs/developers/msgs/profiles/save-profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This message allows you to save a new profile or edit an existent one.
{
"@type": "/desmos.profiles.v1beta1.MsgSaveProfile",
"dtag": "<Profile dtag>",
"moniker": "<Profile moniker>",
"nickname": "<Profile nickname>",
"bio": "<Profile biography>",
"profile_picture": "<URI of the profile account's picture>",
"cover_picture": "<URI of the profile cover picture>",
Expand All @@ -18,7 +18,7 @@ This message allows you to save a new profile or edit an existent one.
| Attribute | Type | Description |
| :-------: | :----: | :-------- |
| `dtag` | String | DTag of the user |
| `moniker` | String (Optional) | Moniker of the user |
| `nickname` | String (Optional) | Nickname of the user |
| `bio` | String | (Optional) Biography of the user |
| `profile_picture` | String | (Optional) URL to the user profile picture |
| `cover_picture` | String | (Optional) URL to the user cover picture |
Expand All @@ -33,7 +33,7 @@ value `[do-not-modify]`.
{
"@type": "/desmos.profiles.v1beta1.MsgSaveProfile",
"dtag": "Eva00",
"moniker": "Rei Ayanami",
"nickname": "Rei Ayanami",
"bio": "The real pilot",
"profile_picture": "[do-not-modify]",
"cover_picture": "https://shorturl.at/cgpyF",
Expand Down
8 changes: 4 additions & 4 deletions docs/developers/msgs/staging/edit_param_proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ proposal through the `gov` module of the Cosmos SDK.
"content": {
"@type": "/cosmos.params.v1beta1.ParameterChangeProposal",
"value": {
"title": "Moniker Param Change",
"description": "Update moniker lengths",
"title": "Nickname Param Change",
"description": "Update nickname lengths",
"changes": [
{
"subspace": "profiles",
"key": "monikerParams",
"value": "{\"type\": \"desmos/MonikerParams\",\"value\": {\"min_moniker_len\":\"5\",\"max_moniker_len\":\"40\"}}"
"key": "nicknameParams",
"value": "{\"type\": \"desmos/NicknameParams\",\"value\": {\"min_nickname_len\":\"5\",\"max_nickname_len\":\"40\"}}"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions docs/developers/types/profiles/profile.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Profile
Inside Desmos, profile are the way that users could register their own identity.

Since this is a decentralized profile, every data inside it can be omitted except for the `moniker` which could be used
Since this is a decentralized profile, every data inside it can be omitted except for the `dTag` which could be used
to identify a desmos `bech32addr` once the profile is created.

Profile can be enriched with some of your personal data.
Expand All @@ -18,8 +18,8 @@ In order to be valid it needs to match the following RegEx:
[A-Za-z0-9_]{2,30}
```

### `Moniker`
The `Moniker` represents the name of the user. It can be either a combination of first, second and last name, or a completely invented name. Although we always suggest setting one, this field is completely optional.
### `Nickname`
The `Nickname` represents the name of the user. It can be either a combination of first, second and last name, or a completely invented name. Although we always suggest setting one, this field is completely optional.

### `Bio`
The `Bio` represents the biography of the user. It can be at most `1000` characters long.
Expand Down
2 changes: 1 addition & 1 deletion proto/desmos/profiles/v1beta1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ message Profile {
(gogoproto.moretags) = "yaml:\"dtag\"",
(gogoproto.customname) = "DTag"
];
string moniker = 3 [(gogoproto.moretags) = "yaml:\"moniker\""];
string nickname = 3 [(gogoproto.moretags) = "yaml:\"nickname\""];
string bio = 4 [(gogoproto.moretags) = "yaml:\"bio\""];
Pictures pictures = 5 [
(gogoproto.nullable) = false,
Expand Down
2 changes: 1 addition & 1 deletion proto/desmos/profiles/v1beta1/msgs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ message MsgSaveProfile {
(gogoproto.customname) = "DTag"
];

string moniker = 2 [(gogoproto.moretags) = "yaml:\"moniker\""];
string nickname = 2 [(gogoproto.moretags) = "yaml:\"nickname\""];

string bio = 3 [(gogoproto.moretags) = "yaml:\"bio\""];

Expand Down
16 changes: 8 additions & 8 deletions proto/desmos/profiles/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ option go_package = "github.com/desmos-labs/desmos/x/profiles/types";

// Params contains the parameters for the profiles module
message Params {
MonikerParams moniker_params = 1 [
NicknameParams nickname_params = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"moniker_params\""
(gogoproto.moretags) = "yaml:\"nickname_params\""
];

DTagParams dtag_params = 2 [
Expand All @@ -25,18 +25,18 @@ message Params {
];
}

// MonikerParams defines the parameters related to the profiles monikers
message MonikerParams {
bytes min_moniker_length = 1 [
// NicknameParams defines the parameters related to the profiles nicknames
message NicknameParams {
bytes min_nickname_length = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"min_moniker_length\""
(gogoproto.moretags) = "yaml:\"min_nickname_length\""
];

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

Expand Down
4 changes: 2 additions & 2 deletions x/profiles/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *IntegrationTestSuite) SetupSuite() {

account, err := types.NewProfile(
"dtag",
"moniker",
"nickname",
"bio",
types.Pictures{},
time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *IntegrationTestSuite) TestCmdQueryProfile() {

profile, err := types.NewProfile(
"dtag",
"moniker",
"nickname",
"bio",
types.Pictures{},
time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/client/cli/keys.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cli

const (
FlagMoniker = "moniker"
FlagNickname = "nickname"
FlagBio = "bio"
FlagProfilePic = "profile-pic"
FlagCoverPic = "cover-pic"
Expand Down
10 changes: 5 additions & 5 deletions x/profiles/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetCmdSaveProfile() *cobra.Command {
Args: cobra.ExactArgs(1),
Short: "Save your profile associating to it the given DTag.",
Long: fmt.Sprintf(`
Save a new profile or edit the existing one specifying a DTag, a moniker, biography, profile picture and cover picture.
Save a new profile or edit the existing one specifying a DTag, a nickname, biography, profile picture and cover picture.
Every data given through the flags is optional.
If you are editing an existing profile you should fill only the fields that you want to edit.
The empty ones will be filled with a special [do-not-modify] flag that tells the system to not edit them.
Expand All @@ -58,20 +58,20 @@ The empty ones will be filled with a special [do-not-modify] flag that tells the
%s "Hollywood actor. Proud environmentalist" \
%s "https://profilePic.jpg"
%s "https://profileCover.jpg"
`, version.AppName, FlagMoniker, FlagBio, FlagProfilePic, FlagCoverPic),
`, version.AppName, FlagNickname, FlagBio, FlagProfilePic, FlagCoverPic),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

dTag := args[0]
moniker, _ := cmd.Flags().GetString(FlagMoniker)
nickname, _ := cmd.Flags().GetString(FlagNickname)
bio, _ := cmd.Flags().GetString(FlagBio)
profilePic, _ := cmd.Flags().GetString(FlagProfilePic)
coverPic, _ := cmd.Flags().GetString(FlagCoverPic)

msg := types.NewMsgSaveProfile(dTag, moniker, bio, profilePic, coverPic, clientCtx.FromAddress.String())
msg := types.NewMsgSaveProfile(dTag, nickname, bio, profilePic, coverPic, clientCtx.FromAddress.String())
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
Expand All @@ -80,7 +80,7 @@ The empty ones will be filled with a special [do-not-modify] flag that tells the
},
}

cmd.Flags().String(FlagMoniker, types.DoNotModify, "Moniker to be used")
cmd.Flags().String(FlagNickname, types.DoNotModify, "Nickname to be used")
cmd.Flags().String(FlagBio, types.DoNotModify, "Biography to be used")
cmd.Flags().String(FlagProfilePic, types.DoNotModify, "Profile picture")
cmd.Flags().String(FlagCoverPic, types.DoNotModify, "Cover picture")
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func RegisterRoutes(cliCtx client.Context, r *mux.Router) {
type SaveProfileReq struct {
BaseReq rest.BaseReq `json:"base_req"`
DTag string `json:"dtag"`
Moniker string `json:"moniker,omitempty"`
Nickname string `json:"nickname,omitempty"`
Bio string `json:"bio,omitempty"`
Pictures types.Pictures `json:"pictures,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func saveProfileHandler(clientCtx client.Context) http.HandlerFunc {

msg := types.NewMsgSaveProfile(
req.DTag,
req.Moniker,
req.Nickname,
req.Bio,
req.Pictures.Profile,
req.Pictures.Cover,
Expand Down
12 changes: 6 additions & 6 deletions x/profiles/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (suite *KeeperTestSuite) Test_ExportGenesis() {
),
},
Params: types.NewParams(
types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
),
Expand Down Expand Up @@ -111,7 +111,7 @@ func (suite *KeeperTestSuite) Test_ExportGenesis() {
),
},
types.NewParams(
types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
),
Expand Down Expand Up @@ -153,7 +153,7 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {

profile1, err := types.NewProfile(
"dtag-1",
"moniker-1",
"nickname-1",
"bio-1",
types.NewPictures("profile-1", "cover-1"),
time.Date(2020, 1, 1, 00, 00, 00, 000, time.UTC),
Expand All @@ -163,7 +163,7 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {

profile2, err := types.NewProfile(
"dtag-2",
"moniker-2",
"nickname-2",
"bio-2",
types.NewPictures("profile-2", "cover-2"),
time.Date(2020, 1, 2, 00, 00, 00, 000, time.UTC),
Expand Down Expand Up @@ -266,7 +266,7 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {
),
},
types.NewParams(
types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
),
Expand Down Expand Up @@ -313,7 +313,7 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {
),
},
Params: types.NewParams(
types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
sdk.NewInt(1000),
),
Expand Down
16 changes: 8 additions & 8 deletions x/profiles/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ 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)

minMonikerLen := params.MonikerParams.MinMonikerLength.Int64()
maxMonikerLen := params.MonikerParams.MaxMonikerLength.Int64()
minNicknameLen := params.NicknameParams.MinNicknameLength.Int64()
maxNicknameLen := params.NicknameParams.MaxNicknameLength.Int64()

if profile.Moniker != "" {
nameLen := int64(len(profile.Moniker))
if nameLen < minMonikerLen {
return fmt.Errorf("profile moniker cannot be less than %d characters", minMonikerLen)
if profile.Nickname != "" {
nameLen := int64(len(profile.Nickname))
if nameLen < minNicknameLen {
return fmt.Errorf("profile nickname cannot be less than %d characters", minNicknameLen)
}
if nameLen > maxMonikerLen {
return fmt.Errorf("profile moniker cannot exceed %d characters", maxMonikerLen)
if nameLen > maxNicknameLen {
return fmt.Errorf("profile nickname cannot exceed %d characters", maxNicknameLen)
}
}

Expand Down
22 changes: 11 additions & 11 deletions x/profiles/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() {

updatedProfile, err := types.NewProfile(
"updated-dtag",
"updated-moniker",
"updated-nickname",
suite.testData.profile.Bio,
suite.testData.profile.Pictures,
suite.testData.profile.CreationDate,
Expand Down Expand Up @@ -299,7 +299,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
expErr error
}{
{
name: "Max moniker length exceeded",
name: "Max nickname length exceeded",
profile: suite.CheckProfileNoError(types.NewProfile(
"custom_dtag",
strings.Repeat("A", 1005),
Expand All @@ -311,10 +311,10 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
suite.testData.profile.CreationDate,
suite.testData.profile.GetAccount(),
)),
expErr: fmt.Errorf("profile moniker cannot exceed 1000 characters"),
expErr: fmt.Errorf("profile nickname cannot exceed 1000 characters"),
},
{
name: "Min moniker length not reached",
name: "Min nickname length not reached",
profile: suite.CheckProfileNoError(types.NewProfile(
"custom_dtag",
"m",
Expand All @@ -327,13 +327,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
suite.testData.profile.CreationDate,
suite.testData.profile.GetAccount(),
)),
expErr: fmt.Errorf("profile moniker cannot be less than 2 characters"),
expErr: fmt.Errorf("profile nickname cannot be less than 2 characters"),
},
{
name: "Max bio length exceeded",
profile: suite.CheckProfileNoError(types.NewProfile(
"custom_dtag",
"moniker",
"nickname",
strings.Repeat("A", 1005),
types.NewPictures(
"https://test.com/profile-picture",
Expand All @@ -349,7 +349,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
name: "Invalid dtag doesn't match regEx",
profile: suite.CheckProfileNoError(types.NewProfile(
"custom.",
"moniker",
"nickname",
strings.Repeat("A", 1000),
types.NewPictures(
"https://test.com/profile-picture",
Expand All @@ -364,7 +364,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
name: "Min dtag length not reached",
profile: suite.CheckProfileNoError(types.NewProfile(
"d",
"moniker",
"nickname",
"my-bio",
types.NewPictures(
"https://test.com/profile-picture",
Expand All @@ -380,7 +380,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
name: "Max dtag length exceeded",
profile: suite.CheckProfileNoError(types.NewProfile(
"9YfrVVi3UEI1ymN7n6isSct30xG6Jn1EDxEXxWOn0voSMIKqLhHsBfnZoXEyHNS",
"moniker",
"nickname",
"my-bio",
types.NewPictures(
"https://test.com/profile-picture",
Expand All @@ -395,7 +395,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
name: "Invalid profile pictures returns error",
profile: suite.CheckProfileNoError(types.NewProfile(
"dtag",
"moniker",
"nickname",
"my-bio",
types.NewPictures(
"pic",
Expand All @@ -410,7 +410,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() {
name: "Valid profile returns no error",
profile: suite.CheckProfileNoError(types.NewProfile(
"dtag",
"moniker",
"nickname",
"my-bio",
types.NewPictures(
"https://test.com/profile-picture",
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/keeper/msgs_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile)
// Update the existing profile with the values provided from the user
updated, err := profile.Update(types.NewProfileUpdate(
msg.DTag,
msg.Moniker,
msg.Nickname,
msg.Bio,
types.NewPictures(msg.ProfilePicture, msg.CoverPicture),
))
Expand Down
Loading