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

Migrate pieces of x/genutil missed in #6734 #6860

Merged
merged 4 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions x/auth/tx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func newBuilder(pubkeyCodec types.PublicKeyCodec) *builder {
}

func (t *builder) GetMsgs() []sdk.Msg {
if t.tx == nil || t.tx.Body == nil {
return nil
}

anys := t.tx.Body.Messages
res := make([]sdk.Msg, len(anys))
for i, any := range anys {
Expand Down
5 changes: 5 additions & 0 deletions x/auth/tx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func TestTxBuilder(t *testing.T) {
require.Equal(t, len(msgs), len(tx.GetMsgs()))
require.Equal(t, 1, len(tx.GetPubKeys()))
require.Equal(t, pubkey.Bytes(), tx.GetPubKeys()[0].Bytes())

tx = &builder{}
require.NotPanics(t, func() {
_ = tx.GetMsgs()
})
}

func TestBuilderValidateBasic(t *testing.T) {
Expand Down
23 changes: 0 additions & 23 deletions x/genutil/types/codec.go

This file was deleted.

8 changes: 6 additions & 2 deletions x/genutil/types/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ func DefaultGenesisState() GenesisState {

// NewGenesisStateFromTx creates a new GenesisState object
// from auth transactions
func NewGenesisStateFromTx(genTxs []sdk.Tx) GenesisState {
func NewGenesisStateFromTx(txJSONEncoder sdk.TxEncoder, genTxs []sdk.Tx) GenesisState {
genTxsBz := make([]json.RawMessage, len(genTxs))
for i, genTx := range genTxs {
genTxsBz[i] = ModuleCdc.MustMarshalJSON(genTx)
var err error
genTxsBz[i], err = txJSONEncoder(genTx)
if err != nil {
panic(err)
}
}
return NewGenesisState(genTxsBz)
}
Expand Down
9 changes: 4 additions & 5 deletions x/genutil/types/genesis_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/tendermint/tendermint/crypto/ed25519"

"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -42,13 +41,13 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
msg2 := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk2.Address()), pk2,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt())

txGen := params.MakeEncodingConfig().TxConfig
txGen := simapp.MakeEncodingConfig().TxConfig
txBuilder := txGen.NewTxBuilder()
err := txBuilder.SetMsgs(msg1, msg2)
require.NoError(t, err)

tx := txBuilder.GetTx()
genesisState := types.NewGenesisStateFromTx([]sdk.Tx{tx})
genesisState := types.NewGenesisStateFromTx(txGen.TxJSONEncoder(), []sdk.Tx{tx})

err = types.ValidateGenesis(genesisState, simapp.MakeEncodingConfig().TxConfig.TxJSONDecoder())
require.Error(t, err)
Expand All @@ -59,13 +58,13 @@ func TestValidateGenesisBadMessage(t *testing.T) {

msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()), desc, nil, nil)

txGen := params.MakeEncodingConfig().TxConfig
txGen := simapp.MakeEncodingConfig().TxConfig
txBuilder := txGen.NewTxBuilder()
err := txBuilder.SetMsgs(msg1)
require.NoError(t, err)

tx := txBuilder.GetTx()
genesisState := types.NewGenesisStateFromTx([]sdk.Tx{tx})
genesisState := types.NewGenesisStateFromTx(txGen.TxJSONEncoder(), []sdk.Tx{tx})

err = types.ValidateGenesis(genesisState, simapp.MakeEncodingConfig().TxConfig.TxJSONDecoder())
require.Error(t, err)
Expand Down