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 36 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
24 changes: 19 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/desmos-labs/desmos/x/relationships"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
Expand All @@ -40,6 +41,8 @@ import (
"github.com/desmos-labs/desmos/x/profiles"
profilesKeeper "github.com/desmos-labs/desmos/x/profiles/keeper"
profilesTypes "github.com/desmos-labs/desmos/x/profiles/types"
relationshipsKeeper "github.com/desmos-labs/desmos/x/relationships/keeper"
relationshipsTypes "github.com/desmos-labs/desmos/x/relationships/types"
"github.com/desmos-labs/desmos/x/reports"
reportsKeeper "github.com/desmos-labs/desmos/x/reports/keeper"
reportsTypes "github.com/desmos-labs/desmos/x/reports/types"
Expand Down Expand Up @@ -81,6 +84,7 @@ var (
posts.AppModuleBasic{},
profiles.AppModuleBasic{},
reports.AppModuleBasic{},
relationships.AppModuleBasic{},
)

// Module account permissions
Expand Down Expand Up @@ -141,10 +145,11 @@ type DesmosApp struct {
evidenceKeeper evidence.Keeper

// Custom modules
magpieKeeper magpieKeeper.Keeper
postsKeeper postsKeeper.Keeper
profileKeeper profilesKeeper.Keeper
reportsKeeper reportsKeeper.Keeper
magpieKeeper magpieKeeper.Keeper
postsKeeper postsKeeper.Keeper
profileKeeper profilesKeeper.Keeper
reportsKeeper reportsKeeper.Keeper
relationshipsKeeper relationships.Keeper

// Module Manager
mm *module.Manager
Expand All @@ -171,6 +176,7 @@ func NewDesmosApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest

// Custom modules
magpieTypes.StoreKey, postsTypes.StoreKey, profilesTypes.StoreKey, reportsTypes.StoreKey,
relationshipsTypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)

Expand Down Expand Up @@ -299,6 +305,11 @@ func NewDesmosApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
keys[reportsTypes.StoreKey],
)

app.relationshipsKeeper = relationshipsKeeper.NewKeeper(
app.cdc,
keys[relationshipsTypes.StoreKey],
)

// Register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.stakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -328,6 +339,7 @@ func NewDesmosApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
posts.NewAppModule(app.postsKeeper, app.AccountKeeper),
profiles.NewAppModule(app.profileKeeper, app.AccountKeeper),
reports.NewAppModule(app.reportsKeeper, app.AccountKeeper, app.postsKeeper),
relationships.NewAppModule(app.relationshipsKeeper, app.AccountKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -345,7 +357,8 @@ func NewDesmosApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
staking.ModuleName, bank.ModuleName, slashing.ModuleName,
gov.ModuleName, evidence.ModuleName,

magpieTypes.ModuleName, postsTypes.ModuleName, profilesTypes.ModuleName, reportsTypes.ModuleName, // custom modules
magpieTypes.ModuleName, postsTypes.ModuleName, profilesTypes.ModuleName, reportsTypes.ModuleName,
relationshipsTypes.ModuleName, // custom modules

supply.ModuleName, // calculates the total supply from account - should run after modules that modify accounts in genesis
crisis.ModuleName, // runs the invariants at genesis - should run after other modules
Expand Down Expand Up @@ -373,6 +386,7 @@ func NewDesmosApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
magpie.NewAppModule(app.magpieKeeper, app.AccountKeeper),
profiles.NewAppModule(app.profileKeeper, app.AccountKeeper),
reports.NewAppModule(app.reportsKeeper, app.AccountKeeper, app.postsKeeper),
relationships.NewAppModule(app.relationshipsKeeper, app.AccountKeeper),
)

app.sm.RegisterStoreDecoders()
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
)
2 changes: 2 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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"
relationshipsTypes "github.com/desmos-labs/desmos/x/relationships/types"
reportsTypes "github.com/desmos-labs/desmos/x/reports/types"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -194,6 +195,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[postsTypes.StoreKey], newApp.keys[postsTypes.StoreKey], [][]byte{}},
{app.keys[profilesTypes.StoreKey], newApp.keys[profilesTypes.StoreKey], [][]byte{}},
{app.keys[reportsTypes.StoreKey], newApp.keys[reportsTypes.StoreKey], [][]byte{}},
{app.keys[relationshipsTypes.StoreKey], newApp.keys[relationshipsTypes.StoreKey], [][]byte{}},
}

for _, skp := range storeKeysPrefixes {
Expand Down
123 changes: 123 additions & 0 deletions cli_test/cli_relationships_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// +build cli_test

//nolint
package clitest

import (
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/desmos-labs/desmos/x/relationships/types"
"github.com/stretchr/testify/require"
"testing"
)

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()
}
36 changes: 32 additions & 4 deletions cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ 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"
relationshipsTypes "github.com/desmos-labs/desmos/x/relationships/types"
reportsTypes "github.com/desmos-labs/desmos/x/reports/types"
)

Expand Down Expand Up @@ -454,7 +455,7 @@ func (f *Fixtures) TxPostsRegisterReaction(shortCode, value, subspace string, fr
}

//___________________________________________________________________________________
// desmoscli tx profile
// desmoscli tx profiles
func (f *Fixtures) TxProfileSave(dTag string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles save %s --keyring-backend=test --from=%s %v`,
f.DesmoscliBinary, dTag, from, f.Flags())
Expand All @@ -467,6 +468,20 @@ func (f *Fixtures) TxProfileDelete(from sdk.AccAddress, flags ...string) (bool,
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

//___________________________________________________________________________________
// desmoscli tx relationships
func (f *Fixtures) TxCreateMonoDirectionalRelationship(receiver, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx relationships create %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 relationships delete %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 +806,30 @@ 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) relationshipsTypes.RelationshipsResponse {
cmd := fmt.Sprintf("%s query relationships user_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 relationshipsTypes.RelationshipsResponse
err := cdc.UnmarshalJSON([]byte(res), &storedRelationships)
require.NoError(f.T, err)
return storedRelationships
}

//___________________________________________________________________________________
// query reports

Expand Down
38 changes: 38 additions & 0 deletions docs/developers/msgs/create-relationship.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# `MsgCreateMonoDirectionalRelationship`
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.

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.


## Structure
```json
{
"type": "desmos/MsgCreateMonoDirectionalRelationship",
"value": {
"sender": "<Desmos address that's creating the relationship>",
"receiver": "<Desmos address that's receiving the relationship>"
}
}
```

### Attributes
| Attribute | Type | Description |
| :-------: | :----: | :-------- |
| `sender` | String | Desmos address of the user that is creating the relationship |
| `receiver`| String | Desmos address of the relationship's recipient |

## Example
````json
{
"type": "desmos/MsgCreateMonoDirectionalRelationship",
"value": {
"sender": "desmos1e209r8nc8qdkmqujahwrq4xrlxhk3fs9k7yzmw",
"receiver": "desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud"
}
}
````

## Message action
The action associated to this message is the following:

```
create_relationship
```
Loading