Skip to content

Commit

Permalink
Migrate pieces of x/genutil missed in #6734 (#6860)
Browse files Browse the repository at this point in the history
* Migrate pieces of x/genutil missed in 6734

* Fix tests

* Fix lint

* Add test
  • Loading branch information
aaronc authored Jul 27, 2020
1 parent 359e9a0 commit bb8aabd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
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

0 comments on commit bb8aabd

Please sign in to comment.