Skip to content

Commit

Permalink
fix code that may be relevant from Finschia#335 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
torao committed Jan 13, 2023
1 parent 027d481 commit 4e472a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
34 changes: 19 additions & 15 deletions privval/file_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package privval

import (
"encoding/base64"
"encoding/hex"
"fmt"
"io/ioutil"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/line/ostracon/crypto"
"github.com/line/ostracon/crypto/ed25519"
"github.com/line/ostracon/crypto/tmhash"
tmjson "github.com/line/ostracon/libs/json"
Expand All @@ -21,18 +21,6 @@ import (
tmtime "github.com/line/ostracon/types/time"
)

var jsonKey = func(t *testing.T, addr crypto.Address, privKey crypto.PrivKey, pubKey crypto.PubKey) string {
privKeyBytes, err := tmjson.MarshalIndent(privKey, " ", " ")
assert.Nil(t, err)
pubKeyBytes, err := tmjson.MarshalIndent(pubKey, " ", " ")
assert.Nil(t, err)
return fmt.Sprintf(`{
"address": "%s",
"pub_key": %s,
"priv_key": %s
}`, addr, pubKeyBytes, privKeyBytes)
}

func TestGenFilePV(t *testing.T) {
tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
require.Nil(t, err)
Expand All @@ -53,6 +41,7 @@ func TestGenLoadValidator(t *testing.T) {
require.Nil(t, err)

privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())

height := int64(100)
privVal.LastSignState.Height = height
privVal.Save()
Expand Down Expand Up @@ -147,8 +136,22 @@ func TestUnmarshalValidatorKey(t *testing.T) {
privKey := ed25519.GenPrivKey()
pubKey := privKey.PubKey()
addr := pubKey.Address()
pubBytes := pubKey.Bytes()
privBytes := privKey.Bytes()
pubB64 := base64.StdEncoding.EncodeToString(pubBytes)
privB64 := base64.StdEncoding.EncodeToString(privBytes)

serialized := jsonKey(t, addr, privKey, pubKey)
serialized := fmt.Sprintf(`{
"address": "%s",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "%s"
},
"priv_key": {
"type": "tendermint/PrivKeyEd25519",
"value": "%s"
}
}`, addr, pubB64, privB64)

val := FilePVKey{}
err := tmjson.Unmarshal([]byte(serialized), &val)
Expand All @@ -174,6 +177,7 @@ func TestSignVote(t *testing.T) {
require.Nil(t, err)

privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())

randbytes := tmrand.Bytes(tmhash.Size)
randbytes2 := tmrand.Bytes(tmhash.Size)

Expand Down Expand Up @@ -226,6 +230,7 @@ func TestSignProposal(t *testing.T) {
require.Nil(t, err)

privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())

randbytes := tmrand.Bytes(tmhash.Size)
randbytes2 := tmrand.Bytes(tmhash.Size)

Expand Down Expand Up @@ -293,7 +298,6 @@ func TestDifferByTimestamp(t *testing.T) {
require.Nil(t, err)

privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
require.Nil(t, err)
randbytes := tmrand.Bytes(tmhash.Size)
block1 := types.BlockID{Hash: randbytes, PartSetHeader: types.PartSetHeader{Total: 5, Hash: randbytes}}
height, round := int64(10), int32(1)
Expand Down
10 changes: 1 addition & 9 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,14 +836,6 @@ func NewCommit(height int64, round int32, blockID BlockID, commitSigs []CommitSi
}
}

const (
CommitHeighMaxtLen = 11
CommitRoundMaxLen = 6
CommitBlockIDMaxLen = 76
CommitAminoOverhead = 1
CommitAggrSigOverhead = 2
)

// CommitToVoteSet constructs a VoteSet from the Commit and validator set.
// Panics if signatures from the commit can't be added to the voteset.
// Inverse of VoteSet.MakeCommit().
Expand All @@ -855,7 +847,7 @@ func CommitToVoteSet(chainID string, commit *Commit, voters *VoterSet) *VoteSet
}
added, err := voteSet.AddVote(commit.GetVote(int32(idx)))
if !added || err != nil {
panic(fmt.Sprintf("Failedd to reconstruct LastCommit: %v", err))
panic(fmt.Sprintf("Failed to reconstruct LastCommit: %v", err))
}
}
return voteSet
Expand Down

0 comments on commit 4e472a1

Please sign in to comment.