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
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
989e47c
reviewed `profiles` folders organization
leobragaz Aug 6, 2020
321420f
added relationship types and methods + tests
leobragaz Aug 7, 2020
c468f20
added relationships messages and tests + keys
leobragaz Aug 7, 2020
813cce0
added msg delete relationship + tests
leobragaz Aug 7, 2020
1dc2d05
started developing keeper methods
leobragaz Aug 7, 2020
ff38990
added keeper methods and handler
leobragaz Aug 10, 2020
e44cba4
edited the way relations are handled inside keeper,
leobragaz Aug 11, 2020
22740ed
completed handler's and keeper's relationships methods
leobragaz Aug 12, 2020
3dff7d7
fixed msgs and keeper tests
leobragaz Aug 13, 2020
f20fef7
added handler tests
leobragaz Aug 13, 2020
3aa5a79
added querier method
leobragaz Aug 17, 2020
b0f0ee5
added cli tests
leobragaz Aug 18, 2020
d932f30
added simulation tests for relationships msgs
leobragaz Aug 18, 2020
b925022
added methods for genesis
leobragaz Aug 19, 2020
b6da0e0
added initialization of new data structures to init genesis
leobragaz Aug 20, 2020
47725b6
Merge branch 'master' of https://github.com/desmos-labs/desmos into l…
leobragaz Aug 20, 2020
493f2a6
merged with master
leobragaz Aug 20, 2020
ac79300
fixed sim tests
leobragaz Aug 20, 2020
9f93900
raised gas to make sim tests pass
leobragaz Aug 20, 2020
c4923ca
added tests to raise coverage
leobragaz Aug 21, 2020
8236487
Merge branch 'master' of https://github.com/desmos-labs/desmos into l…
leobragaz Aug 24, 2020
bcfe6dc
Merge branch 'master' of https://github.com/desmos-labs/desmos into l…
leobragaz Aug 24, 2020
8f745a4
added docs lines to handler
leobragaz Aug 24, 2020
851e748
added tests to raise coverage
leobragaz Aug 24, 2020
479d8dd
fixed relationships as discussed in morning call
leobragaz Aug 24, 2020
fd9d43d
fixed sims tests
leobragaz Aug 25, 2020
5735392
added relationships response
leobragaz Aug 25, 2020
536623e
raise coverage
leobragaz Aug 25, 2020
7d2ee3f
fixed refactoring errors
leobragaz Aug 26, 2020
359bae7
fixed refactoring errors
leobragaz Aug 26, 2020
91068ab
fixed refactoring errors
leobragaz Aug 26, 2020
7f3a6bf
fixed refactoring errors
leobragaz Aug 26, 2020
90c6679
moved all relationships related files
leobragaz Aug 26, 2020
3d50e7e
added dontcover to sim files
leobragaz Aug 26, 2020
31cd7cc
added new query for all relationships
leobragaz Aug 27, 2020
cc1366c
added a query to retrieve all the relationships
leobragaz Aug 27, 2020
ebc47f6
renamed query and message
leobragaz Aug 28, 2020
a720170
fixed PR's suggestions:
leobragaz Aug 31, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
##Changes
- Allowed the possibility to edit a post's attachments and poll data using the `MsgEditPost` type (#202)
- Removed the `Open` field from within the `PollData` object. Now you should rely on the `CloseDate` field to determine whether a poll is closed or open. (#252)
- Implemented users `Relationships` (#168)

# Version 0.10.0
## Changes
Expand Down
20 changes: 11 additions & 9 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package params

// Default simulation operation weights for messages
const (
DefaultWeightMsgCreatePost int = 100
DefaultWeightMsgEditPost int = 100
DefaultWeightMsgAddReaction int = 100
DefaultWeightMsgRemoveReaction int = 100
DefaultWeightMsgAnswerPoll int = 100
DefaultWeightMsgRegisterReaction int = 100
DefaultWeightMsgSaveAccount int = 100
DefaultWeightMsgDeleteAccount int = 100
DefaultWeightMsgReportPost int = 100
DefaultWeightMsgCreatePost int = 100
DefaultWeightMsgEditPost int = 100
DefaultWeightMsgAddReaction int = 100
DefaultWeightMsgRemoveReaction int = 100
DefaultWeightMsgAnswerPoll int = 100
DefaultWeightMsgRegisterReaction int = 100
DefaultWeightMsgSaveAccount int = 100
DefaultWeightMsgDeleteAccount int = 100
DefaultWeightMsgReportPost int = 100
DefaultWeightMsgCreateRelationship int = 100
DefaultWeightMsgDeleteRelationship int = 100
)
112 changes: 112 additions & 0 deletions cli_test/cli_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package clitest

import (
"github.com/desmos-labs/desmos/x/profiles/types"
"testing"

"github.com/cosmos/cosmos-sdk/tests"
Expand Down Expand Up @@ -327,3 +328,114 @@ func TestDesmosCLIProfileDelete(t *testing.T) {

f.Cleanup()
}

func TestDesmosCLICreateMonoDirectionalRelationship(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

// Start Desmosd server
proc := f.GDStart()
defer proc.Stop(false)

// Save key addresses for later use
fooAddr := f.KeyAddress(keyFoo)

// Later usage variables
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromConsensusPower(140)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
receiver, err := sdk.AccAddressFromBech32("desmos15ux5mc98jlhsg30dzwwv06ftjs82uy4g3t99ru")
require.NoError(t, err)

// Create mono directional relationship
success, _, sterr := f.TxCreateMonoDirectionalRelationship(receiver, fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure relationship is created
storedRelationships := f.QueryRelationships(fooAddr)
require.NotEmpty(t, storedRelationships)
expRelationship := types.NewRelationshipResponse([]sdk.AccAddress{receiver})
require.Equal(t, expRelationship, storedRelationships)

// Delete the relationship to perform other tests
success, _, sterr = f.TxDeleteUserRelationship(receiver, fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Test --dry-tun
success, _, _ = f.TxCreateMonoDirectionalRelationship(receiver, fooAddr, "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxCreateMonoDirectionalRelationship(receiver, fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

f.Cleanup()
}

func TestDesmosCLIDeleteRelationship(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

// Start Desmosd server
proc := f.GDStart()
defer proc.Stop(false)

// Save key addresses for later use
fooAddr := f.KeyAddress(keyFoo)

// Later usage variables
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromConsensusPower(140)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))
receiver, err := sdk.AccAddressFromBech32("desmos15ux5mc98jlhsg30dzwwv06ftjs82uy4g3t99ru")
require.NoError(t, err)

// Create mono directional relationship
success, _, sterr := f.TxCreateMonoDirectionalRelationship(receiver, fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure relationship is created
storedRelationships := f.QueryRelationships(fooAddr)
require.NotEmpty(t, storedRelationships)
expRelationship := types.NewRelationshipResponse([]sdk.AccAddress{receiver})
require.Equal(t, expRelationship, storedRelationships)

// Delete the relationship to perform other tests
success, _, sterr = f.TxDeleteUserRelationship(receiver, fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure relationship is deleted
storedRelationships = f.QueryRelationships(fooAddr)
require.Empty(t, storedRelationships)

// Create mono directional relationship
success, _, sterr = f.TxCreateMonoDirectionalRelationship(receiver, fooAddr, "-y")

// Test --dry-tun
success, _, _ = f.TxDeleteUserRelationship(receiver, fooAddr, "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxDeleteUserRelationship(receiver, fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

f.Cleanup()
}
30 changes: 27 additions & 3 deletions cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

"github.com/desmos-labs/desmos/app"
postsTypes "github.com/desmos-labs/desmos/x/posts/types"
profileTypes "github.com/desmos-labs/desmos/x/profiles/types"
profilesTypes "github.com/desmos-labs/desmos/x/profiles/types"
reportsTypes "github.com/desmos-labs/desmos/x/reports/types"
)

Expand Down Expand Up @@ -467,6 +467,18 @@ func (f *Fixtures) TxProfileDelete(from sdk.AccAddress, flags ...string) (bool,
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

func (f *Fixtures) TxCreateMonoDirectionalRelationship(receiver, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles create-relationship %s --keyring-backend=test --from=%s %v`,
f.DesmoscliBinary, receiver, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

func (f *Fixtures) TxDeleteUserRelationship(receiver, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles delete-relationship %s --keyring-backend=test --from=%s %v`,
f.DesmoscliBinary, receiver, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

//___________________________________________________________________________________
// desmoscli tx reports

Expand Down Expand Up @@ -791,17 +803,29 @@ func (f *Fixtures) QueryReactions(flags ...string) postsTypes.Reactions {
// query profile

// QueryProfile returns stored profiles
func (f *Fixtures) QueryProfiles(flags ...string) profileTypes.Profiles {
func (f *Fixtures) QueryProfiles(flags ...string) profilesTypes.Profiles {
cmd := fmt.Sprintf("%s query profiles all --output=json %s", f.DesmoscliBinary, f.Flags())
res, errStr := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
var storedProfile profileTypes.Profiles
var storedProfile profilesTypes.Profiles
err := cdc.UnmarshalJSON([]byte(res), &storedProfile)
require.NoError(f.T, err)
return storedProfile
}

// QueryRelationships returns stored relationships
func (f *Fixtures) QueryRelationships(user sdk.AccAddress, flags ...string) profilesTypes.RelationshipsResponse {
cmd := fmt.Sprintf("%s query profiles relationships %s --output=json %s", f.DesmoscliBinary, user, f.Flags())
res, errStr := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
var storedRelationships profilesTypes.RelationshipsResponse
err := cdc.UnmarshalJSON([]byte(res), &storedRelationships)
require.NoError(f.T, err)
return storedRelationships
}

//___________________________________________________________________________________
// query reports

Expand Down
50 changes: 25 additions & 25 deletions x/posts/types/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ const (

var (
// functions aliases
ParsePostID = models.ParsePostID
NewPost = models.NewPost
NewPostResponse = models.NewPostResponse
PostStoreKey = models.PostStoreKey
PostIndexedIDStoreKey = models.PostIndexedIDStoreKey
PostCommentsStoreKey = models.PostCommentsStoreKey
PostReactionsStoreKey = models.PostReactionsStoreKey
ReactionsStoreKey = models.ReactionsStoreKey
PollAnswersStoreKey = models.PollAnswersStoreKey
RegisterModelsCodec = models.RegisterModelsCodec
IsValidPostID = common.IsValidPostID
IsValidSubspace = common.IsValidSubspace
IsValidReactionCode = common.IsValidReactionCode
GetEmojiByShortCodeOrValue = common.GetEmojiByShortCodeOrValue
NewAttachment = common.NewAttachment
NewAttachments = common.NewAttachments
ParseAnswerID = polls.ParseAnswerID
NewPollAnswer = polls.NewPollAnswer
NewPollAnswers = polls.NewPollAnswers
Expand All @@ -47,29 +63,13 @@ var (
NewReaction = reactions.NewReaction
IsEmoji = reactions.IsEmoji
NewReactions = reactions.NewReactions
RegisterMessagesCodec = msgs.RegisterMessagesCodec
NewMsgAddPostReaction = msgs.NewMsgAddPostReaction
NewMsgRemovePostReaction = msgs.NewMsgRemovePostReaction
NewMsgAnswerPoll = msgs.NewMsgAnswerPoll
NewMsgCreatePost = msgs.NewMsgCreatePost
NewMsgEditPost = msgs.NewMsgEditPost
NewMsgRegisterReaction = msgs.NewMsgRegisterReaction
RegisterMessagesCodec = msgs.RegisterMessagesCodec
NewMsgAddPostReaction = msgs.NewMsgAddPostReaction
NewMsgRemovePostReaction = msgs.NewMsgRemovePostReaction
ParsePostID = models.ParsePostID
NewPost = models.NewPost
NewPostResponse = models.NewPostResponse
PostStoreKey = models.PostStoreKey
PostIndexedIDStoreKey = models.PostIndexedIDStoreKey
PostCommentsStoreKey = models.PostCommentsStoreKey
PostReactionsStoreKey = models.PostReactionsStoreKey
ReactionsStoreKey = models.ReactionsStoreKey
PollAnswersStoreKey = models.PollAnswersStoreKey
RegisterModelsCodec = models.RegisterModelsCodec
NewAttachment = common.NewAttachment
NewAttachments = common.NewAttachments
IsValidPostID = common.IsValidPostID
IsValidSubspace = common.IsValidSubspace
IsValidReactionCode = common.IsValidReactionCode
GetEmojiByShortCodeOrValue = common.GetEmojiByShortCodeOrValue

// variable aliases
MsgsCodec = msgs.MsgsCodec
Expand All @@ -85,12 +85,6 @@ var (
)

type (
MsgAnswerPoll = msgs.MsgAnswerPoll
MsgCreatePost = msgs.MsgCreatePost
MsgEditPost = msgs.MsgEditPost
MsgRegisterReaction = msgs.MsgRegisterReaction
MsgAddPostReaction = msgs.MsgAddPostReaction
MsgRemovePostReaction = msgs.MsgRemovePostReaction
PostID = models.PostID
PostIDs = models.PostIDs
Post = models.Post
Expand All @@ -111,4 +105,10 @@ type (
PostReactions = reactions.PostReactions
Reaction = reactions.Reaction
Reactions = reactions.Reactions
MsgAddPostReaction = msgs.MsgAddPostReaction
MsgRemovePostReaction = msgs.MsgRemovePostReaction
MsgAnswerPoll = msgs.MsgAnswerPoll
MsgCreatePost = msgs.MsgCreatePost
MsgEditPost = msgs.MsgEditPost
MsgRegisterReaction = msgs.MsgRegisterReaction
)
12 changes: 6 additions & 6 deletions x/posts/types/models/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ var (
GetEmojiByShortCodeOrValue = common.GetEmojiByShortCodeOrValue
NewAttachment = common.NewAttachment
NewAttachments = common.NewAttachments
ParseAnswerID = polls.ParseAnswerID
NewPollAnswer = polls.NewPollAnswer
NewPollAnswers = polls.NewPollAnswers
NewPollData = polls.NewPollData
ArePollDataEquals = polls.ArePollDataEquals
NewUserAnswer = polls.NewUserAnswer
NewUserAnswers = polls.NewUserAnswers
ParseAnswerID = polls.ParseAnswerID
NewPollAnswer = polls.NewPollAnswer
NewPollAnswers = polls.NewPollAnswers
NewPostReaction = reactions.NewPostReaction
NewPostReactions = reactions.NewPostReactions
NewReaction = reactions.NewReaction
Expand All @@ -68,12 +68,12 @@ type (
KeyValue = common.KeyValue
Attachment = common.Attachment
Attachments = common.Attachments
AnswerID = polls.AnswerID
PollAnswer = polls.PollAnswer
PollAnswers = polls.PollAnswers
PollData = polls.PollData
UserAnswer = polls.UserAnswer
UserAnswers = polls.UserAnswers
AnswerID = polls.AnswerID
PollAnswer = polls.PollAnswer
PollAnswers = polls.PollAnswers
PostReaction = reactions.PostReaction
PostReactions = reactions.PostReactions
Reaction = reactions.Reaction
Expand Down
31 changes: 27 additions & 4 deletions x/profiles/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/spf13/cobra"

"github.com/desmos-labs/desmos/x/profiles/types"
"github.com/spf13/cobra"
)

// GetQueryCmd adds the query commands
Expand All @@ -25,6 +24,7 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
GetCmdQueryProfile(cdc),
GetCmdQueryProfiles(cdc),
GetCmdQueryProfileParams(cdc),
GetCmdQueryUserRelationships(cdc),
)...)
return profileQueryCmd
}
Expand Down Expand Up @@ -57,7 +57,7 @@ func GetCmdQueryProfiles(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "all",
Short: "Retrieve all the registered profiles.",
Args: cobra.ExactArgs(0),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

Expand All @@ -80,7 +80,7 @@ func GetCmdQueryProfileParams(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "parameters",
Short: "Retrieve all the profile module parameters",
Args: cobra.ExactArgs(0),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

Expand All @@ -97,3 +97,26 @@ func GetCmdQueryProfileParams(cdc *codec.Codec) *cobra.Command {
},
}
}

// GetCmdQueryUserRelationships queries all the profiles' users' relationships
func GetCmdQueryUserRelationships(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "relationships [address]",
Short: "Retrieve all the user's relationships",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

route := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, types.QueryRelationships, args[0])
res, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
fmt.Printf("Could not find any relationship associated with the given address %s", args[0])
return nil
}

var out types.RelationshipsResponse
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}
Loading