mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-06 16:17:11 +00:00
fix tests
This commit is contained in:
@@ -157,6 +157,30 @@ func (privVal *PrivValidatorFS) save() {
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals the given jsonString
|
||||
// into a PrivValidatorFS using a DefaultSigner.
|
||||
func (pv *PrivValidatorFS) UnmarshalJSON(jsonString []byte) error {
|
||||
idAndInfo := &struct {
|
||||
ID ValidatorID `json:"id"`
|
||||
Info LastSignedInfo `json:"info"`
|
||||
}{}
|
||||
if err := json.Unmarshal(jsonString, idAndInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
signer := &struct {
|
||||
Signer *DefaultSigner `json:"signer"`
|
||||
}{}
|
||||
if err := json.Unmarshal(jsonString, signer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pv.ID = idAndInfo.ID
|
||||
pv.Info = idAndInfo.Info
|
||||
pv.Signer = signer.Signer
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset resets all fields in the PrivValidatorFS.Info.
|
||||
// NOTE: Unsafe!
|
||||
func (privVal *PrivValidatorFS) Reset() {
|
||||
|
||||
@@ -29,12 +29,14 @@ func TestLoadValidator(t *testing.T) {
|
||||
require.Nil(err, "%+v", err)
|
||||
|
||||
serialized := fmt.Sprintf(`{
|
||||
"info": {
|
||||
"id": {
|
||||
"address": "%s",
|
||||
"pub_key": {
|
||||
"type": "ed25519",
|
||||
"data": "%s"
|
||||
},
|
||||
}
|
||||
},
|
||||
"info": {
|
||||
"last_height": 0,
|
||||
"last_round": 0,
|
||||
"last_step": 0,
|
||||
@@ -48,14 +50,14 @@ func TestLoadValidator(t *testing.T) {
|
||||
}
|
||||
}`, addrStr, pubStr, privStr)
|
||||
|
||||
val := DefaultPrivValidator{}
|
||||
val := PrivValidatorFS{}
|
||||
err = json.Unmarshal([]byte(serialized), &val)
|
||||
require.Nil(err, "%+v", err)
|
||||
|
||||
// make sure the values match
|
||||
assert.EqualValues(addrBytes, val.Address())
|
||||
assert.EqualValues(pubKey, val.PubKey())
|
||||
valPrivKey := val.Signer.PrivKey
|
||||
valPrivKey := val.Signer.(*DefaultSigner).PrivKey
|
||||
assert.EqualValues(privKey, valPrivKey)
|
||||
|
||||
// export it and make sure it is the same
|
||||
|
||||
@@ -28,7 +28,7 @@ func BenchmarkProposalWriteSignBytes(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkProposalSign(b *testing.B) {
|
||||
privVal := GenPrivValidator()
|
||||
privVal := GenPrivValidatorFS("")
|
||||
for i := 0; i < b.N; i++ {
|
||||
privVal.Signer.Sign(SignBytes("test_chain_id", testProposal))
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func BenchmarkProposalSign(b *testing.B) {
|
||||
|
||||
func BenchmarkProposalVerifySignature(b *testing.B) {
|
||||
signBytes := SignBytes("test_chain_id", testProposal)
|
||||
privVal := GenPrivValidator()
|
||||
privVal := GenPrivValidatorFS("")
|
||||
signature, _ := privVal.Signer.Sign(signBytes)
|
||||
pubKey := privVal.PubKey()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// NOTE: privValidators are in order
|
||||
func randVoteSet(height int, round int, type_ byte, numValidators int, votingPower int64) (*VoteSet, *ValidatorSet, []*DefaultPrivValidator) {
|
||||
func randVoteSet(height int, round int, type_ byte, numValidators int, votingPower int64) (*VoteSet, *ValidatorSet, []*PrivValidatorFS) {
|
||||
valSet, privValidators := RandValidatorSet(numValidators, votingPower)
|
||||
return NewVoteSet("test_chain_id", height, round, type_, valSet), valSet, privValidators
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func withBlockPartsHeader(vote *Vote, blockPartsHeader PartSetHeader) *Vote {
|
||||
return vote
|
||||
}
|
||||
|
||||
func signAddVote(privVal *DefaultPrivValidator, vote *Vote, voteSet *VoteSet) (bool, error) {
|
||||
func signAddVote(privVal *PrivValidatorFS, vote *Vote, voteSet *VoteSet) (bool, error) {
|
||||
var err error
|
||||
vote.Signature, err = privVal.Signer.Sign(SignBytes(voteSet.ChainID(), vote))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user