better init test
This commit is contained in:
parent
05c5809bae
commit
ade42e74b7
|
@ -65,8 +65,8 @@ func GaiaAppInit() server.AppInit {
|
||||||
return server.AppInit{
|
return server.AppInit{
|
||||||
FlagsAppGenState: fsAppGenState,
|
FlagsAppGenState: fsAppGenState,
|
||||||
FlagsAppGenTx: fsAppGenTx,
|
FlagsAppGenTx: fsAppGenTx,
|
||||||
AppGenState: GaiaAppGenState,
|
|
||||||
AppGenTx: GaiaAppGenTx,
|
AppGenTx: GaiaAppGenTx,
|
||||||
|
AppGenState: GaiaAppGenState,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,45 @@ type GaiaGenTx struct {
|
||||||
PubKey crypto.PubKey `json:"pub_key"`
|
PubKey crypto.PubKey `json:"pub_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// power given to validators in gaia init functions
|
// Generate a gaia genesis transaction
|
||||||
|
func GaiaAppGenTx(cdc *wire.Codec, pk crypto.PubKey) (
|
||||||
|
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
|
||||||
|
|
||||||
|
var addr sdk.Address
|
||||||
|
var secret string
|
||||||
|
clientRoot := viper.GetString(flagClientHome)
|
||||||
|
overwrite := viper.GetBool(flagOWK)
|
||||||
|
name := viper.GetString(flagName)
|
||||||
|
addr, secret, err = server.GenerateSaveCoinKey(clientRoot, name, "1234567890", overwrite)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var bz []byte
|
||||||
|
gaiaGenTx := GaiaGenTx{
|
||||||
|
Name: name,
|
||||||
|
Address: addr,
|
||||||
|
PubKey: pk,
|
||||||
|
}
|
||||||
|
bz, err = wire.MarshalJSONIndent(cdc, gaiaGenTx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
appGenTx = json.RawMessage(bz)
|
||||||
|
|
||||||
|
mm := map[string]string{"secret": secret}
|
||||||
|
bz, err = cdc.MarshalJSON(mm)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cliPrint = json.RawMessage(bz)
|
||||||
|
|
||||||
|
validator = tmtypes.GenesisValidator{
|
||||||
|
PubKey: pk,
|
||||||
|
Power: freeFermionVal,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Create the core parameters for genesis initialization for gaia
|
// Create the core parameters for genesis initialization for gaia
|
||||||
// note that the pubkey input is this machines pubkey
|
// note that the pubkey input is this machines pubkey
|
||||||
|
@ -133,43 +171,3 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState jso
|
||||||
appState, err = wire.MarshalJSONIndent(cdc, genesisState)
|
appState, err = wire.MarshalJSONIndent(cdc, genesisState)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a gaia genesis transaction
|
|
||||||
func GaiaAppGenTx(cdc *wire.Codec, pk crypto.PubKey) (
|
|
||||||
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
|
|
||||||
|
|
||||||
var addr sdk.Address
|
|
||||||
var secret string
|
|
||||||
clientRoot := viper.GetString(flagClientHome)
|
|
||||||
overwrite := viper.GetBool(flagOWK)
|
|
||||||
name := viper.GetString(flagName)
|
|
||||||
addr, secret, err = server.GenerateSaveCoinKey(clientRoot, name, "1234567890", overwrite)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var bz []byte
|
|
||||||
gaiaGenTx := GaiaGenTx{
|
|
||||||
Name: name,
|
|
||||||
Address: addr,
|
|
||||||
PubKey: pk,
|
|
||||||
}
|
|
||||||
bz, err = wire.MarshalJSONIndent(cdc, gaiaGenTx)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
appGenTx = json.RawMessage(bz)
|
|
||||||
|
|
||||||
mm := map[string]string{"secret": secret}
|
|
||||||
bz, err = cdc.MarshalJSON(mm)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cliPrint = json.RawMessage(bz)
|
|
||||||
|
|
||||||
validator = tmtypes.GenesisValidator{
|
|
||||||
PubKey: pk,
|
|
||||||
Power: freeFermionVal,
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
crypto "github.com/tendermint/go-crypto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestToAccount(t *testing.T) {
|
||||||
|
priv = crypto.GenPrivKeyEd25519()
|
||||||
|
addr = priv.PubKey().Address()
|
||||||
|
authAcc := auth.NewBaseAccountWithAddress(addr)
|
||||||
|
genAcc := NewGenesisAccount(authAcc)
|
||||||
|
assert.Equal(t, authAcc, genAcc.ToAccount())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGaiaAppGenTx(t *testing.T) {
|
||||||
|
cdc := MakeCodec()
|
||||||
|
|
||||||
|
//TODO test that key overwrite flags work / no overwrites if set off
|
||||||
|
//TODO test validator created has provided pubkey
|
||||||
|
//TODO test the account created has the correct pubkey
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGaiaAppGenState(t *testing.T) {
|
||||||
|
cdc := MakeCodec()
|
||||||
|
|
||||||
|
// TODO test must provide at least genesis transaction
|
||||||
|
// TODO test with both one and two genesis transactions:
|
||||||
|
// TODO correct: genesis account created, canididates created, pool token variance
|
||||||
|
}
|
|
@ -58,7 +58,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nodeID := string(nodeKey.ID())
|
nodeID := string(nodeKey.ID())
|
||||||
pubKey := ReadOrCreatePrivValidator(config)
|
pubKey := readOrCreatePrivValidator(config)
|
||||||
|
|
||||||
appGenTx, cliPrint, validator, err := appInit.AppGenTx(cdc, pubKey)
|
appGenTx, cliPrint, validator, err := appInit.AppGenTx(cdc, pubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -126,7 +126,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nodeID := string(nodeKey.ID())
|
nodeID := string(nodeKey.ID())
|
||||||
pubKey := ReadOrCreatePrivValidator(config)
|
pubKey := readOrCreatePrivValidator(config)
|
||||||
|
|
||||||
chainID := viper.GetString(flagChainID)
|
chainID := viper.GetString(flagChainID)
|
||||||
if chainID == "" {
|
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
|
// 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
|
// private validator
|
||||||
privValFile := tmConfig.PrivValidatorFile()
|
privValFile := tmConfig.PrivValidatorFile()
|
||||||
var privValidator *pvm.FilePV
|
var privValidator *pvm.FilePV
|
||||||
|
@ -297,21 +297,21 @@ type AppInit struct {
|
||||||
FlagsAppGenState *pflag.FlagSet
|
FlagsAppGenState *pflag.FlagSet
|
||||||
FlagsAppGenTx *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
|
// create the application genesis tx
|
||||||
AppGenTx func(cdc *wire.Codec, pk crypto.PubKey) (
|
AppGenTx func(cdc *wire.Codec, pk crypto.PubKey) (
|
||||||
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error)
|
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
|
// simple default application init
|
||||||
var DefaultAppInit = AppInit{
|
var DefaultAppInit = AppInit{
|
||||||
AppGenState: SimpleAppGenState,
|
|
||||||
AppGenTx: SimpleAppGenTx,
|
AppGenTx: SimpleAppGenTx,
|
||||||
|
AppGenState: SimpleAppGenState,
|
||||||
}
|
}
|
||||||
|
|
||||||
// simple genesis tx
|
// simple genesis tx
|
||||||
|
@ -319,34 +319,6 @@ type SimpleGenTx struct {
|
||||||
Addr sdk.Address `json:"addr"`
|
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
|
// Generate a genesis transaction
|
||||||
func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey) (
|
func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey) (
|
||||||
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
|
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
|
||||||
|
@ -380,6 +352,36 @@ func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey) (
|
||||||
return
|
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
|
// GenerateCoinKey returns the address of a public key, along with the secret
|
||||||
// phrase to recover the private key.
|
// phrase to recover the private key.
|
||||||
func GenerateCoinKey() (sdk.Address, string, error) {
|
func GenerateCoinKey() (sdk.Address, string, error) {
|
||||||
|
|
|
@ -12,7 +12,8 @@ import (
|
||||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
// TODO update
|
||||||
|
func TestInitCmd(t *testing.T) {
|
||||||
defer setupViper(t)()
|
defer setupViper(t)()
|
||||||
|
|
||||||
logger := log.NewNopLogger()
|
logger := log.NewNopLogger()
|
||||||
|
@ -28,3 +29,15 @@ func TestInit(t *testing.T) {
|
||||||
err = cmd.RunE(nil, nil)
|
err = cmd.RunE(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenTxCmd(t *testing.T) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSimpleAppGenTx(t *testing.T) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSimpleAppGenState(t *testing.T) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue