ci build -> install

pubkey issue

...

rebase fixes

...
This commit is contained in:
rigelrozanski 2018-04-14 16:52:58 -04:00
parent 158e9dd12d
commit e584d5acac
8 changed files with 98 additions and 43 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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, "")

View File

@ -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

View File

@ -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 <host>:<port> 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 {

View File

@ -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

View File

@ -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 {

View File

@ -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,
}
}