better init test

This commit is contained in:
rigelrozanski
2018-04-26 14:26:39 -04:00
parent 05c5809bae
commit ade42e74b7
4 changed files with 125 additions and 79 deletions
+38 -36
View File
@@ -58,7 +58,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
return err
}
nodeID := string(nodeKey.ID())
pubKey := ReadOrCreatePrivValidator(config)
pubKey := readOrCreatePrivValidator(config)
appGenTx, cliPrint, validator, err := appInit.AppGenTx(cdc, pubKey)
if err != nil {
@@ -126,7 +126,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
return err
}
nodeID := string(nodeKey.ID())
pubKey := ReadOrCreatePrivValidator(config)
pubKey := readOrCreatePrivValidator(config)
chainID := viper.GetString(flagChainID)
if chainID == "" {
@@ -247,7 +247,7 @@ func processGenTxs(genTxsDir string, cdc *wire.Codec, appInit AppInit) (
//________________________________________________________________________________________
// read of create the private key file for this config
func ReadOrCreatePrivValidator(tmConfig *cfg.Config) crypto.PubKey {
func readOrCreatePrivValidator(tmConfig *cfg.Config) crypto.PubKey {
// private validator
privValFile := tmConfig.PrivValidatorFile()
var privValidator *pvm.FilePV
@@ -297,21 +297,21 @@ type AppInit struct {
FlagsAppGenState *pflag.FlagSet
FlagsAppGenTx *pflag.FlagSet
// AppGenState creates the core parameters initialization. It takes in a
// pubkey meant to represent the pubkey of the validator of this machine.
AppGenState func(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error)
// create the application genesis tx
AppGenTx func(cdc *wire.Codec, pk crypto.PubKey) (
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error)
// AppGenState creates the core parameters initialization. It takes in a
// pubkey meant to represent the pubkey of the validator of this machine.
AppGenState func(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error)
}
//_____________________________________________________________________
// simple default application init
var DefaultAppInit = AppInit{
AppGenState: SimpleAppGenState,
AppGenTx: SimpleAppGenTx,
AppGenState: SimpleAppGenState,
}
// simple genesis tx
@@ -319,34 +319,6 @@ type SimpleGenTx struct {
Addr sdk.Address `json:"addr"`
}
// create the genesis app state
func SimpleAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) {
if len(appGenTxs) != 1 {
err = errors.New("must provide a single genesis transaction")
return
}
var genTx SimpleGenTx
err = cdc.UnmarshalJSON(appGenTxs[0], &genTx)
if err != nil {
return
}
appState = json.RawMessage(fmt.Sprintf(`{
"accounts": [{
"address": "%s",
"coins": [
{
"denom": "mycoin",
"amount": 9007199254740992
}
]
}]
}`, genTx.Addr.String()))
return
}
// Generate a genesis transaction
func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey) (
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
@@ -380,6 +352,36 @@ func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey) (
return
}
// create the genesis app state
func SimpleAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) {
if len(appGenTxs) != 1 {
err = errors.New("must provide a single genesis transaction")
return
}
var genTx SimpleGenTx
err = cdc.UnmarshalJSON(appGenTxs[0], &genTx)
if err != nil {
return
}
appState = json.RawMessage(fmt.Sprintf(`{
"accounts": [{
"address": "%s",
"coins": [
{
"denom": "mycoin",
"amount": 9007199254740992
}
]
}]
}`, genTx.Addr.String()))
return
}
//___________________________________________________________________________________________
// GenerateCoinKey returns the address of a public key, along with the secret
// phrase to recover the private key.
func GenerateCoinKey() (sdk.Address, string, error) {
+14 -1
View File
@@ -12,7 +12,8 @@ import (
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
)
func TestInit(t *testing.T) {
// TODO update
func TestInitCmd(t *testing.T) {
defer setupViper(t)()
logger := log.NewNopLogger()
@@ -28,3 +29,15 @@ func TestInit(t *testing.T) {
err = cmd.RunE(nil, nil)
require.NoError(t, err)
}
func TestGenTxCmd(t *testing.T) {
// TODO
}
func TestSimpleAppGenTx(t *testing.T) {
// TODO
}
func TestSimpleAppGenState(t *testing.T) {
// TODO
}