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
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
6 changes: 0 additions & 6 deletions x/profiles/types/msgs_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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 +35,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