From e584d5acacc96108a1f028e69810946295a9aa10 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Sat, 14 Apr 2018 16:52:58 -0400 Subject: [PATCH] ci build -> install pubkey issue ... rebase fixes ... --- Makefile | 2 +- client/keys/wire.go | 6 ++++ cmd/gaia/app/app.go | 14 +++----- cmd/gaia/app/app_test.go | 19 ++++------- cmd/gaia/cmd/cli_test.go | 68 ++++++++++++++++++++++++++++++-------- cmd/gaia/cmd/gaiad/main.go | 2 +- x/stake/commands/tx.go | 4 ++- x/stake/types.go | 26 ++++++++++++--- 8 files changed, 98 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index 78a5c9dcc..daa0361fc 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: check_tools get_vendor_deps build build_examples test ######################################## ### CI -ci: get_tools get_vendor_deps build test_cover +ci: get_tools get_vendor_deps install test_cover ######################################## ### Build diff --git a/client/keys/wire.go b/client/keys/wire.go index 225e60ae7..a163f995a 100644 --- a/client/keys/wire.go +++ b/client/keys/wire.go @@ -11,6 +11,12 @@ func init() { wire.RegisterCrypto(cdc) } +// marshal keys func MarshalJSON(o interface{}) ([]byte, error) { return cdc.MarshalJSON(o) } + +// unmarshal json +func UnmarshalJSON(bz []byte, ptr interface{}) error { + return cdc.UnmarshalJSON(bz, ptr) +} diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index eeb64a7a7..0c9ef8b55 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -39,10 +39,10 @@ type GaiaApp struct { stakeKeeper stake.Keeper } -func NewGaiaApp(logger log.Logger, dbs map[string]dbm.DB) *GaiaApp { +func NewGaiaApp(logger log.Logger, db dbm.DB) *GaiaApp { // create your application object var app = &GaiaApp{ - BaseApp: bam.NewBaseApp(appName, logger, dbs["main"]), + BaseApp: bam.NewBaseApp(appName, logger, db), cdc: MakeCodec(), capKeyMainStore: sdk.NewKVStoreKey("main"), capKeyAccountStore: sdk.NewKVStoreKey("acc"), @@ -70,13 +70,7 @@ func NewGaiaApp(logger log.Logger, dbs map[string]dbm.DB) *GaiaApp { app.SetTxDecoder(app.txDecoder) app.SetInitChainer(app.initChainer) app.SetEndBlocker(stake.NewEndBlocker(app.stakeKeeper)) - app.MountStoreWithDB(app.capKeyMainStore, sdk.StoreTypeIAVL, dbs["main"]) - app.MountStoreWithDB(app.capKeyAccountStore, sdk.StoreTypeIAVL, dbs["acc"]) - app.MountStoreWithDB(app.capKeyIBCStore, sdk.StoreTypeIAVL, dbs["ibc"]) - app.MountStoreWithDB(app.capKeyStakeStore, sdk.StoreTypeIAVL, dbs["stake"]) - - // NOTE: Broken until #532 lands - //app.MountStoresIAVL(app.capKeyMainStore, app.capKeyIBCStore, app.capKeyStakeStore) + app.MountStoresIAVL(app.capKeyMainStore, app.capKeyAccountStore, app.capKeyIBCStore, app.capKeyStakeStore) app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper)) err := app.LoadLatestVersion(app.capKeyMainStore) if err != nil { @@ -116,7 +110,7 @@ func (app *GaiaApp) txDecoder(txBytes []byte) (sdk.Tx, sdk.Error) { } // StdTx.Msg is an interface. The concrete types - // are registered by MakeTxCodec in bank.RegisterWire. + // are registered by MakeTxCodec err := app.cdc.UnmarshalBinary(txBytes, &tx) if err != nil { return nil, sdk.ErrTxDecode("").TraceCause(err, "") diff --git a/cmd/gaia/app/app_test.go b/cmd/gaia/app/app_test.go index ea10cebc5..5c8450138 100644 --- a/cmd/gaia/app/app_test.go +++ b/cmd/gaia/app/app_test.go @@ -85,20 +85,15 @@ var ( } ) -func loggerAndDBs() (log.Logger, map[string]dbm.DB) { +func loggerAndDB() (log.Logger, dbm.DB) { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app") - dbs := map[string]dbm.DB{ - "main": dbm.NewMemDB(), - "acc": dbm.NewMemDB(), - "ibc": dbm.NewMemDB(), - "stake": dbm.NewMemDB(), - } - return logger, dbs + db := dbm.NewMemDB() + return logger, db } func newGaiaApp() *GaiaApp { - logger, dbs := loggerAndDBs() - return NewGaiaApp(logger, dbs) + logger, db := loggerAndDB() + return NewGaiaApp(logger, db) } func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error { @@ -144,7 +139,7 @@ func TestMsgs(t *testing.T) { } func TestSortGenesis(t *testing.T) { - logger, dbs := loggerAndDBs() + logger, dbs := loggerAndDB() gapp := NewGaiaApp(logger, dbs) // Note the order: the coins are unsorted! @@ -188,7 +183,7 @@ func TestSortGenesis(t *testing.T) { } func TestGenesis(t *testing.T) { - logger, dbs := loggerAndDBs() + logger, dbs := loggerAndDB() gapp := NewGaiaApp(logger, dbs) // Construct some genesis bytes to reflect GaiaAccount diff --git a/cmd/gaia/cmd/cli_test.go b/cmd/gaia/cmd/cli_test.go index eb31aaad1..c537ae0a5 100644 --- a/cmd/gaia/cmd/cli_test.go +++ b/cmd/gaia/cmd/cli_test.go @@ -1,6 +1,7 @@ package common import ( + "encoding/hex" "encoding/json" "fmt" "strings" @@ -10,17 +11,20 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/tests" "github.com/cosmos/cosmos-sdk/x/auth" + crypto "github.com/tendermint/go-crypto" + crkeys "github.com/tendermint/go-crypto/keys" ) func TestGaiaCLI(t *testing.T) { tests.ExecuteT(t, "gaiad unsafe_reset_all") pass := "1234567890" - executeWrite(t, "gaiacli keys delete foo", pass) - executeWrite(t, "gaiacli keys delete bar", pass) + executeWrite(t, false, "gaiacli keys delete foo", pass) + executeWrite(t, false, "gaiacli keys delete bar", pass) masterKey, chainID := executeInit(t, "gaiad init") // get a free port, also setup some common flags @@ -31,25 +35,55 @@ func TestGaiaCLI(t *testing.T) { cmd, _, _ := tests.GoExecuteT(t, fmt.Sprintf("gaiad start --rpc.laddr=%v", servAddr)) defer cmd.Process.Kill() - executeWrite(t, "gaiacli keys add foo --recover", pass, masterKey) - executeWrite(t, "gaiacli keys add bar", pass) + executeWrite(t, false, "gaiacli keys add foo --recover", pass, masterKey) + executeWrite(t, false, "gaiacli keys add bar", pass) - fooAddr := executeGetAddr(t, "gaiacli keys show foo") - barAddr := executeGetAddr(t, "gaiacli keys show bar") - executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10fermion --to=%v --name=foo", flags, barAddr), pass) + fooAddr, fooPubKey := executeGetAddr(t, "gaiacli keys show foo --output=json") + barAddr, _ := executeGetAddr(t, "gaiacli keys show bar --output=json") + + fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooAddr, flags)) + assert.Equal(t, int64(100000), fooAcc.GetCoins().AmountOf("fermion")) + + executeWrite(t, false, fmt.Sprintf("gaiacli send %v --amount=10fermion --to=%v --name=foo", flags, barAddr), pass) time.Sleep(time.Second * 3) // waiting for some blocks to pass barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barAddr, flags)) assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("fermion")) - fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooAddr, flags)) + fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooAddr, flags)) assert.Equal(t, int64(99990), fooAcc.GetCoins().AmountOf("fermion")) // declare candidacy - //executeWrite(t, "gaiacli declare-candidacy -", pass) + //--address-candidate string hex address of the validator/candidate + //--amount string Amount of coins to bond (default "1fermion") + //--chain-id string Chain ID of tendermint node + //--fee string Fee to pay along with transaction + //--keybase-sig string optional keybase signature + //--moniker string validator-candidate name + //--name string Name of private key with which to sign + //--node string : to tendermint rpc interface for this chain (default "tcp://localhost:46657") + //--pubkey string PubKey of the validator-candidate + //--sequence int Sequence number to sign the tx + //--website string optional website + _ = fooPubKey + //declStr := fmt.Sprintf("gaiacli declare-candidacy %v", flags) + //declStr += fmt.Sprintf(" --name=%v", "foo") + //declStr += fmt.Sprintf(" --address-candidate=%v", fooAddr) + //declStr += fmt.Sprintf(" --pubkey=%v", fooPubKey) + //declStr += fmt.Sprintf(" --amount=%v", "3fermion") + //declStr += fmt.Sprintf(" --moniker=%v", "foo-vally") + //fmt.Printf("debug declStr: %v\n", declStr) + //executeWrite(t, true, declStr, pass) } -func executeWrite(t *testing.T, cmdStr string, writes ...string) { - cmd, wc, _ := tests.GoExecuteT(t, cmdStr) +func executeWrite(t *testing.T, print bool, cmdStr string, writes ...string) { + cmd, wc, rc := tests.GoExecuteT(t, cmdStr) + + if print { + bz := make([]byte, 100000) + rc.Read(bz) + fmt.Printf("debug read: %v\n", string(bz)) + } + for _, write := range writes { _, err := wc.Write([]byte(write + "\n")) require.NoError(t, err) @@ -71,10 +105,16 @@ func executeInit(t *testing.T, cmdStr string) (masterKey, chainID string) { return } -func executeGetAddr(t *testing.T, cmdStr string) (addr string) { +func executeGetAddr(t *testing.T, cmdStr string) (addr, pubKey string) { out := tests.ExecuteT(t, cmdStr) - name := strings.SplitN(cmdStr, " show ", 2)[1] - return strings.TrimLeft(out, name+"\t") + var info crkeys.Info + keys.UnmarshalJSON([]byte(out), &info) + pubKey = hex.EncodeToString(info.PubKey.(crypto.PubKeyEd25519).Bytes()) + pubKey = strings.TrimLeft(pubKey, "1624de6220") + fmt.Printf("debug pubKey: %v\n", pubKey) + addr = info.PubKey.Address().String() + fmt.Printf("debug addr: %v\n", addr) + return } func executeGetAccount(t *testing.T, cmdStr string) auth.BaseAccount { diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index b84a4e20d..91ea778f7 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -31,7 +31,7 @@ func generateApp(rootDir string, logger log.Logger) (abci.Application, error) { if err != nil { return nil, err } - bapp := app.NewBasecoinApp(logger, db) + bapp := app.NewGaiaApp(logger, db) //dbAcc, err := dbm.NewGoLevelDB("gaia-acc", dataDir) //if err != nil { //return nil, err diff --git a/x/stake/commands/tx.go b/x/stake/commands/tx.go index 679e59b15..76220aeb6 100644 --- a/x/stake/commands/tx.go +++ b/x/stake/commands/tx.go @@ -269,9 +269,11 @@ func GetPubKey(pubKeyStr string) (pk crypto.PubKey, err error) { return } if len(pubKeyStr) != 64 { //if len(pkBytes) != 32 { - err = fmt.Errorf("pubkey must be Ed25519 hex encoded string which is 64 characters long") + err = fmt.Errorf("pubkey must be Ed25519 hex encoded string which is 64 characters, this pubkey is %v characters", len(pubKeyStr)) return } + + // TODO: bech32 ... var pkBytes []byte pkBytes, err = hex.DecodeString(pubKeyStr) if err != nil { diff --git a/x/stake/types.go b/x/stake/types.go index 240f3fe2a..14978ce35 100644 --- a/x/stake/types.go +++ b/x/stake/types.go @@ -1,6 +1,8 @@ package stake import ( + "encoding/hex" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/wire" abci "github.com/tendermint/abci/types" @@ -131,12 +133,20 @@ type Validator struct { // abci validator from stake validator type func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator { - pkBytes, err := cdc.MarshalBinary(v.PubKey) + //pkBytes, err := cdc.MarshalBinary(v.PubKey) + //if err != nil { + //panic(err) + //} + //return abci.Validator{ + //PubKey: pkBytes, + //Power: v.Power.Evaluate(), + //} + TypeDistinguisher, err := hex.DecodeString("1624de6220") if err != nil { panic(err) } return abci.Validator{ - PubKey: pkBytes, + PubKey: append(TypeDistinguisher, v.PubKey.Bytes()...), Power: v.Power.Evaluate(), } } @@ -144,12 +154,20 @@ func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator { // abci validator from stake validator type // with zero power used for validator updates func (v Validator) abciValidatorZero(cdc *wire.Codec) abci.Validator { - pkBytes, err := cdc.MarshalBinary(v.PubKey) + //pkBytes, err := cdc.MarshalBinary(v.PubKey) + //if err != nil { + //panic(err) + //} + //return abci.Validator{ + //PubKey: pkBytes, + //Power: 0, + //} + TypeDistinguisher, err := hex.DecodeString("1624de6220") if err != nil { panic(err) } return abci.Validator{ - PubKey: pkBytes, + PubKey: append(TypeDistinguisher, v.PubKey.Bytes()...), Power: 0, } }