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

feat: ADR-009: Make MsgSaveProfile DTag optional #651

Merged
merged 9 commits into from
Oct 18, 2021
33 changes: 17 additions & 16 deletions x/profiles/client/cli/cli_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ import (
"github.com/desmos-labs/desmos/v2/x/profiles/types"
)

// GetCmdSaveProfile returns the command used to save a profile
func GetCmdSaveProfile() *cobra.Command {
cmd := &cobra.Command{
Use: "save [dtag]",
Args: cobra.ExactArgs(1),
Short: "Save your profile associating to it the given DTag.",
Use: "save",
Args: cobra.NoArgs,
Short: "Save your profile",
Long: fmt.Sprintf(`
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.

%s tx profiles save LeoDiCap \
--%s "Leonardo Di Caprio" \
--%s "Hollywood actor. Proud environmentalist" \
--%s "https://profilePic.jpg" \
--%s "https://profileCover.jpg"
`, version.AppName, FlagNickname, FlagBio, FlagProfilePic, FlagCoverPic),
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.

%s tx profiles save
--%s "LeoDiCaprio" \
--%s "Leonardo Di Caprio" \
--%s "Hollywood actor. Proud environmentalist" \
--%s "https://profilePic.jpg" \
--%s "https://profileCover.jpg"
`, version.AppName, FlagDTag, 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]
dTag, _ := cmd.Flags().GetString(FlagDTag)
nickname, _ := cmd.Flags().GetString(FlagNickname)
bio, _ := cmd.Flags().GetString(FlagBio)
profilePic, _ := cmd.Flags().GetString(FlagProfilePic)
Expand All @@ -52,6 +52,7 @@ The empty ones will be filled with a special [do-not-modify] flag that tells the
},
}

cmd.Flags().String(FlagDTag, types.DoNotModify, "DTag 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")
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/client/cli/cli_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (s *IntegrationTestSuite) TestCmdSaveProfile() {
{
name: "correct data returns no error",
args: []string{
"dtag",
fmt.Sprintf("--%s=%s", cli.FlagDTag, "dtag"),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
Expand Down
1 change: 1 addition & 0 deletions x/profiles/client/cli/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

const (
FlagDTag = "dtag"
FlagNickname = "nickname"
FlagBio = "bio"
FlagProfilePic = "profile-pic"
Expand Down
56 changes: 54 additions & 2 deletions x/profiles/keeper/msgs_server_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (suite *KeeperTestSuite) TestMsgServer_SaveProfile() {
name: "profile saved with same DTag but capital first letter (with previous profile created)",
store: func(ctx sdk.Context) {
profile := suite.CheckProfileNoError(types.NewProfile(
"tc",
"tomtom",
"old-nickname",
"old-biography",
types.NewPictures(
Expand Down Expand Up @@ -134,7 +134,7 @@ func (suite *KeeperTestSuite) TestMsgServer_SaveProfile() {
name: "profile not saved because of the same DTag",
store: func(ctx sdk.Context) {
profile := suite.CheckProfileNoError(types.NewProfile(
"tc",
"Test",
"nickname",
"biography",
types.NewPictures(
Expand All @@ -156,6 +156,58 @@ func (suite *KeeperTestSuite) TestMsgServer_SaveProfile() {
),
shouldErr: true,
},
{
name: "profile not saved because DTag is set to DoNotModify",
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
msg: types.NewMsgSaveProfile(
types.DoNotModify,
"another-one",
"biography",
"https://tc.com/profile-pic",
"https://tc.com/cover-pic",
"cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns",
),
shouldErr: true,
},
{
name: "profile updated correctly with DTag set to DoNotModify",
store: func(ctx sdk.Context) {
profile := suite.CheckProfileNoError(types.NewProfile(
"tomtom",
"nickname",
"biography",
types.NewPictures(
"https://tc.com/profile-pic",
"https://tc.com/cover-pic",
),
blockTime,
testutil.AccountFromAddr("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns"),
))
suite.Require().NoError(suite.k.StoreProfile(ctx, profile))
},
msg: types.NewMsgSaveProfile(
types.DoNotModify,
"another-one",
"biography",
"https://tc.com/profile-pic",
"https://tc.com/cover-pic",
"cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns",
),
expEvents: sdk.Events{
sdk.NewEvent(
types.EventTypeProfileSaved,
sdk.NewAttribute(types.AttributeProfileDTag, "tomtom"),
sdk.NewAttribute(types.AttributeProfileCreator, "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns"),
sdk.NewAttribute(types.AttributeProfileCreationTime, blockTime.Format(time.RFC3339)),
),
},
check: func(ctx sdk.Context) {
profile, found, err := suite.k.GetProfile(ctx, "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns")
suite.Require().NoError(err)
suite.Require().True(found)
suite.Require().Equal("tomtom", profile.DTag)
suite.Require().Equal("another-one", profile.Nickname)
},
},
{
leobragaz marked this conversation as resolved.
Show resolved Hide resolved
name: "profile not edited because of the invalid profile picture",
store: func(ctx sdk.Context) {
Expand Down
15 changes: 15 additions & 0 deletions x/profiles/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ func TestProfile_Validate(t *testing.T) {
)),
shouldErr: true,
},
{
name: "setting DTag to DoNotModify returns error",
account: testutil.AssertNoProfileError(types.NewProfile(
types.DoNotModify,
"",
"bio",
types.NewPictures(
"https://shorturl.at/adnX3",
"https://shorturl.at/cgpyF",
),
time.Now(),
testutil.AccountFromAddr("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47"),
)),
shouldErr: true,
},
{
name: "invalid profile picture returns error",
account: testutil.AssertNoProfileError(types.NewProfile(
Expand Down
5 changes: 0 additions & 5 deletions x/profiles/types/msgs_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -37,10 +36,6 @@ func (msg MsgSaveProfile) ValidateBasic() error {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator: %s", msg.Creator))
}

if strings.TrimSpace(msg.DTag) == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "profile dtag cannot be empty or blank")
}

return nil
}

Expand Down
12 changes: 0 additions & 12 deletions x/profiles/types/msgs_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ func TestMsgSaveProfile_ValidateBasic(t *testing.T) {
),
shouldErr: true,
},
{
name: "empty DTag returns error",
msg: types.NewMsgSaveProfile(
"",
"",
"",
"",
"",
"cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns",
),
shouldErr: true,
},
{
name: "valid message returns no error",
msg: msgEditProfile,
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/types/query_app_links.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
query "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/types/query"
)

// NewQueryApplicationLinksRequest returns a new QueryApplicationLinksRequest instance
Expand Down