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 28 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
23 changes: 14 additions & 9 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ 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
DefaultWeightMsgRequestRelationship int = 100
DefaultWeightMsgAcceptRelationship int = 100
DefaultWeightMsgDenyRelationship int = 100
DefaultWeightMsgDeleteRelationship int = 100
)
4 changes: 2 additions & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"encoding/json"
"fmt"
"github.com/desmos-labs/desmos/x/profiles/types/models"
"math/rand"
"os"
"path/filepath"
Expand All @@ -17,7 +18,6 @@ import (

magpieTypes "github.com/desmos-labs/desmos/x/magpie/types"
postsTypes "github.com/desmos-labs/desmos/x/posts/types"
profilesTypes "github.com/desmos-labs/desmos/x/profiles/types"
reportsTypes "github.com/desmos-labs/desmos/x/reports/types"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestAppImportExport(t *testing.T) {

{app.keys[magpieTypes.StoreKey], newApp.keys[magpieTypes.StoreKey], [][]byte{}},
{app.keys[postsTypes.StoreKey], newApp.keys[postsTypes.StoreKey], [][]byte{}},
{app.keys[profilesTypes.StoreKey], newApp.keys[profilesTypes.StoreKey], [][]byte{}},
{app.keys[models.StoreKey], newApp.keys[models.StoreKey], [][]byte{}},
{app.keys[reportsTypes.StoreKey], newApp.keys[reportsTypes.StoreKey], [][]byte{}},
}

Expand Down
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 @@ -24,11 +24,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/desmos-labs/desmos/x/profiles/types"
"github.com/stretchr/testify/require"

"github.com/desmos-labs/desmos/app"
postsTypes "github.com/desmos-labs/desmos/x/posts/types"
profileTypes "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) types.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 types.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) types.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 types.RelationshipsResponse
err := cdc.UnmarshalJSON([]byte(res), &storedRelationships)
require.NoError(f.T, err)
return storedRelationships
}

//___________________________________________________________________________________
// query reports

Expand Down
2 changes: 1 addition & 1 deletion cmd/desmoscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
}

// Add --chain-id to persistent flags and mark it required
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "Chain ID of tendermint node")
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "Chain RelationshipID of tendermint node")
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
return initConfig(rootCmd)
}
Expand Down
4 changes: 2 additions & 2 deletions x/magpie/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func (suite *KeeperTestSuite) TestKeeper_GetLastSessionID() {
expID types.SessionID
}{
{
name: "First ID is returned properly",
name: "First RelationshipID is returned properly",
expID: types.SessionID(0),
},
{
name: "Existing ID is returned properly",
name: "Existing RelationshipID is returned properly",
existingID: types.SessionID(18446744073709551615),
expID: types.SessionID(18446744073709551615),
},
Expand Down
2 changes: 1 addition & 1 deletion x/magpie/legacy/v0.2.0/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SessionID uint64

// Session is a struct of a user session
type Session struct {
SessionID SessionID `json:"id,string"` // Id of the session
SessionID SessionID `json:"id,string"` // RelationshipID of the session
Owner sdk.AccAddress `json:"owner"` // Desmos owner of this session
Created int64 `json:"creation_time,string"` // Block height at which the session has been created
Expiry int64 `json:"expiration_time,string"` // Block height at which the session will expire
Expand Down
2 changes: 1 addition & 1 deletion x/magpie/legacy/v0.3.0/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type SessionID uint64

// Session is a struct of a user session
type Session struct {
SessionID SessionID `json:"id,string"` // Id of the session
SessionID SessionID `json:"id,string"` // RelationshipID of the session
Owner sdk.AccAddress `json:"owner"` // Desmos owner of this session
Created int64 `json:"creation_time,string"` // Block height at which the session has been created
Expiry int64 `json:"expiration_time,string"` // Block height at which the session will expire
Expand Down
2 changes: 1 addition & 1 deletion x/magpie/types/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ParseSessionID(value string) (SessionID, error) {

// Session is a struct of a user session
type Session struct {
SessionID SessionID `json:"id,string" yaml:"id,string"` // Id of the session
SessionID SessionID `json:"id,string" yaml:"id,string"` // RelationshipID of the session
Owner sdk.AccAddress `json:"owner" yaml:"owner"` // Desmos owner of this session
Created int64 `json:"creation_time,string" yaml:"creation_time"` // Block height at which the session has been created
Expiry int64 `json:"expiration_time,string" yaml:"expiration_time"` // Block height at which the session will expire
Expand Down
8 changes: 4 additions & 4 deletions x/magpie/types/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ func TestParseSessionID(t *testing.T) {
expErr bool
}{
{
name: "ID 0 is parsed correctly",
name: "RelationshipID 0 is parsed correctly",
string: "0",
expID: types.SessionID(0),
},
{
name: "Negative ID returns error",
name: "Negative RelationshipID returns error",
string: "-1",
expID: types.SessionID(0),
expErr: true,
},
{
name: "Positive ID is parsed correctly",
name: "Positive RelationshipID is parsed correctly",
string: "54624",
expID: types.SessionID(54624),
},
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestSession_Equals(t *testing.T) {
expEquals bool
}{
{
name: "Different session ID",
name: "Different session RelationshipID",
first: types.Session{
SessionID: 0,
Owner: owner,
Expand Down
2 changes: 1 addition & 1 deletion x/posts/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ E.g.
}

cmd.Flags().Bool(flagAllowsComments, true, "Possibility to comment the post or not")
cmd.Flags().String(flagParentID, "", "Id of the post to which this one should be an answer to")
cmd.Flags().String(flagParentID, "", "ID of the post to which this one should be an answer to")
cmd.Flags().StringArray(flagAttachment, []string{}, "Current post's attachment")
cmd.Flags().StringToString(flagPollDetails, map[string]string{}, "Current post's poll details")
cmd.Flags().StringSlice(flagPollAnswer, []string{}, "Current post's poll answer")
Expand Down
2 changes: 1 addition & 1 deletion x/posts/legacy/v0.1.0/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ type Post struct {
// Reaction is a struct of a user like
type Like struct {
Created sdk.Int `json:"created"` // Block height at which the like was created
Owner sdk.AccAddress `json:"owner"` // User that has inserted the like
Owner sdk.AccAddress `json:"owner"` // Sender that has inserted the like
}
2 changes: 1 addition & 1 deletion x/posts/legacy/v0.2.0/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ func (p Post) ContentsEquals(other Post) bool {

// Reaction is a struct of a user reaction to a post
type Reaction struct {
Owner sdk.AccAddress `json:"owner"` // User that has created the reaction
Owner sdk.AccAddress `json:"owner"` // Sender that has created the reaction
Value string `json:"value"` // Value of the reaction
}
2 changes: 1 addition & 1 deletion x/posts/legacy/v0.3.0/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type Post struct {

// Reaction is a struct of a user reaction to a post
type Reaction struct {
Owner sdk.AccAddress `json:"owner"` // User that has created the reaction
Owner sdk.AccAddress `json:"owner"` // Sender that has created the reaction
Value string `json:"value"` // Value of the reaction
}

Expand Down
Loading