rename privval#GetAddress and GetPubKey to Address and PubKey

This commit is contained in:
Anton Kaliaev
2018-07-12 22:40:06 +04:00
parent 20bb522592
commit ff8ddee708
23 changed files with 121 additions and 119 deletions
+2 -2
View File
@@ -14,7 +14,7 @@ type voteData struct {
func makeVote(val PrivValidator, chainID string, valIndex int, height int64, round, step int, blockID BlockID) *Vote {
v := &Vote{
ValidatorAddress: val.GetAddress(),
ValidatorAddress: val.Address(),
ValidatorIndex: valIndex,
Height: height,
Round: round,
@@ -59,7 +59,7 @@ func TestEvidence(t *testing.T) {
{vote1, badVote, false}, // signed by wrong key
}
pubKey := val.GetPubKey()
pubKey := val.PubKey()
for _, c := range cases {
ev := &DuplicateVoteEvidence{
VoteA: c.vote1,
+6 -6
View File
@@ -10,8 +10,8 @@ import (
// PrivValidator defines the functionality of a local Tendermint validator
// that signs votes, proposals, and heartbeats, and never double signs.
type PrivValidator interface {
GetAddress() Address // redundant since .PubKey().Address()
GetPubKey() crypto.PubKey
Address() Address // redundant since .PubKey().Address()
PubKey() crypto.PubKey
SignVote(chainID string, vote *Vote) error
SignProposal(chainID string, proposal *Proposal) error
@@ -28,7 +28,7 @@ func (pvs PrivValidatorsByAddress) Len() int {
}
func (pvs PrivValidatorsByAddress) Less(i, j int) bool {
return bytes.Compare(pvs[i].GetAddress(), pvs[j].GetAddress()) == -1
return bytes.Compare(pvs[i].Address(), pvs[j].Address()) == -1
}
func (pvs PrivValidatorsByAddress) Swap(i, j int) {
@@ -51,12 +51,12 @@ func NewMockPV() *MockPV {
}
// Implements PrivValidator.
func (pv *MockPV) GetAddress() Address {
func (pv *MockPV) Address() Address {
return pv.privKey.PubKey().Address()
}
// Implements PrivValidator.
func (pv *MockPV) GetPubKey() crypto.PubKey {
func (pv *MockPV) PubKey() crypto.PubKey {
return pv.privKey.PubKey()
}
@@ -94,7 +94,7 @@ func (pv *MockPV) SignHeartbeat(chainID string, heartbeat *Heartbeat) error {
// String returns a string representation of the MockPV.
func (pv *MockPV) String() string {
return fmt.Sprintf("MockPV{%v}", pv.GetAddress())
return fmt.Sprintf("MockPV{%v}", pv.Address())
}
// XXX: Implement.
+2 -2
View File
@@ -47,7 +47,7 @@ func TestProposalString(t *testing.T) {
func TestProposalVerifySignature(t *testing.T) {
privVal := NewMockPV()
pubKey := privVal.GetPubKey()
pubKey := privVal.PubKey()
prop := NewProposal(4, 2, PartSetHeader{777, []byte("proper")}, 2, BlockID{})
signBytes := prop.SignBytes("test_chain_id")
@@ -94,7 +94,7 @@ func BenchmarkProposalVerifySignature(b *testing.B) {
privVal := NewMockPV()
err := privVal.SignProposal("test_chain_id", testProposal)
require.Nil(b, err)
pubKey := privVal.GetPubKey()
pubKey := privVal.PubKey()
for i := 0; i < b.N; i++ {
pubKey.VerifyBytes(testProposal.SignBytes("test_chain_id"), testProposal.Signature)
+2 -2
View File
@@ -89,13 +89,13 @@ func TestABCIEvidence(t *testing.T) {
blockID2 := makeBlockID("blockhash2", 1000, "partshash")
const chainID = "mychain"
ev := &DuplicateVoteEvidence{
PubKey: val.GetPubKey(),
PubKey: val.PubKey(),
VoteA: makeVote(val, chainID, 0, 10, 2, 1, blockID),
VoteB: makeVote(val, chainID, 0, 10, 2, 1, blockID2),
}
abciEv := TM2PB.Evidence(
ev,
NewValidatorSet([]*Validator{NewValidator(val.GetPubKey(), 10)}),
NewValidatorSet([]*Validator{NewValidator(val.PubKey(), 10)}),
time.Now(),
)
+1 -1
View File
@@ -10,7 +10,7 @@ func MakeCommit(blockID BlockID, height int64, round int,
for i := 0; i < len(validators); i++ {
vote := &Vote{
ValidatorAddress: validators[i].GetAddress(),
ValidatorAddress: validators[i].Address(),
ValidatorIndex: i,
Height: height,
Round: round,
+2 -1
View File
@@ -93,6 +93,7 @@ func RandValidator(randPower bool, minPower int64) (*Validator, PrivValidator) {
if randPower {
votePower += int64(cmn.RandUint32())
}
val := NewValidator(privVal.GetPubKey(), votePower)
val := NewValidator(privVal.PubKey(), votePower)
return val, privVal
}
+27 -27
View File
@@ -66,7 +66,7 @@ func TestAddVote(t *testing.T) {
// t.Logf(">> %v", voteSet)
if voteSet.GetByAddress(val0.GetAddress()) != nil {
if voteSet.GetByAddress(val0.Address()) != nil {
t.Errorf("Expected GetByAddress(val0.Address) to be nil")
}
if voteSet.BitArray().GetIndex(0) {
@@ -78,7 +78,7 @@ func TestAddVote(t *testing.T) {
}
vote := &Vote{
ValidatorAddress: val0.GetAddress(),
ValidatorAddress: val0.Address(),
ValidatorIndex: 0, // since privValidators are in order
Height: height,
Round: round,
@@ -91,7 +91,7 @@ func TestAddVote(t *testing.T) {
t.Error(err)
}
if voteSet.GetByAddress(val0.GetAddress()) == nil {
if voteSet.GetByAddress(val0.Address()) == nil {
t.Errorf("Expected GetByAddress(val0.Address) to be present")
}
if !voteSet.BitArray().GetIndex(0) {
@@ -118,7 +118,7 @@ func Test2_3Majority(t *testing.T) {
}
// 6 out of 10 voted for nil.
for i := 0; i < 6; i++ {
vote := withValidator(voteProto, privValidators[i].GetAddress(), i)
vote := withValidator(voteProto, privValidators[i].Address(), i)
_, err := signAddVote(privValidators[i], vote, voteSet)
if err != nil {
t.Error(err)
@@ -131,7 +131,7 @@ func Test2_3Majority(t *testing.T) {
// 7th validator voted for some blockhash
{
vote := withValidator(voteProto, privValidators[6].GetAddress(), 6)
vote := withValidator(voteProto, privValidators[6].Address(), 6)
_, err := signAddVote(privValidators[6], withBlockHash(vote, cmn.RandBytes(32)), voteSet)
if err != nil {
t.Error(err)
@@ -144,7 +144,7 @@ func Test2_3Majority(t *testing.T) {
// 8th validator voted for nil.
{
vote := withValidator(voteProto, privValidators[7].GetAddress(), 7)
vote := withValidator(voteProto, privValidators[7].Address(), 7)
_, err := signAddVote(privValidators[7], vote, voteSet)
if err != nil {
t.Error(err)
@@ -176,7 +176,7 @@ func Test2_3MajorityRedux(t *testing.T) {
// 66 out of 100 voted for nil.
for i := 0; i < 66; i++ {
vote := withValidator(voteProto, privValidators[i].GetAddress(), i)
vote := withValidator(voteProto, privValidators[i].Address(), i)
_, err := signAddVote(privValidators[i], vote, voteSet)
if err != nil {
t.Error(err)
@@ -189,7 +189,7 @@ func Test2_3MajorityRedux(t *testing.T) {
// 67th validator voted for nil
{
vote := withValidator(voteProto, privValidators[66].GetAddress(), 66)
vote := withValidator(voteProto, privValidators[66].Address(), 66)
_, err := signAddVote(privValidators[66], withBlockHash(vote, nil), voteSet)
if err != nil {
t.Error(err)
@@ -202,7 +202,7 @@ func Test2_3MajorityRedux(t *testing.T) {
// 68th validator voted for a different BlockParts PartSetHeader
{
vote := withValidator(voteProto, privValidators[67].GetAddress(), 67)
vote := withValidator(voteProto, privValidators[67].Address(), 67)
blockPartsHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
_, err := signAddVote(privValidators[67], withBlockPartsHeader(vote, blockPartsHeader), voteSet)
if err != nil {
@@ -216,7 +216,7 @@ func Test2_3MajorityRedux(t *testing.T) {
// 69th validator voted for different BlockParts Total
{
vote := withValidator(voteProto, privValidators[68].GetAddress(), 68)
vote := withValidator(voteProto, privValidators[68].Address(), 68)
blockPartsHeader := PartSetHeader{blockPartsTotal + 1, blockPartsHeader.Hash}
_, err := signAddVote(privValidators[68], withBlockPartsHeader(vote, blockPartsHeader), voteSet)
if err != nil {
@@ -230,7 +230,7 @@ func Test2_3MajorityRedux(t *testing.T) {
// 70th validator voted for different BlockHash
{
vote := withValidator(voteProto, privValidators[69].GetAddress(), 69)
vote := withValidator(voteProto, privValidators[69].Address(), 69)
_, err := signAddVote(privValidators[69], withBlockHash(vote, cmn.RandBytes(32)), voteSet)
if err != nil {
t.Error(err)
@@ -243,7 +243,7 @@ func Test2_3MajorityRedux(t *testing.T) {
// 71st validator voted for the right BlockHash & BlockPartsHeader
{
vote := withValidator(voteProto, privValidators[70].GetAddress(), 70)
vote := withValidator(voteProto, privValidators[70].Address(), 70)
_, err := signAddVote(privValidators[70], vote, voteSet)
if err != nil {
t.Error(err)
@@ -271,7 +271,7 @@ func TestBadVotes(t *testing.T) {
// val0 votes for nil.
{
vote := withValidator(voteProto, privValidators[0].GetAddress(), 0)
vote := withValidator(voteProto, privValidators[0].Address(), 0)
added, err := signAddVote(privValidators[0], vote, voteSet)
if !added || err != nil {
t.Errorf("Expected VoteSet.Add to succeed")
@@ -280,7 +280,7 @@ func TestBadVotes(t *testing.T) {
// val0 votes again for some block.
{
vote := withValidator(voteProto, privValidators[0].GetAddress(), 0)
vote := withValidator(voteProto, privValidators[0].Address(), 0)
added, err := signAddVote(privValidators[0], withBlockHash(vote, cmn.RandBytes(32)), voteSet)
if added || err == nil {
t.Errorf("Expected VoteSet.Add to fail, conflicting vote.")
@@ -289,7 +289,7 @@ func TestBadVotes(t *testing.T) {
// val1 votes on another height
{
vote := withValidator(voteProto, privValidators[1].GetAddress(), 1)
vote := withValidator(voteProto, privValidators[1].Address(), 1)
added, err := signAddVote(privValidators[1], withHeight(vote, height+1), voteSet)
if added || err == nil {
t.Errorf("Expected VoteSet.Add to fail, wrong height")
@@ -298,7 +298,7 @@ func TestBadVotes(t *testing.T) {
// val2 votes on another round
{
vote := withValidator(voteProto, privValidators[2].GetAddress(), 2)
vote := withValidator(voteProto, privValidators[2].Address(), 2)
added, err := signAddVote(privValidators[2], withRound(vote, round+1), voteSet)
if added || err == nil {
t.Errorf("Expected VoteSet.Add to fail, wrong round")
@@ -307,7 +307,7 @@ func TestBadVotes(t *testing.T) {
// val3 votes of another type.
{
vote := withValidator(voteProto, privValidators[3].GetAddress(), 3)
vote := withValidator(voteProto, privValidators[3].Address(), 3)
added, err := signAddVote(privValidators[3], withType(vote, VoteTypePrecommit), voteSet)
if added || err == nil {
t.Errorf("Expected VoteSet.Add to fail, wrong type")
@@ -333,7 +333,7 @@ func TestConflicts(t *testing.T) {
// val0 votes for nil.
{
vote := withValidator(voteProto, privValidators[0].GetAddress(), 0)
vote := withValidator(voteProto, privValidators[0].Address(), 0)
added, err := signAddVote(privValidators[0], vote, voteSet)
if !added || err != nil {
t.Errorf("Expected VoteSet.Add to succeed")
@@ -342,7 +342,7 @@ func TestConflicts(t *testing.T) {
// val0 votes again for blockHash1.
{
vote := withValidator(voteProto, privValidators[0].GetAddress(), 0)
vote := withValidator(voteProto, privValidators[0].Address(), 0)
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet)
if added {
t.Errorf("Expected VoteSet.Add to fail, conflicting vote.")
@@ -357,7 +357,7 @@ func TestConflicts(t *testing.T) {
// val0 votes again for blockHash1.
{
vote := withValidator(voteProto, privValidators[0].GetAddress(), 0)
vote := withValidator(voteProto, privValidators[0].Address(), 0)
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet)
if !added {
t.Errorf("Expected VoteSet.Add to succeed, called SetPeerMaj23().")
@@ -372,7 +372,7 @@ func TestConflicts(t *testing.T) {
// val0 votes again for blockHash1.
{
vote := withValidator(voteProto, privValidators[0].GetAddress(), 0)
vote := withValidator(voteProto, privValidators[0].Address(), 0)
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash2), voteSet)
if added {
t.Errorf("Expected VoteSet.Add to fail, duplicate SetPeerMaj23() from peerA")
@@ -384,7 +384,7 @@ func TestConflicts(t *testing.T) {
// val1 votes for blockHash1.
{
vote := withValidator(voteProto, privValidators[1].GetAddress(), 1)
vote := withValidator(voteProto, privValidators[1].Address(), 1)
added, err := signAddVote(privValidators[1], withBlockHash(vote, blockHash1), voteSet)
if !added || err != nil {
t.Errorf("Expected VoteSet.Add to succeed")
@@ -401,7 +401,7 @@ func TestConflicts(t *testing.T) {
// val2 votes for blockHash2.
{
vote := withValidator(voteProto, privValidators[2].GetAddress(), 2)
vote := withValidator(voteProto, privValidators[2].Address(), 2)
added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash2), voteSet)
if !added || err != nil {
t.Errorf("Expected VoteSet.Add to succeed")
@@ -421,7 +421,7 @@ func TestConflicts(t *testing.T) {
// val2 votes for blockHash1.
{
vote := withValidator(voteProto, privValidators[2].GetAddress(), 2)
vote := withValidator(voteProto, privValidators[2].Address(), 2)
added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash1), voteSet)
if !added {
t.Errorf("Expected VoteSet.Add to succeed")
@@ -462,7 +462,7 @@ func TestMakeCommit(t *testing.T) {
// 6 out of 10 voted for some block.
for i := 0; i < 6; i++ {
vote := withValidator(voteProto, privValidators[i].GetAddress(), i)
vote := withValidator(voteProto, privValidators[i].Address(), i)
_, err := signAddVote(privValidators[i], vote, voteSet)
if err != nil {
t.Error(err)
@@ -474,7 +474,7 @@ func TestMakeCommit(t *testing.T) {
// 7th voted for some other block.
{
vote := withValidator(voteProto, privValidators[6].GetAddress(), 6)
vote := withValidator(voteProto, privValidators[6].Address(), 6)
vote = withBlockHash(vote, cmn.RandBytes(32))
vote = withBlockPartsHeader(vote, PartSetHeader{123, cmn.RandBytes(32)})
@@ -486,7 +486,7 @@ func TestMakeCommit(t *testing.T) {
// The 8th voted like everyone else.
{
vote := withValidator(voteProto, privValidators[7].GetAddress(), 7)
vote := withValidator(voteProto, privValidators[7].Address(), 7)
_, err := signAddVote(privValidators[7], vote, voteSet)
if err != nil {
t.Error(err)
+1 -1
View File
@@ -72,7 +72,7 @@ func TestVoteString(t *testing.T) {
func TestVoteVerifySignature(t *testing.T) {
privVal := NewMockPV()
pubKey := privVal.GetPubKey()
pubKey := privVal.PubKey()
vote := examplePrecommit()
signBytes := vote.SignBytes("test_chain_id")