|
|
@ -3,6 +3,7 @@ package privval |
|
|
|
import ( |
|
|
|
"encoding/base64" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"os" |
|
|
|
"testing" |
|
|
|
"time" |
|
|
@ -11,22 +12,22 @@ import ( |
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
"github.com/tendermint/tendermint/crypto" |
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519" |
|
|
|
cmn "github.com/tendermint/tendermint/libs/common" |
|
|
|
"github.com/tendermint/tendermint/types" |
|
|
|
) |
|
|
|
|
|
|
|
func TestGenLoadValidator(t *testing.T) { |
|
|
|
assert := assert.New(t) |
|
|
|
|
|
|
|
_, tempFilePath := cmn.Tempfile("priv_validator_") |
|
|
|
privVal := GenFilePV(tempFilePath) |
|
|
|
tempFile, err := ioutil.TempFile("", "priv_validator_") |
|
|
|
require.Nil(t, err) |
|
|
|
privVal := GenFilePV(tempFile.Name()) |
|
|
|
|
|
|
|
height := int64(100) |
|
|
|
privVal.LastHeight = height |
|
|
|
privVal.Save() |
|
|
|
addr := privVal.GetAddress() |
|
|
|
|
|
|
|
privVal = LoadFilePV(tempFilePath) |
|
|
|
privVal = LoadFilePV(tempFile.Name()) |
|
|
|
assert.Equal(addr, privVal.GetAddress(), "expected privval addr to be the same") |
|
|
|
assert.Equal(height, privVal.LastHeight, "expected privval.LastHeight to have been saved") |
|
|
|
} |
|
|
@ -34,7 +35,9 @@ func TestGenLoadValidator(t *testing.T) { |
|
|
|
func TestLoadOrGenValidator(t *testing.T) { |
|
|
|
assert := assert.New(t) |
|
|
|
|
|
|
|
_, tempFilePath := cmn.Tempfile("priv_validator_") |
|
|
|
tempFile, err := ioutil.TempFile("", "priv_validator_") |
|
|
|
require.Nil(t, err) |
|
|
|
tempFilePath := tempFile.Name() |
|
|
|
if err := os.Remove(tempFilePath); err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
@ -91,8 +94,9 @@ func TestUnmarshalValidator(t *testing.T) { |
|
|
|
func TestSignVote(t *testing.T) { |
|
|
|
assert := assert.New(t) |
|
|
|
|
|
|
|
_, tempFilePath := cmn.Tempfile("priv_validator_") |
|
|
|
privVal := GenFilePV(tempFilePath) |
|
|
|
tempFile, err := ioutil.TempFile("", "priv_validator_") |
|
|
|
require.Nil(t, err) |
|
|
|
privVal := GenFilePV(tempFile.Name()) |
|
|
|
|
|
|
|
block1 := types.BlockID{[]byte{1, 2, 3}, types.PartSetHeader{}} |
|
|
|
block2 := types.BlockID{[]byte{3, 2, 1}, types.PartSetHeader{}} |
|
|
@ -101,7 +105,7 @@ func TestSignVote(t *testing.T) { |
|
|
|
|
|
|
|
// sign a vote for first time
|
|
|
|
vote := newVote(privVal.Address, 0, height, round, voteType, block1) |
|
|
|
err := privVal.SignVote("mychainid", vote) |
|
|
|
err = privVal.SignVote("mychainid", vote) |
|
|
|
assert.NoError(err, "expected no error signing vote") |
|
|
|
|
|
|
|
// try to sign the same vote again; should be fine
|
|
|
@ -132,8 +136,9 @@ func TestSignVote(t *testing.T) { |
|
|
|
func TestSignProposal(t *testing.T) { |
|
|
|
assert := assert.New(t) |
|
|
|
|
|
|
|
_, tempFilePath := cmn.Tempfile("priv_validator_") |
|
|
|
privVal := GenFilePV(tempFilePath) |
|
|
|
tempFile, err := ioutil.TempFile("", "priv_validator_") |
|
|
|
require.Nil(t, err) |
|
|
|
privVal := GenFilePV(tempFile.Name()) |
|
|
|
|
|
|
|
block1 := types.PartSetHeader{5, []byte{1, 2, 3}} |
|
|
|
block2 := types.PartSetHeader{10, []byte{3, 2, 1}} |
|
|
@ -141,7 +146,7 @@ func TestSignProposal(t *testing.T) { |
|
|
|
|
|
|
|
// sign a proposal for first time
|
|
|
|
proposal := newProposal(height, round, block1) |
|
|
|
err := privVal.SignProposal("mychainid", proposal) |
|
|
|
err = privVal.SignProposal("mychainid", proposal) |
|
|
|
assert.NoError(err, "expected no error signing proposal") |
|
|
|
|
|
|
|
// try to sign the same proposal again; should be fine
|
|
|
@ -170,8 +175,9 @@ func TestSignProposal(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestDifferByTimestamp(t *testing.T) { |
|
|
|
_, tempFilePath := cmn.Tempfile("priv_validator_") |
|
|
|
privVal := GenFilePV(tempFilePath) |
|
|
|
tempFile, err := ioutil.TempFile("", "priv_validator_") |
|
|
|
require.Nil(t, err) |
|
|
|
privVal := GenFilePV(tempFile.Name()) |
|
|
|
|
|
|
|
block1 := types.PartSetHeader{5, []byte{1, 2, 3}} |
|
|
|
height, round := int64(10), 1 |
|
|
|