fix PK encodings
This commit is contained in:
parent
e584d5acac
commit
265670297c
|
@ -23,8 +23,8 @@ func TestGaiaCLI(t *testing.T) {
|
|||
|
||||
tests.ExecuteT(t, "gaiad unsafe_reset_all")
|
||||
pass := "1234567890"
|
||||
executeWrite(t, false, "gaiacli keys delete foo", pass)
|
||||
executeWrite(t, false, "gaiacli keys delete bar", pass)
|
||||
executeWrite(t, "gaiacli keys delete foo", pass)
|
||||
executeWrite(t, "gaiacli keys delete bar", pass)
|
||||
masterKey, chainID := executeInit(t, "gaiad init")
|
||||
|
||||
// get a free port, also setup some common flags
|
||||
|
@ -35,8 +35,8 @@ func TestGaiaCLI(t *testing.T) {
|
|||
cmd, _, _ := tests.GoExecuteT(t, fmt.Sprintf("gaiad start --rpc.laddr=%v", servAddr))
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
executeWrite(t, false, "gaiacli keys add foo --recover", pass, masterKey)
|
||||
executeWrite(t, false, "gaiacli keys add bar", pass)
|
||||
executeWrite(t, "gaiacli keys add foo --recover", pass, masterKey)
|
||||
executeWrite(t, "gaiacli keys add bar", pass)
|
||||
|
||||
fooAddr, fooPubKey := executeGetAddr(t, "gaiacli keys show foo --output=json")
|
||||
barAddr, _ := executeGetAddr(t, "gaiacli keys show bar --output=json")
|
||||
|
@ -44,7 +44,7 @@ func TestGaiaCLI(t *testing.T) {
|
|||
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)
|
||||
executeWrite(t, 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))
|
||||
|
@ -64,25 +64,25 @@ func TestGaiaCLI(t *testing.T) {
|
|||
//--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)
|
||||
//_ = 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, declStr, pass)
|
||||
}
|
||||
|
||||
func executeWrite(t *testing.T, print bool, cmdStr string, writes ...string) {
|
||||
cmd, wc, rc := tests.GoExecuteT(t, cmdStr)
|
||||
func executeWrite(t *testing.T, cmdStr string, writes ...string) {
|
||||
cmd, wc, _ := tests.GoExecuteT(t, cmdStr)
|
||||
|
||||
if print {
|
||||
bz := make([]byte, 100000)
|
||||
rc.Read(bz)
|
||||
fmt.Printf("debug read: %v\n", string(bz))
|
||||
}
|
||||
//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"))
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"testing"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -315,15 +314,6 @@ func TestGetAccUpdateValidators(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// to compare pubkeys between abci pubkey and crypto.PubKey
|
||||
wirePK := func(pk crypto.PubKey) []byte {
|
||||
pkBytes, err := keeper.cdc.MarshalBinary(pk)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return pkBytes
|
||||
}
|
||||
|
||||
// test from nothing to something
|
||||
// candidate set: {} -> {c1, c3}
|
||||
// validator set: {} -> {c1, c3}
|
||||
|
@ -478,7 +468,7 @@ func TestGetAccUpdateValidators(t *testing.T) {
|
|||
acc = keeper.getAccUpdateValidators(ctx)
|
||||
require.Equal(t, 2, len(acc), "%v", acc)
|
||||
|
||||
assert.Equal(t, wirePK(candidatesIn[0].PubKey), acc[0].PubKey)
|
||||
assert.Equal(t, candidatesIn[0].PubKey.Bytes(), acc[0].PubKey)
|
||||
assert.Equal(t, int64(0), acc[0].Power)
|
||||
assert.Equal(t, vals[0].abciValidator(keeper.cdc), acc[1])
|
||||
|
||||
|
@ -503,10 +493,10 @@ func TestGetAccUpdateValidators(t *testing.T) {
|
|||
require.Equal(t, 0, len(candidates))
|
||||
acc = keeper.getAccUpdateValidators(ctx)
|
||||
require.Equal(t, 4, len(acc))
|
||||
assert.Equal(t, wirePK(candidatesIn[1].PubKey), acc[0].PubKey)
|
||||
assert.Equal(t, wirePK(candidatesIn[2].PubKey), acc[1].PubKey)
|
||||
assert.Equal(t, wirePK(candidatesIn[3].PubKey), acc[2].PubKey)
|
||||
assert.Equal(t, wirePK(candidatesIn[4].PubKey), acc[3].PubKey)
|
||||
assert.Equal(t, candidatesIn[1].PubKey.Bytes(), acc[0].PubKey)
|
||||
assert.Equal(t, candidatesIn[2].PubKey.Bytes(), acc[1].PubKey)
|
||||
assert.Equal(t, candidatesIn[3].PubKey.Bytes(), acc[2].PubKey)
|
||||
assert.Equal(t, candidatesIn[4].PubKey.Bytes(), acc[3].PubKey)
|
||||
assert.Equal(t, int64(0), acc[0].Power)
|
||||
assert.Equal(t, int64(0), acc[1].Power)
|
||||
assert.Equal(t, int64(0), acc[2].Power)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package stake
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
|
@ -133,20 +131,8 @@ type Validator struct {
|
|||
|
||||
// abci validator from stake validator type
|
||||
func (v Validator) abciValidator(cdc *wire.Codec) abci.Validator {
|
||||
//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: append(TypeDistinguisher, v.PubKey.Bytes()...),
|
||||
PubKey: v.PubKey.Bytes(),
|
||||
Power: v.Power.Evaluate(),
|
||||
}
|
||||
}
|
||||
|
@ -154,20 +140,8 @@ 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)
|
||||
//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: append(TypeDistinguisher, v.PubKey.Bytes()...),
|
||||
PubKey: v.PubKey.Bytes(),
|
||||
Power: 0,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue