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

Leonardo/users relationship impl #260

Merged
merged 38 commits into from
Aug 31, 2020
Merged

Conversation

leobragaz
Copy link
Contributor

@leobragaz leobragaz commented Aug 17, 2020

Description

This PR implements the users' relationships.
Close #168 .

Checklist

  • Targeted PR against correct branch.
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit tests.
  • Wrote integration tests (simulation & CLI).
  • Updated the documentation.
  • Added an entry to the CHANGELOG.md file.
  • Re-reviewed Files changed in the Github PR explorer.

@leobragaz leobragaz added kind/new-feature Propose the addition of a new feature that does not yet exist x/profiles Module that allows to create and manage decentralized social profiles labels Aug 17, 2020
@leobragaz leobragaz self-assigned this Aug 17, 2020
@codecov
Copy link

codecov bot commented Aug 17, 2020

Codecov Report

Merging #260 into master will increase coverage by 0.56%.
The diff coverage is 92.47%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
x/posts/simulation/decoder.go 94.11% <0.00%> (ø)
x/profiles/keeper/querier.go 71.79% <0.00%> (ø)
x/profiles/simulation/decoder.go 85.71% <0.00%> (ø)
x/profiles/types/models/keys.go 0.00% <ø> (ø)
x/profiles/types/models/pictures.go 89.47% <ø> (ø)
x/profiles/types/models/profile.go 100.00% <ø> (ø)
x/relationships/types/models/keys.go 0.00% <0.00%> (ø)
x/profiles/keeper/handler.go 93.58% <50.00%> (ø)
x/relationships/keeper/querier.go 75.00% <75.00%> (ø)
x/relationships/simulation/decoder.go 77.77% <77.77%> (ø)
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56205de...a720170. Read the comment docs.

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
@leobragaz leobragaz marked this pull request as ready for review August 24, 2020 08:07
…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
@leobragaz
Copy link
Contributor Author

@RiccardoM I've made all the changes we discussed during the call.
I've not updated the docs yet, I'll wait for the approval of the code than I'll do it.

@leobragaz leobragaz requested a review from RiccardoM August 25, 2020 16:58
Copy link
Contributor

@RiccardoM RiccardoM left a 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 to RelationshipID
  • 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

@leobragaz leobragaz requested a review from RiccardoM August 26, 2020 08:47
Copy link
Contributor

@RiccardoM RiccardoM left a 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?

@@ -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")
Copy link
Contributor

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?

Copy link
Contributor Author

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

@@ -30,6 +31,8 @@ func GetTxCmd(_ string, cdc *codec.Codec) *cobra.Command {
profileTxCmd.AddCommand(flags.PostCommands(
GetCmdSaveProfile(cdc),
GetCmdDeleteProfile(cdc),
GetCmdCreateMonoDirectionalRelationship(cdc),
GetCmdDeleteUserRelationship(cdc),
Copy link
Contributor

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 {
Copy link
Contributor

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

Comment on lines 18 to 22
for _, addr := range relationships {
if addr.Equals(receiver) {
return fmt.Errorf("relationship already exists with %s", receiver)
}
}
Copy link
Contributor

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:

  1. Extract these lines in a new method, maybe something like DoesRelationshipExist
  2. Call the new method from the handler
  3. Inside this method, if the relationship already exists then simply not add it to the array instead of throwing an error

Copy link
Contributor Author

@leobragaz leobragaz Aug 27, 2020

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.

Copy link
Contributor

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

@leobragaz leobragaz requested a review from RiccardoM August 27, 2020 10:33
Copy link
Contributor

@RiccardoM RiccardoM left a 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?

// GetCmdQueryUserRelationships queries all the profiles' users' relationships
func GetCmdQueryUserRelationships(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "user_relationships [address]",
Copy link
Contributor

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]

@leobragaz leobragaz requested a review from RiccardoM August 28, 2020 13:07
Copy link
Contributor

@RiccardoM RiccardoM left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [`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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.

}

// GetCmdDeleteUserRelationship is the CLI command for deleting a relationship
func GetCmdDeleteUserRelationship(cdc *codec.Codec) *cobra.Command {
Copy link
Contributor

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

Comment on lines 15 to 16
r.HandleFunc("/relationships/create/{address}", createRelationshipHandler(cliCtx)).Methods("POST")
r.HandleFunc("/relationships/delete/{address}", deleteRelationshipHandler(cliCtx)).Methods("DELETE")
Copy link
Contributor

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?

Suggested change
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")

Copy link
Contributor Author

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

Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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,
},
Copy link
Contributor

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
@leobragaz leobragaz requested a review from RiccardoM August 31, 2020 09:41
@RiccardoM RiccardoM merged commit 454c3ab into master Aug 31, 2020
@RiccardoM RiccardoM deleted the leonardo/users-relationship-impl branch August 31, 2020 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/new-feature Propose the addition of a new feature that does not yet exist x/profiles Module that allows to create and manage decentralized social profiles
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement users relationship
2 participants