Skip to content

Commit

Permalink
Migration and genesis validation fixes
Browse files Browse the repository at this point in the history
See PR #340
  • Loading branch information
RiccardoM authored Jan 14, 2021
1 parent 23bd4ca commit 1fcdb0b
Show file tree
Hide file tree
Showing 67 changed files with 661 additions and 784 deletions.
5 changes: 1 addition & 4 deletions proto/desmos/fees/v1beta1/min_fee.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ option go_package = "github.com/desmos-labs/desmos/x/fees/types";
// MinFee contains the minimum amount of coins that should be paid as a fee for
// each message of the specific type sent
message MinFee {
string message_type = 1 [
(gogoproto.jsontag) = "message_type",
(gogoproto.moretags) = "yaml:\"message_type\""
];
string message_type = 1 [(gogoproto.moretags) = "yaml:\"message_type\""];

repeated cosmos.base.v1beta1.Coin amount = 2 [
(gogoproto.nullable) = false,
Expand Down
1 change: 0 additions & 1 deletion proto/desmos/fees/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ option go_package = "github.com/desmos-labs/desmos/x/fees/types";
message Params {
repeated desmos.fees.v1beta1.MinFee min_fees = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "min_fees",
(gogoproto.moretags) = "yaml:\"min_fees\""
];
}
5 changes: 0 additions & 5 deletions proto/desmos/posts/v1beta1/msgs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ message MsgCreatePost {
option (gogoproto.goproto_getters) = false;

string parent_id = 1 [
(gogoproto.customname) = "ParentID",
(gogoproto.moretags) = "yaml:\"parent_id\"",
(gogoproto.jsontag) = "parent_id"
];
Expand Down Expand Up @@ -84,7 +83,6 @@ message MsgEditPost {
option (gogoproto.goproto_getters) = false;

string post_id = 1 [
(gogoproto.customname) = "PostID",
(gogoproto.moretags) = "yaml:\"post_id\"",
(gogoproto.jsontag) = "post_id"
];
Expand Down Expand Up @@ -117,7 +115,6 @@ message MsgAddPostReaction {
option (gogoproto.goproto_getters) = false;

string post_id = 1 [
(gogoproto.customname) = "PostID",
(gogoproto.moretags) = "yaml:\"post_id\"",
(gogoproto.jsontag) = "post_id"
];
Expand All @@ -139,7 +136,6 @@ message MsgRemovePostReaction {
option (gogoproto.goproto_getters) = false;

string post_id = 1 [
(gogoproto.customname) = "PostID",
(gogoproto.moretags) = "yaml:\"post_id\"",
(gogoproto.jsontag) = "post_id"
];
Expand All @@ -161,7 +157,6 @@ message MsgAnswerPoll {
option (gogoproto.goproto_getters) = false;

string post_id = 1 [
(gogoproto.customname) = "PostID",
(gogoproto.moretags) = "yaml:\"post_id\"",
(gogoproto.jsontag) = "post_id"
];
Expand Down
8 changes: 2 additions & 6 deletions proto/desmos/posts/v1beta1/posts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ message Post {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;

string post_id = 1 [
(gogoproto.customname) = "PostID",
(gogoproto.jsontag) = "id",
(gogoproto.moretags) = "yaml:\"id\""
];
string post_id = 1
[(gogoproto.jsontag) = "id", (gogoproto.moretags) = "yaml:\"id\""];
string parent_id = 2 [
(gogoproto.customname) = "ParentID",
(gogoproto.jsontag) = "parent_id",
(gogoproto.moretags) = "yaml:\"parent_id\""
];
Expand Down
8 changes: 4 additions & 4 deletions proto/desmos/posts/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ message QueryPostsParams {
string sort_by = 3;
string sort_order = 4;

string parent_id = 5 [ (gogoproto.customname) = "ParentID" ];
google.protobuf.Timestamp creation_time = 6 [ (gogoproto.stdtime) = true ];
string parent_id = 5;
google.protobuf.Timestamp creation_time = 6 [(gogoproto.stdtime) = true];
string subspace = 7;
string creator = 8;
repeated string hashtags = 9;
Expand All @@ -67,8 +67,8 @@ message QueryPostsRequest {
string sort_by = 1;
string sort_order = 2;

string parent_id = 3 [ (gogoproto.customname) = "ParentID" ];
google.protobuf.Timestamp creation_time = 4 [ (gogoproto.stdtime) = true ];
string parent_id = 3;
google.protobuf.Timestamp creation_time = 4 [(gogoproto.stdtime) = true];
string subspace = 5;
string creator = 6;
repeated string hashtags = 7;
Expand Down
30 changes: 15 additions & 15 deletions x/fees/types/min_fee.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions x/fees/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions x/genutil/client/cli/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ const chainUpgradeGuide = "https://docs.cosmos.network/master/migrations/chain-u
// a version of the chain to the next one. It contains an array as we need to support Cosmos SDK migrations
// too if needed.
var migrationMap = map[string]genutiltypes.MigrationCallback{
"v0.13.0": v0130.Migrate,
"stargate": v0150.Migrate,
"v0.13.0": v0130.Migrate,
"v0.15.0": v0150.Migrate,
}

const (
flagGenesisTime = "genesis-time"
flagChainID = "chain-id"
flagBlockInterval = "block-interval"
flagGenesisTime = "genesis-time"
flagChainID = "chain-id"
)

// GetMigrationCallback returns a MigrationCallback for a given version.
Expand Down Expand Up @@ -171,7 +170,6 @@ $ %s migrate v0.2.0 /path/to/genesis.json --chain-id=morpheus-XXXXX --genesis-ti

cmd.Flags().String(flagGenesisTime, "", "Override genesis_time with this flag")
cmd.Flags().String(flagChainID, "", "Override chain_id with this flag")
cmd.Flags().Int(flagBlockInterval, 0, "Block interval of seconds to consider while computing timestamps dates")

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions x/genutil/legacy/v0.13.0/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func verifyPostsStateMigrated(
}

func verifyMigratedPost(t *testing.T, original v0120posts.Post, migrated v0130posts.Post) {
require.Equal(t, original.PostID, migrated.PostID)
require.Equal(t, original.ParentID, migrated.ParentID)
require.Equal(t, original.PostId, migrated.PostId)
require.Equal(t, original.ParentId, migrated.ParentId)
require.Equal(t, original.Message, migrated.Message)
require.True(t, original.Created.Equal(migrated.Created))
require.True(t, original.LastEdited.Equal(migrated.LastEdited))
Expand Down
7 changes: 6 additions & 1 deletion x/genutil/legacy/v0.15.0/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
v040 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v040"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

v0150fees "github.com/desmos-labs/desmos/x/fees/types"

v0120posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.12.0"

v0130posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.13.0"
Expand Down Expand Up @@ -60,7 +62,10 @@ func Migrate(appState genutiltypes.AppMap, cliCtx client.Context) genutiltypes.A
appState[v0150reports.ModuleName] = v0150Codec.MustMarshalJSON(v0150reports.Migrate(genDocs))
}

// TODO: Add fees module, maybe?
// Add fees if non existing
if appState[v0150fees.ModuleName] == nil {
appState[v0150fees.ModuleName] = v0150Codec.MustMarshalJSON(v0150fees.DefaultGenesisState())
}

return appState
}
16 changes: 8 additions & 8 deletions x/genutil/legacy/v0.15.0/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func verifyPostsStateMigrated(

// Make sure the poll answers are migrated properly
for postID, originalValue := range original.UsersPollAnswers {
found, migratedEntry := migrated.FindUserAnswerEntryForPostID(postID)
found, migratedEntry := v0150posts.FindUserAnswerEntryForPostID(migrated, postID)
require.True(t, found)

for index, original := range originalValue {
Expand All @@ -124,9 +124,9 @@ func verifyPostsStateMigrated(
}

// Make sure the post reactions are migrated properly
require.Len(t, migrated.PostReactions, len(original.PostReactions))
require.Len(t, migrated.PostsReactions, len(original.PostReactions))
for postID, originalValue := range original.PostReactions {
found, migratedEntry := migrated.FindPostReactionEntryForPostID(postID)
found, migratedEntry := v0150posts.FindPostReactionEntryForPostID(migrated, postID)
require.True(t, found)

for index, original := range originalValue {
Expand All @@ -147,8 +147,8 @@ func verifyPostsStateMigrated(
}

func verifyMigratedPost(t *testing.T, original v0130posts.Post, migrated v0150posts.Post) {
require.Equal(t, original.PostID, migrated.PostID)
require.Equal(t, original.ParentID, migrated.ParentID)
require.Equal(t, original.PostId, migrated.PostId)
require.Equal(t, original.ParentId, migrated.ParentId)
require.Equal(t, original.Message, migrated.Message)
require.True(t, original.Created.Equal(migrated.Created))
require.True(t, original.LastEdited.Equal(migrated.LastEdited))
Expand Down Expand Up @@ -310,7 +310,7 @@ func verifyRelationshipsStateMigrated(
t *testing.T, original v0130relationships.GenesisState, migrated v0150relationships.GenesisState,
) {
for user, originalRelationships := range original.UsersRelationships {
migratedRelationships := migrated.FindRelationshipsForUser(user)
migratedRelationships := v0150relationships.FindRelationshipsForUser(migrated, user)

require.Len(t, migratedRelationships, len(originalRelationships))
for index, originalRelationship := range originalRelationships {
Expand Down Expand Up @@ -345,7 +345,7 @@ func verifyReportsStateMigrated(
t *testing.T, original v0130reports.GenesisState, migrated v0150reports.GenesisState,
) {
for postID, originalReports := range original.Reports {
migratedReports := migrated.FindReportsForPostWithID(postID)
migratedReports := v0150reports.FindReportsForPostWithID(migrated, postID)

require.Len(t, migratedReports, len(originalReports))
for index, originalReport := range originalReports {
Expand All @@ -356,7 +356,7 @@ func verifyReportsStateMigrated(
}

func verifyMigratedReport(t *testing.T, postID string, original v0130reports.Report, migrated v0150reports.Report) {
require.Equal(t, postID, migrated.PostID)
require.Equal(t, postID, migrated.PostId)
require.Equal(t, original.Type, migrated.Type)
require.Equal(t, original.Message, migrated.Message)
require.Equal(t, original.User.String(), migrated.User)
Expand Down
6 changes: 3 additions & 3 deletions x/posts/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
}
postsData.Posts = []types.Post{
{
PostID: "19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
PostId: "19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
Message: "Post message",
Created: creationDate,
LastEdited: creationDate.Add(1),
Expand Down Expand Up @@ -154,7 +154,7 @@ func (s *IntegrationTestSuite) TestCmdQueryPost() {
expectErr: false,
expectedOutput: types.QueryPostResponse{
Post: types.Post{
PostID: "19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
PostId: "19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
Message: "Post message",
Created: creationDate,
LastEdited: creationDate.Add(1),
Expand Down Expand Up @@ -245,7 +245,7 @@ func (s *IntegrationTestSuite) TestCmdQueryPosts() {
Posts: []types.QueryPostResponse{
{
Post: types.Post{
PostID: "19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
PostId: "19de02e105c68a60e45c289bff19fde745bca9c63c38f2095b59e8e8090ae1af",
Message: "Post message",
Created: creationDate,
LastEdited: creationDate.Add(1),
Expand Down
2 changes: 1 addition & 1 deletion x/posts/client/cli/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func DefaultQueryPostsRequest(page, limit uint64) types.QueryPostsRequest {
SortBy: types.PostSortByCreationDate,
SortOrder: types.PostSortOrderAscending,

ParentID: "",
ParentId: "",
CreationTime: nil,
Subspace: "",
Creator: "",
Expand Down
2 changes: 1 addition & 1 deletion x/posts/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ $ %s query posts posts --page=2 --limit=100
if !types.IsValidPostID(idParent) {
return fmt.Errorf("invalid postID: %s", idParent)
}
params.ParentID = parentID
params.ParentId = parentID
}

// CreationTime
Expand Down
2 changes: 1 addition & 1 deletion x/posts/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func queryPostsWithParameterHandlerFn(cliCtx client.Context) http.HandlerFunc {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("invalid postID: %s", parentID))
return
}
params.ParentID = parentID
params.ParentId = parentID
}

if v := r.URL.Query().Get(ParamCreationTime); len(v) != 0 {
Expand Down
8 changes: 4 additions & 4 deletions x/posts/keeper/common_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k Keeper) IteratePosts(ctx sdk.Context, fn func(index int64, post types.Po
postsSorted := make([]types.Post, len(posts))
for _, post := range posts {
var index types.PostIndex
k.cdc.MustUnmarshalBinaryBare(store.Get(types.PostIndexedIDStoreKey(post.PostID)), &index)
k.cdc.MustUnmarshalBinaryBare(store.Get(types.PostIndexedIDStoreKey(post.PostId)), &index)
postsSorted[index.Value-1] = post
}

Expand All @@ -54,20 +54,20 @@ func (k Keeper) ValidatePost(ctx sdk.Context, post types.Post) error {

if int64(len(post.Message)) > maxMsgLen {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
fmt.Sprintf("post with id %s has more than %d characters", post.PostID, maxMsgLen))
fmt.Sprintf("post with id %s has more than %d characters", post.PostId, maxMsgLen))
}

if int64(len(post.OptionalData)) > maxOpFieldNum {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
fmt.Sprintf("post with id %s contains optional data with more than %d key-value pairs",
post.PostID, maxOpFieldNum))
post.PostId, maxOpFieldNum))
}

for _, optionalData := range post.OptionalData {
if int64(len(strings.TrimSpace(optionalData.Value))) > maxOpFieldValLen {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
fmt.Sprintf("post with id %s has optional data with key %s which value exceeds %d characters.",
post.PostID, optionalData.Key, maxOpFieldValLen))
post.PostId, optionalData.Key, maxOpFieldValLen))
}
}

Expand Down
Loading

0 comments on commit 1fcdb0b

Please sign in to comment.