-
Notifications
You must be signed in to change notification settings - Fork 48
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
Leonardo/users relationship impl #260
Conversation
need to review the way of saving/getting relationships
added relationship id fixed keeper and handler methods
fixed lint errors
added relationshipID tests fixed relationship tests
Codecov Report
@@ Coverage Diff @@
## master #260 +/- ##
==========================================
+ Coverage 85.85% 86.42% +0.56%
==========================================
Files 82 95 +13
Lines 2970 3174 +204
==========================================
+ Hits 2550 2743 +193
- Misses 363 373 +10
- Partials 57 58 +1
Continue to review full report at Codecov.
|
added querier tests added cli tx and queries added rest tx and queries added helper functions for cli testing started CLI tests
added new relationships object to genesis
added simulation genesis tests fixed lint errors
…eonardo/users-relationship-impl � Conflicts: � x/posts/keeper/handler_test.go � x/posts/keeper/keeper_test.go � x/posts/types/alias.go � x/posts/types/models/post_response_test.go � x/posts/types/models/post_test.go � x/reports/types/alias.go
fixed some refactoring errors inside posts
improved code
…eonardo/users-relationship-impl � Conflicts: � CHANGELOG.md
…eonardo/users-relationship-impl � Conflicts: � CHANGELOG.md
removed keeper blank lines merged with master
excluded sim tests from coverage
fixed sim tests fixed cli tests
@RiccardoM I've made all the changes we discussed during the call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you made some refactoring errors. Namely:
- All
ID
references inside strings have been changed toRelationshipID
- All the
profilesTypes "github.com/desmos-labs/desmos/x/profiles/types"
imports have been changed to"github.com/desmos-labs/desmos/x/profiles/types/models"
Can you please revert that so that I have to view less files? Otherwise it would be complicated for me to see actual changes in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good. I left some comments. Also, I would like to discuss the possibility of moving the whole relationship implementation inside their own module instead of leaving it inside the x/profile
one. What do you think?
x/profiles/client/rest/query.go
Outdated
@@ -15,6 +15,7 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { | |||
r.HandleFunc("/profiles/parameters", queryProfilesParamsHandlerFn(cliCtx)).Methods("GET") | |||
r.HandleFunc("/profiles/{address_or_dtag}", queryProfileHandlerFn(cliCtx)).Methods("GET") | |||
r.HandleFunc("/profiles", queryProfilesHandlerFn(cliCtx)).Methods("GET") | |||
r.HandleFunc("/relationships/{address}", queryUserRelationships(cliCtx)).Methods("GET") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a new endpoint to query all the relationship for all the profiles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it could be good, Also ok for moving relationships on a new module
x/profiles/client/cli/tx.go
Outdated
@@ -30,6 +31,8 @@ func GetTxCmd(_ string, cdc *codec.Codec) *cobra.Command { | |||
profileTxCmd.AddCommand(flags.PostCommands( | |||
GetCmdSaveProfile(cdc), | |||
GetCmdDeleteProfile(cdc), | |||
GetCmdCreateMonoDirectionalRelationship(cdc), | |||
GetCmdDeleteUserRelationship(cdc), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a new command to query all the relationship for all the profiles?
} | ||
|
||
// GetUsersRelationshipsMap allows to returns the map of all the users and their associated storedRelationships | ||
func (k Keeper) GetUsersRelationshipsMap(ctx sdk.Context) map[string][]sdk.AccAddress { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can rename this to be simply GetUsersRelationships
for _, addr := range relationships { | ||
if addr.Equals(receiver) { | ||
return fmt.Errorf("relationship already exists with %s", receiver) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of performing this check here, I think we can:
- Extract these lines in a new method, maybe something like
DoesRelationshipExist
- Call the new method from the handler
- Inside this method, if the relationship already exists then simply not add it to the array instead of throwing an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think extracting this is the better choice since we use it only here and, with a method like DoesRelationshipExist
, we'll need to access two times to the store instead of one inside the msg
Handler
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bragaz Ok, I see. Then let's keep it that way
to a new module relationships
reviewed query and tx endpoints added docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Can we rename all the MonoDirectionalRelationship
referenced to be simply Relationship
instead?
x/relationships/client/cli/query.go
Outdated
// GetCmdQueryUserRelationships queries all the profiles' users' relationships | ||
func GetCmdQueryUserRelationships(cdc *codec.Codec) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "user_relationships [address]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can rename this to be simply user [address]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Some small fixed and tests additions and it should be ready to be merged 💯
@@ -0,0 +1,38 @@ | |||
# `MsgCreateRelationship` | |||
This message allows you to create a mono directional relationship with a specified user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message allows you to create a mono directional relationship with a specified user. | |
This message allows you to create a relationship between the signer and a specified user. |
@@ -0,0 +1,38 @@ | |||
# `MsgCreateRelationship` | |||
This message allows you to create a mono directional relationship with a specified user. | |||
Mono directional relationships are like the follow of today's social networks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mono directional relationships are like the follow of today's social networks. |
@@ -0,0 +1,37 @@ | |||
# `MsgDeleteRelationship` | |||
This message allows you to delete a mono directional relationship with a specified counterparty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message allows you to delete a mono directional relationship with a specified counterparty. | |
This message allows you to delete a relationship existing with a specified counterparty. |
* [`MsgSaveProfile`](msgs/save-profile.md): allows you to create or edit an existing profile. | ||
* [`MsgDeleteProfile`](msgs/delete-profile.md): allows you to delete an existing profile. | ||
* [`EditParamsProposal`](msgs/edit_param_proposal.md): allows you to open a proposal to change profile's params. | ||
|
||
## Relationships | ||
* [`MsgCreateMonoDirectionalRelationship`](msgs/create-relationship.md): allows you to create a mono directional relationship. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [`MsgCreateMonoDirectionalRelationship`](msgs/create-relationship.md): allows you to create a mono directional relationship. | |
* [`MsgCreateRelationship`](msgs/create-relationship.md): allows you to create a relationship. |
@@ -0,0 +1,18 @@ | |||
## Query user relationships | |||
This query endpoint allows you to retrieve the details of a relationship where the creator is the given `address`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query endpoint allows you to retrieve the details of a relationship where the creator is the given `address`. | |
This query endpoint allows you to retrieve the details of a relationship where the creator has the given `address`. |
x/relationships/client/cli/tx.go
Outdated
} | ||
|
||
// GetCmdDeleteUserRelationship is the CLI command for deleting a relationship | ||
func GetCmdDeleteUserRelationship(cdc *codec.Codec) *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can rename this GetCmdDeleteRelationship
for simplicity
x/relationships/client/rest/tx.go
Outdated
r.HandleFunc("/relationships/create/{address}", createRelationshipHandler(cliCtx)).Methods("POST") | ||
r.HandleFunc("/relationships/delete/{address}", deleteRelationshipHandler(cliCtx)).Methods("DELETE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can delete the /create/
and /delete/
parts of the query, and maybe the /{address}
as well, requiring the user to put it into the body of the request instead. What do you think?
r.HandleFunc("/relationships/create/{address}", createRelationshipHandler(cliCtx)).Methods("POST") | |
r.HandleFunc("/relationships/delete/{address}", deleteRelationshipHandler(cliCtx)).Methods("DELETE") | |
r.HandleFunc("/relationships", createRelationshipHandler(cliCtx)).Methods("POST") | |
r.HandleFunc("/relationships", deleteRelationshipHandler(cliCtx)).Methods("DELETE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there will not be much difference. The only concern I have is if it's possibile to have two endpoints with the exact same name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bragaz Yes, it is cause the REST method will be different. In the first one it will be POST
, and the other one it will be DELETE
. Removing the /create
and /delete
parts will make the endpoint follow the REST guidelines (no verbs inside endpoint names, only nouns). And removing the {address}
variable will make it coherent with other requests as well
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestKeeper_GetUserRelationshipsMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test case where we try to read the relationships with an empty set?
suite.Equal(relationshipsMap, actualIDsMap) | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestKeeper_GetUserRelationships() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test case where we try to read the relationships with an empty slice?
storedRelationships: []sdk.AccAddress{addr1}, | ||
expRelationships: nil, | ||
userToDelete: addr1, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test case where we try deleting a relationship with len(relationships) == 0
?
added test cases edited tx endpoints fixed docs
Description
This PR implements the users' relationships.
Close #168 .
Checklist
CHANGELOG.md
file.Files changed
in the Github PR explorer.