Merge branch 'develop' of https://github.com/cosmos/cosmos-sdk into fedekunze/2819-fix-tx-search

Merge develop
This commit is contained in:
Federico Kunze 2018-11-16 16:06:12 +01:00
commit f42363b326
5 changed files with 72 additions and 6 deletions

View File

@ -8,6 +8,8 @@ BREAKING CHANGES
* [cli] [\#2728](https://github.com/cosmos/cosmos-sdk/pull/2728) Seperate `tx` and `query` subcommands by module
* [cli] [\#2727](https://github.com/cosmos/cosmos-sdk/pull/2727) Fix unbonding command flow
* [cli] [\#2786](https://github.com/cosmos/cosmos-sdk/pull/2786) Fix redelegation command flow
* [cli] [\#2829](https://github.com/cosmos/cosmos-sdk/pull/2829) add-genesis-account command now validates state when adding accounts
* [cli] [\#2804](https://github.com/cosmos/cosmos-sdk/issues/2804) Check whether key exists before passing it on to `tx create-validator`.
* Gaia

View File

@ -1,6 +1,7 @@
package init
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
@ -48,11 +49,7 @@ func AddGenesisAccountCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command
return err
}
acc := auth.NewBaseAccountWithAddress(addr)
acc.Coins = coins
appState.Accounts = append(appState.Accounts, app.NewGenesisAccount(&acc))
appStateJSON, err := cdc.MarshalJSON(appState)
appStateJSON, err := addGenesisAccount(cdc, appState, addr, coins)
if err != nil {
return err
}
@ -64,3 +61,16 @@ func AddGenesisAccountCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command
cmd.Flags().String(cli.HomeFlag, app.DefaultNodeHome, "node's home directory")
return cmd
}
func addGenesisAccount(cdc *codec.Codec, appState app.GenesisState, addr sdk.AccAddress, coins sdk.Coins) (json.RawMessage, error) {
for _, stateAcc := range appState.Accounts {
if stateAcc.Address.Equals(addr) {
return nil, fmt.Errorf("the application state already contains account %v", addr)
}
}
acc := auth.NewBaseAccountWithAddress(addr)
acc.Coins = coins
appState.Accounts = append(appState.Accounts, app.NewGenesisAccount(&acc))
return cdc.MarshalJSON(appState)
}

View File

@ -0,0 +1,45 @@
package init
import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/secp256k1"
"testing"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func TestAddGenesisAccount(t *testing.T) {
cdc := codec.New()
addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
type args struct {
appState app.GenesisState
addr sdk.AccAddress
coins sdk.Coins
}
tests := []struct {
name string
args args
wantErr bool
}{
{
"valid account",
args{
app.GenesisState{},
addr1,
sdk.Coins{},
},
false},
{"dup account", args{
app.GenesisState{Accounts: []app.GenesisAccount{app.GenesisAccount{Address:addr1}}},
addr1,
sdk.Coins{}}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := addGenesisAccount(cdc, tt.args.appState, tt.args.addr, tt.args.coins)
require.Equal(t, tt.wantErr, (err != nil))
})
}
}

View File

@ -3,6 +3,7 @@ package init
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
@ -61,6 +62,14 @@ following delegation and commission default parameters:
return err
}
kb, err := keys.GetKeyBaseFromDir(viper.GetString(flagClientHome))
if err != nil {
return err
}
if _, err = kb.Get(viper.GetString(client.FlagName)); err != nil {
return err
}
// Read --pubkey, if empty take it from priv_validator.json
if valPubKeyString := viper.GetString(cli.FlagPubKey); valPubKeyString != "" {
valPubKey, err = sdk.GetConsPubKeyBech32(valPubKeyString)

View File

@ -34,7 +34,7 @@ To install the latest version of the `gaia` application and join the public test
## Contribute
See [this file](./DOCS_README.md) for details of the build process and
See [this file](https://github.com/cosmos/cosmos-sdk/blob/master/docs/DOCS_README.md) for details of the build process and
considerations when making changes.
## Version