test/e2e: fix secp failures (#5649)

This commit is contained in:
Marko
2020-11-16 12:31:32 +01:00
committed by Marko
parent 53463b3fef
commit 26493bbbd8
11 changed files with 47 additions and 21 deletions

View File

@@ -10,7 +10,7 @@ import (
func RandVal(i int) types.ValidatorUpdate {
pubkey := tmrand.Bytes(32)
power := tmrand.Uint16() + 1
v := types.Ed25519ValidatorUpdate(pubkey, int64(power))
v := types.UpdateValidator(pubkey, int64(power), "")
return v
}

View File

@@ -238,7 +238,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon
}
// update
return app.updateValidator(types.Ed25519ValidatorUpdate(pubkey, power))
return app.updateValidator(types.UpdateValidator(pubkey, power, ""))
}
// add, update, or remove a validator

View File

@@ -16,7 +16,7 @@ func InitChain(client abcicli.Client) error {
for i := 0; i < total; i++ {
pubkey := tmrand.Bytes(33)
power := tmrand.Int()
vals[i] = types.Ed25519ValidatorUpdate(pubkey, int64(power))
vals[i] = types.UpdateValidator(pubkey, int64(power), "")
}
_, err := client.InitChainSync(types.RequestInitChain{
Validators: vals,

View File

@@ -1,16 +1,16 @@
package types
import (
fmt "fmt"
"github.com/tendermint/tendermint/crypto/ed25519"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
)
const (
PubKeyEd25519 = "ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
)
func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
pke := ed25519.PubKey(pk)
pkp, err := cryptoenc.PubKeyToProto(pke)
if err != nil {
panic(err)
@@ -22,3 +22,23 @@ func Ed25519ValidatorUpdate(pk []byte, power int64) ValidatorUpdate {
Power: power,
}
}
func UpdateValidator(pk []byte, power int64, keyType string) ValidatorUpdate {
switch keyType {
case "", ed25519.KeyType:
return Ed25519ValidatorUpdate(pk, power)
case secp256k1.KeyType:
pke := secp256k1.PubKey(pk)
pkp, err := cryptoenc.PubKeyToProto(pke)
if err != nil {
panic(err)
}
return ValidatorUpdate{
// Address:
PubKey: pkp,
Power: power,
}
default:
panic(fmt.Sprintf("key type %s not supported", keyType))
}
}