-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See PR #277
- Loading branch information
Showing
50 changed files
with
67,574 additions
and
146,688 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package v0120 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
|
||
"github.com/desmos-labs/desmos/x/relationships" | ||
relationshipsTypes "github.com/desmos-labs/desmos/x/relationships/types" | ||
|
||
v0100posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.10.0" | ||
v0120posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.12.0" | ||
v060posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.6.0" | ||
) | ||
|
||
// Migrate migrates exported state from v0.10.0 to a v0.12.0 genesis state. | ||
func Migrate(appState genutil.AppMap, values ...interface{}) genutil.AppMap { | ||
v0100Codec := codec.New() | ||
codec.RegisterCrypto(v0100Codec) | ||
|
||
v0120Codec := codec.New() | ||
codec.RegisterCrypto(v0120Codec) | ||
|
||
// Migrate posts state | ||
if appState[v060posts.ModuleName] != nil { | ||
var genDocs v0100posts.GenesisState | ||
v0120Codec.MustUnmarshalJSON(appState[v060posts.ModuleName], &genDocs) | ||
|
||
appState[v060posts.ModuleName] = v0120Codec.MustMarshalJSON( | ||
v0120posts.Migrate(genDocs), | ||
) | ||
} | ||
|
||
// Add the relationships default state | ||
if appState[relationships.ModuleName] == nil { | ||
appState[relationships.ModuleName] = v0120Codec.MustMarshalJSON( | ||
relationshipsTypes.DefaultGenesisState(), | ||
) | ||
} | ||
|
||
return appState | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package v0120_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
"github.com/stretchr/testify/require" | ||
tm "github.com/tendermint/tendermint/types" | ||
|
||
v0120 "github.com/desmos-labs/desmos/x/genutil/legacy/v0.12.0" | ||
v0100posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.10.0" | ||
v0120posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.12.0" | ||
v060posts "github.com/desmos-labs/desmos/x/posts/legacy/v0.6.0" | ||
"github.com/desmos-labs/desmos/x/relationships" | ||
) | ||
|
||
func TestMigrate0100(t *testing.T) { | ||
cdc := codec.New() | ||
codec.RegisterCrypto(cdc) | ||
|
||
config := sdk.GetConfig() | ||
config.SetBech32PrefixForAccount("desmos", "desmos"+sdk.PrefixPublic) | ||
config.Seal() | ||
|
||
// Read the genesis | ||
genesis, err := tm.GenesisDocFromFile("v0100state.json") | ||
require.NoError(t, err) | ||
|
||
// Read the whole app state | ||
var v010state genutil.AppMap | ||
err = cdc.UnmarshalJSON(genesis.AppState, &v010state) | ||
require.NoError(t, err) | ||
|
||
// Migrate everything | ||
v0120state := v0120.Migrate(v010state) | ||
|
||
// Make sure that all the posts are migrated | ||
var v010postsState v0100posts.GenesisState | ||
err = cdc.UnmarshalJSON(v010state[v060posts.ModuleName], &v010postsState) | ||
|
||
var v0120postsState v0120posts.GenesisState | ||
err = cdc.UnmarshalJSON(v0120state[v060posts.ModuleName], &v0120postsState) | ||
require.Equal(t, len(v0120postsState.Posts), len(v010postsState.Posts)) | ||
|
||
// Make sure that all the posts' polls are migrated correctly | ||
for index, post := range v010postsState.Posts { | ||
if post.PollData == nil { | ||
require.Nil(t, v010postsState.Posts[index].PollData) | ||
} else { | ||
require.NotNil(t, v010postsState.Posts[index].PollData) | ||
} | ||
} | ||
|
||
// Make sure the relationships genesis state is not nil | ||
require.NotNil(t, v0120state[relationships.ModuleName]) | ||
} |
Oops, something went wrong.