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
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: x/profiles
pull_request: 651
description: edited save profile cli command to avoid accidental dtag override
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
backward_compatible: true
date: 2021-10-18T07:46:28.091666Z
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go v1.2.1
github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20210623064146-c30bc8196d0f
github.com/desmos-labs/changeset v0.0.0-20210928063644-c1c28b0364b7 // indirect
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE=
github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20210623064146-c30bc8196d0f h1:gUywWy8Pw1ROmF4o/qLy/FP1bEyEtjPg6a/RgdXmcCA=
github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20210623064146-c30bc8196d0f/go.mod h1:5TMhouV+kDGQZZrBK+rzBP+Jmeyu0V7WvrBHqukiTv8=
github.com/desmos-labs/changeset v0.0.0-20210928063644-c1c28b0364b7 h1:LXbQ2HwztczVv7H2Fda+GR9ixiY19btQwDQoEr0xYYk=
github.com/desmos-labs/changeset v0.0.0-20210928063644-c1c28b0364b7/go.mod h1:M09LGRoE77bmC9LmZ+PMZwlvQDGLu0SBoXCayGCbYjg=
github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210927075512-e26bf1014f50 h1:aHMy8n0itEDKqMIAnjdNJ2L8SMzBgqTx0TXzDVYKCOc=
github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210927075512-e26bf1014f50/go.mod h1:2Gy2237TJhvo7vcn+r8hovzipVaLj51Mjtuw9eyzWEU=
github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20211012153741-0450cc890f95 h1:OwvcwlMwvY+AD0/agVgvlTayPvSWqaDK318/h7+Yqdo=
Expand Down Expand Up @@ -614,6 +616,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU=
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
github.com/juju/ansiterm v0.0.0-20210706145210-9283cdf370b5 h1:Q5klzs6BL5FkassBX65t+KkG0XjYcjxEm+GNcQAsuaw=
github.com/juju/ansiterm v0.0.0-20210706145210-9283cdf370b5/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
Expand Down Expand Up @@ -671,6 +675,8 @@ github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQ
github.com/lucasjones/reggen v0.0.0-20180717132126-cdb49ff09d77/go.mod h1:5ELEyG+X8f+meRWHuqUOewBOhvHkl7M76pdGEansxW4=
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
github.com/lunixbochs/vtclean v1.0.0 h1:xu2sLAri4lGiovBDQKxl5mrXyESr3gUr5m5SM5+LVb8=
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
Expand Down
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 created because DTag is set to DoNotModify",
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