parent
158e9dd12d
commit
e584d5acac
2
Makefile
2
Makefile
|
@ -7,7 +7,7 @@ all: check_tools get_vendor_deps build build_examples test
|
||||||
########################################
|
########################################
|
||||||
### CI
|
### CI
|
||||||
|
|
||||||
ci: get_tools get_vendor_deps build test_cover
|
ci: get_tools get_vendor_deps install test_cover
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
### Build
|
### Build
|
||||||
|
|
|
@ -11,6 +11,12 @@ func init() {
|
||||||
wire.RegisterCrypto(cdc)
|
wire.RegisterCrypto(cdc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// marshal keys
|
||||||
func MarshalJSON(o interface{}) ([]byte, error) {
|
func MarshalJSON(o interface{}) ([]byte, error) {
|
||||||
return cdc.MarshalJSON(o)
|
return cdc.MarshalJSON(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unmarshal json
|
||||||
|
func UnmarshalJSON(bz []byte, ptr interface{}) error {
|
||||||
|
return cdc.UnmarshalJSON(bz, ptr)
|
||||||
|
}
|
||||||
|
|
|
@ -39,10 +39,10 @@ type GaiaApp struct {
|
||||||
stakeKeeper stake.Keeper
|
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
|
// create your application object
|
||||||
var app = &GaiaApp{
|
var app = &GaiaApp{
|
||||||
BaseApp: bam.NewBaseApp(appName, logger, dbs["main"]),
|
BaseApp: bam.NewBaseApp(appName, logger, db),
|
||||||
cdc: MakeCodec(),
|
cdc: MakeCodec(),
|
||||||
capKeyMainStore: sdk.NewKVStoreKey("main"),
|
capKeyMainStore: sdk.NewKVStoreKey("main"),
|
||||||
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
|
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
|
||||||
|
@ -70,13 +70,7 @@ func NewGaiaApp(logger log.Logger, dbs map[string]dbm.DB) *GaiaApp {
|
||||||
app.SetTxDecoder(app.txDecoder)
|
app.SetTxDecoder(app.txDecoder)
|
||||||
app.SetInitChainer(app.initChainer)
|
app.SetInitChainer(app.initChainer)
|
||||||
app.SetEndBlocker(stake.NewEndBlocker(app.stakeKeeper))
|
app.SetEndBlocker(stake.NewEndBlocker(app.stakeKeeper))
|
||||||
app.MountStoreWithDB(app.capKeyMainStore, sdk.StoreTypeIAVL, dbs["main"])
|
app.MountStoresIAVL(app.capKeyMainStore, app.capKeyAccountStore, app.capKeyIBCStore, app.capKeyStakeStore)
|
||||||
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.SetAnteHandler(auth.NewAnteHandler(app.accountMapper))
|
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper))
|
||||||
err := app.LoadLatestVersion(app.capKeyMainStore)
|
err := app.LoadLatestVersion(app.capKeyMainStore)
|
||||||
if err != nil {
|
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
|
// 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)
|
err := app.cdc.UnmarshalBinary(txBytes, &tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, sdk.ErrTxDecode("").TraceCause(err, "")
|
return nil, sdk.ErrTxDecode("").TraceCause(err, "")
|
||||||
|
|
|
@ -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")
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
|
||||||
dbs := map[string]dbm.DB{
|
db := dbm.NewMemDB()
|
||||||
"main": dbm.NewMemDB(),
|
return logger, db
|
||||||
"acc": dbm.NewMemDB(),
|
|
||||||
"ibc": dbm.NewMemDB(),
|
|
||||||
"stake": dbm.NewMemDB(),
|
|
||||||
}
|
|
||||||
return logger, dbs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGaiaApp() *GaiaApp {
|
func newGaiaApp() *GaiaApp {
|
||||||
logger, dbs := loggerAndDBs()
|
logger, db := loggerAndDB()
|
||||||
return NewGaiaApp(logger, dbs)
|
return NewGaiaApp(logger, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
|
func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
|
||||||
|
@ -144,7 +139,7 @@ func TestMsgs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSortGenesis(t *testing.T) {
|
func TestSortGenesis(t *testing.T) {
|
||||||
logger, dbs := loggerAndDBs()
|
logger, dbs := loggerAndDB()
|
||||||
gapp := NewGaiaApp(logger, dbs)
|
gapp := NewGaiaApp(logger, dbs)
|
||||||
|
|
||||||
// Note the order: the coins are unsorted!
|
// Note the order: the coins are unsorted!
|
||||||
|
@ -188,7 +183,7 @@ func TestSortGenesis(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenesis(t *testing.T) {
|
func TestGenesis(t *testing.T) {
|
||||||
logger, dbs := loggerAndDBs()
|
logger, dbs := loggerAndDB()
|
||||||
gapp := NewGaiaApp(logger, dbs)
|
gapp := NewGaiaApp(logger, dbs)
|
||||||
|
|
||||||
// Construct some genesis bytes to reflect GaiaAccount
|
// Construct some genesis bytes to reflect GaiaAccount
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -10,17 +11,20 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
"github.com/cosmos/cosmos-sdk/tests"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"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) {
|
func TestGaiaCLI(t *testing.T) {
|
||||||
|
|
||||||
tests.ExecuteT(t, "gaiad unsafe_reset_all")
|
tests.ExecuteT(t, "gaiad unsafe_reset_all")
|
||||||
pass := "1234567890"
|
pass := "1234567890"
|
||||||
executeWrite(t, "gaiacli keys delete foo", pass)
|
executeWrite(t, false, "gaiacli keys delete foo", pass)
|
||||||
executeWrite(t, "gaiacli keys delete bar", pass)
|
executeWrite(t, false, "gaiacli keys delete bar", pass)
|
||||||
masterKey, chainID := executeInit(t, "gaiad init")
|
masterKey, chainID := executeInit(t, "gaiad init")
|
||||||
|
|
||||||
// get a free port, also setup some common flags
|
// 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))
|
cmd, _, _ := tests.GoExecuteT(t, fmt.Sprintf("gaiad start --rpc.laddr=%v", servAddr))
|
||||||
defer cmd.Process.Kill()
|
defer cmd.Process.Kill()
|
||||||
|
|
||||||
executeWrite(t, "gaiacli keys add foo --recover", pass, masterKey)
|
executeWrite(t, false, "gaiacli keys add foo --recover", pass, masterKey)
|
||||||
executeWrite(t, "gaiacli keys add bar", pass)
|
executeWrite(t, false, "gaiacli keys add bar", pass)
|
||||||
|
|
||||||
fooAddr := executeGetAddr(t, "gaiacli keys show foo")
|
fooAddr, fooPubKey := executeGetAddr(t, "gaiacli keys show foo --output=json")
|
||||||
barAddr := executeGetAddr(t, "gaiacli keys show bar")
|
barAddr, _ := executeGetAddr(t, "gaiacli keys show bar --output=json")
|
||||||
executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10fermion --to=%v --name=foo", flags, barAddr), pass)
|
|
||||||
|
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
|
time.Sleep(time.Second * 3) // waiting for some blocks to pass
|
||||||
|
|
||||||
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barAddr, flags))
|
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barAddr, flags))
|
||||||
assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("fermion"))
|
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"))
|
assert.Equal(t, int64(99990), fooAcc.GetCoins().AmountOf("fermion"))
|
||||||
|
|
||||||
// declare candidacy
|
// 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, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeWrite(t *testing.T, cmdStr string, writes ...string) {
|
|
||||||
cmd, wc, _ := tests.GoExecuteT(t, cmdStr)
|
|
||||||
for _, write := range writes {
|
for _, write := range writes {
|
||||||
_, err := wc.Write([]byte(write + "\n"))
|
_, err := wc.Write([]byte(write + "\n"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -71,10 +105,16 @@ func executeInit(t *testing.T, cmdStr string) (masterKey, chainID string) {
|
||||||
return
|
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)
|
out := tests.ExecuteT(t, cmdStr)
|
||||||
name := strings.SplitN(cmdStr, " show ", 2)[1]
|
var info crkeys.Info
|
||||||
return strings.TrimLeft(out, name+"\t")
|
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 {
|
func executeGetAccount(t *testing.T, cmdStr string) auth.BaseAccount {
|
||||||
|
|
|
@ -31,7 +31,7 @@ func generateApp(rootDir string, logger log.Logger) (abci.Application, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bapp := app.NewBasecoinApp(logger, db)
|
bapp := app.NewGaiaApp(logger, db)
|
||||||
//dbAcc, err := dbm.NewGoLevelDB("gaia-acc", dataDir)
|
//dbAcc, err := dbm.NewGoLevelDB("gaia-acc", dataDir)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
//return nil, err
|
//return nil, err
|
||||||
|
|
|
@ -269,9 +269,11 @@ func GetPubKey(pubKeyStr string) (pk crypto.PubKey, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(pubKeyStr) != 64 { //if len(pkBytes) != 32 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: bech32 ...
|
||||||
var pkBytes []byte
|
var pkBytes []byte
|
||||||
pkBytes, err = hex.DecodeString(pubKeyStr)
|
pkBytes, err = hex.DecodeString(pubKeyStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package stake
|
package stake
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/wire"
|
"github.com/cosmos/cosmos-sdk/wire"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
|
@ -131,12 +133,20 @@ type Validator struct {
|
||||||
|
|
||||||
// abci validator from stake validator type
|
// abci validator from stake validator type
|
||||||
func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator {
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return abci.Validator{
|
return abci.Validator{
|
||||||
PubKey: pkBytes,
|
PubKey: append(TypeDistinguisher, v.PubKey.Bytes()...),
|
||||||
Power: v.Power.Evaluate(),
|
Power: v.Power.Evaluate(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,12 +154,20 @@ func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator {
|
||||||
// abci validator from stake validator type
|
// abci validator from stake validator type
|
||||||
// with zero power used for validator updates
|
// with zero power used for validator updates
|
||||||
func (v Validator) abciValidatorZero(cdc *wire.Codec) abci.Validator {
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return abci.Validator{
|
return abci.Validator{
|
||||||
PubKey: pkBytes,
|
PubKey: append(TypeDistinguisher, v.PubKey.Bytes()...),
|
||||||
Power: 0,
|
Power: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue