Skip to content

Commit

Permalink
feat: ADR-010: Posts module (#847)
Browse files Browse the repository at this point in the history
## Description

This PR implements the `x/posts` module as per ADR-010.

Implementation checklist
- [x] Types
- [x] Keeper
- [x] CLI
- [x] Simulation tests
- [x] Invariants
- [ ] `spec` folder



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [ ] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [x] confirmed all author checklist items have been addressed
- [x] reviewed state machine logic
- [x] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [x] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
RiccardoM authored May 26, 2022
1 parent d28eca1 commit a091bdd
Show file tree
Hide file tree
Showing 84 changed files with 34,710 additions and 2,955 deletions.
6 changes: 4 additions & 2 deletions .changeset/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ types:
modules:
- id: x/profiles
description: Profiles
- id: x/subspaces
description: Subspaces
- id: x/relationships
description: Relationships
- id: x/subspaces
description: Subspaces
- id: x/posts
description: Posts
- id: x/fees
description: Fees
- id: x/supply
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: x/posts
pull_request: 847
description: Added the new x/posts module
backward_compatible: false
date: 2022-05-13T11:12:11.336881249Z
44 changes: 31 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import (
"path/filepath"
"strings"

postskeeper "github.com/desmos-labs/desmos/v3/x/posts/keeper"
poststypes "github.com/desmos-labs/desmos/v3/x/posts/types"

"github.com/desmos-labs/desmos/v3/app/upgrades"
v300 "github.com/desmos-labs/desmos/v3/app/upgrades/v300"
v310 "github.com/desmos-labs/desmos/v3/app/upgrades/v310"

profilesv4 "github.com/desmos-labs/desmos/v3/x/profiles/legacy/v4"

"github.com/cosmos/cosmos-sdk/version"

"github.com/desmos-labs/desmos/v3/x/posts"
"github.com/desmos-labs/desmos/v3/x/relationships"
relationshipstypes "github.com/desmos-labs/desmos/v3/x/relationships/types"

"github.com/cosmos/cosmos-sdk/version"

"github.com/desmos-labs/desmos/v3/x/fees"
feeskeeper "github.com/desmos-labs/desmos/v3/x/fees/keeper"
feestypes "github.com/desmos-labs/desmos/v3/x/fees/types"
Expand Down Expand Up @@ -233,6 +237,7 @@ var (
profiles.AppModuleBasic{},
relationships.AppModuleBasic{},
subspaces.AppModuleBasic{},
posts.AppModuleBasic{},
fees.AppModuleBasic{},
supply.AppModuleBasic{},
)
Expand Down Expand Up @@ -298,6 +303,7 @@ type DesmosApp struct {
SubspacesKeeper subspaceskeeper.Keeper
ProfileKeeper profileskeeper.Keeper
RelationshipsKeeper relationshipskeeper.Keeper
PostsKeeper postskeeper.Keeper
SupplyKeeper supplykeeper.Keeper

// Module Manager
Expand Down Expand Up @@ -346,6 +352,7 @@ func NewDesmosApp(

// Custom modules
profilestypes.StoreKey, relationshipstypes.StoreKey, subspacestypes.StoreKey,
poststypes.StoreKey,
feestypes.StoreKey, supplytypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -469,10 +476,22 @@ func NewDesmosApp(
app.FeesKeeper,
)

// Create posts keeper and module
app.PostsKeeper = postskeeper.NewKeeper(
app.appCodec,
keys[poststypes.StoreKey],
app.GetSubspace(poststypes.ModuleName),
&subspacesKeeper,
app.RelationshipsKeeper,
)

// Register the subspaces hooks
// NOTE: subspacesKeeper above is passed by reference, so that it will contain these hooks
app.SubspacesKeeper = *subspacesKeeper.SetHooks(
subspacestypes.NewMultiSubspacesHooks(app.RelationshipsKeeper.Hooks()),
subspacestypes.NewMultiSubspacesHooks(
app.RelationshipsKeeper.Hooks(),
app.PostsKeeper.Hooks(),
),
)

app.SupplyKeeper = supplykeeper.NewKeeper(app.appCodec, app.AccountKeeper, app.BankKeeper, app.DistrKeeper)
Expand Down Expand Up @@ -576,11 +595,8 @@ func NewDesmosApp(
fees.NewAppModule(app.appCodec, app.FeesKeeper),
subspaces.NewAppModule(appCodec, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
profilesModule,
relationships.NewAppModule(
appCodec, app.RelationshipsKeeper, app.SubspacesKeeper,
profilesv4.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper,
app.BankKeeper, app.FeesKeeper,
),
relationships.NewAppModule(appCodec, app.RelationshipsKeeper, app.SubspacesKeeper, profilesv4.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
posts.NewAppModule(appCodec, app.PostsKeeper, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
supply.NewAppModule(appCodec, legacyAmino, app.SupplyKeeper),
)

Expand Down Expand Up @@ -614,6 +630,7 @@ func NewDesmosApp(
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
supplytypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -641,6 +658,7 @@ func NewDesmosApp(
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
supplytypes.ModuleName,
)

Expand Down Expand Up @@ -675,6 +693,7 @@ func NewDesmosApp(
subspacestypes.ModuleName,
profilestypes.ModuleName,
relationshipstypes.ModuleName,
poststypes.ModuleName,
supplytypes.ModuleName,

crisistypes.ModuleName,
Expand Down Expand Up @@ -708,6 +727,7 @@ func NewDesmosApp(
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
supplytypes.ModuleName,

crisistypes.ModuleName,
Expand Down Expand Up @@ -749,11 +769,8 @@ func NewDesmosApp(
supply.NewAppModule(appCodec, legacyAmino, app.SupplyKeeper),
subspaces.NewAppModule(appCodec, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
profilesModule,
relationships.NewAppModule(
appCodec, app.RelationshipsKeeper, app.SubspacesKeeper,
profilesv4.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper,
app.BankKeeper, app.FeesKeeper,
),
relationships.NewAppModule(appCodec, app.RelationshipsKeeper, app.SubspacesKeeper, profilesv4.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
posts.NewAppModule(appCodec, app.PostsKeeper, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -1005,6 +1022,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(feestypes.ModuleName)
paramsKeeper.Subspace(subspacestypes.ModuleName)
paramsKeeper.Subspace(profilestypes.ModuleName)
paramsKeeper.Subspace(poststypes.ModuleName)

return paramsKeeper
}
7 changes: 7 additions & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ const (
DefaultWeightMsgAddUserToUserGroup int = 7
DefaultWeightMsgRemoveUserFromUserGroup int = 3
DefaultWeightMsgSetUserPermissions int = 85

DefaultWeightMsgCreatePost int = 80
DefaultWeightMsgEditPost int = 40
DefaultWeightMsgDeletePost int = 20
DefaultWeightMsgAddPostAttachment int = 50
DefaultWeightMsgRemovePostAttachment int = 50
DefaultWeightMsgAnswerPoll int = 50
)
3 changes: 3 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"path/filepath"
"testing"

poststypes "github.com/desmos-labs/desmos/v3/x/posts/types"

feestypes "github.com/desmos-labs/desmos/v3/x/fees/types"

relationshipstypes "github.com/desmos-labs/desmos/v3/x/relationships/types"
Expand Down Expand Up @@ -235,6 +237,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[subspacestypes.StoreKey], newApp.keys[subspacestypes.StoreKey], [][]byte{}},
{app.keys[profilestypes.StoreKey], newApp.keys[profilestypes.StoreKey], [][]byte{}},
{app.keys[relationshipstypes.StoreKey], newApp.keys[relationshipstypes.StoreKey], [][]byte{}},
{app.keys[poststypes.StoreKey], newApp.keys[poststypes.StoreKey], [][]byte{}},
}

for _, skp := range storeKeysPrefixes {
Expand Down
8 changes: 8 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
{
"url": "./tmp-swagger-gen/desmos/subspaces/v1/query.swagger.json"
},
{
"url": "./tmp-swagger-gen/desmos/posts/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "PostsParams"
}
}
},
{
"url": "./tmp-swagger-gen/desmos/fees/v1/query.swagger.json",
"operationIds": {
Expand Down
Loading

0 comments on commit a091bdd

Please sign in to comment.