mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 17:34:36 +00:00
+29
-29
@@ -52,19 +52,19 @@ func (b *Block) ValidateBasic() error {
|
||||
defer b.mtx.Unlock()
|
||||
|
||||
if len(b.ChainID) > MaxChainIDLen {
|
||||
return fmt.Errorf("ChainID is too long. Max is %d, got %d", MaxChainIDLen, len(b.ChainID))
|
||||
return fmt.Errorf("chainID is too long. Max is %d, got %d", MaxChainIDLen, len(b.ChainID))
|
||||
}
|
||||
|
||||
if b.Height < 0 {
|
||||
return errors.New("Negative Header.Height")
|
||||
return errors.New("negative Header.Height")
|
||||
} else if b.Height == 0 {
|
||||
return errors.New("Zero Header.Height")
|
||||
return errors.New("zero Header.Height")
|
||||
}
|
||||
|
||||
// NOTE: Timestamp validation is subtle and handled elsewhere.
|
||||
|
||||
if err := b.LastBlockID.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Wrong Header.LastBlockID: %v", err)
|
||||
return fmt.Errorf("wrong Header.LastBlockID: %v", err)
|
||||
}
|
||||
|
||||
// Validate the last commit and its hash.
|
||||
@@ -73,14 +73,14 @@ func (b *Block) ValidateBasic() error {
|
||||
return errors.New("nil LastCommit")
|
||||
}
|
||||
if err := b.LastCommit.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Wrong LastCommit")
|
||||
return fmt.Errorf("wrong LastCommit")
|
||||
}
|
||||
}
|
||||
if err := ValidateHash(b.LastCommitHash); err != nil {
|
||||
return fmt.Errorf("Wrong Header.LastCommitHash: %v", err)
|
||||
return fmt.Errorf("wrong Header.LastCommitHash: %v", err)
|
||||
}
|
||||
if !bytes.Equal(b.LastCommitHash, b.LastCommit.Hash()) {
|
||||
return fmt.Errorf("Wrong Header.LastCommitHash. Expected %v, got %v",
|
||||
return fmt.Errorf("wrong Header.LastCommitHash. Expected %v, got %v",
|
||||
b.LastCommit.Hash(),
|
||||
b.LastCommitHash,
|
||||
)
|
||||
@@ -90,11 +90,11 @@ func (b *Block) ValidateBasic() error {
|
||||
// NOTE: b.Data.Txs may be nil, but b.Data.Hash()
|
||||
// still works fine
|
||||
if err := ValidateHash(b.DataHash); err != nil {
|
||||
return fmt.Errorf("Wrong Header.DataHash: %v", err)
|
||||
return fmt.Errorf("wrong Header.DataHash: %v", err)
|
||||
}
|
||||
if !bytes.Equal(b.DataHash, b.Data.Hash()) {
|
||||
return fmt.Errorf(
|
||||
"Wrong Header.DataHash. Expected %v, got %v",
|
||||
"wrong Header.DataHash. Expected %v, got %v",
|
||||
b.Data.Hash(),
|
||||
b.DataHash,
|
||||
)
|
||||
@@ -103,38 +103,38 @@ func (b *Block) ValidateBasic() error {
|
||||
// Basic validation of hashes related to application data.
|
||||
// Will validate fully against state in state#ValidateBlock.
|
||||
if err := ValidateHash(b.ValidatorsHash); err != nil {
|
||||
return fmt.Errorf("Wrong Header.ValidatorsHash: %v", err)
|
||||
return fmt.Errorf("wrong Header.ValidatorsHash: %v", err)
|
||||
}
|
||||
if err := ValidateHash(b.NextValidatorsHash); err != nil {
|
||||
return fmt.Errorf("Wrong Header.NextValidatorsHash: %v", err)
|
||||
return fmt.Errorf("wrong Header.NextValidatorsHash: %v", err)
|
||||
}
|
||||
if err := ValidateHash(b.ConsensusHash); err != nil {
|
||||
return fmt.Errorf("Wrong Header.ConsensusHash: %v", err)
|
||||
return fmt.Errorf("wrong Header.ConsensusHash: %v", err)
|
||||
}
|
||||
// NOTE: AppHash is arbitrary length
|
||||
if err := ValidateHash(b.LastResultsHash); err != nil {
|
||||
return fmt.Errorf("Wrong Header.LastResultsHash: %v", err)
|
||||
return fmt.Errorf("wrong Header.LastResultsHash: %v", err)
|
||||
}
|
||||
|
||||
// Validate evidence and its hash.
|
||||
if err := ValidateHash(b.EvidenceHash); err != nil {
|
||||
return fmt.Errorf("Wrong Header.EvidenceHash: %v", err)
|
||||
return fmt.Errorf("wrong Header.EvidenceHash: %v", err)
|
||||
}
|
||||
// NOTE: b.Evidence.Evidence may be nil, but we're just looping.
|
||||
for i, ev := range b.Evidence.Evidence {
|
||||
if err := ev.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Invalid evidence (#%d): %v", i, err)
|
||||
return fmt.Errorf("invalid evidence (#%d): %v", i, err)
|
||||
}
|
||||
}
|
||||
if !bytes.Equal(b.EvidenceHash, b.Evidence.Hash()) {
|
||||
return fmt.Errorf("Wrong Header.EvidenceHash. Expected %v, got %v",
|
||||
return fmt.Errorf("wrong Header.EvidenceHash. Expected %v, got %v",
|
||||
b.EvidenceHash,
|
||||
b.Evidence.Hash(),
|
||||
)
|
||||
}
|
||||
|
||||
if len(b.ProposerAddress) != crypto.AddressSize {
|
||||
return fmt.Errorf("Expected len(Header.ProposerAddress) to be %d, got %d",
|
||||
return fmt.Errorf("expected len(Header.ProposerAddress) to be %d, got %d",
|
||||
crypto.AddressSize, len(b.ProposerAddress))
|
||||
}
|
||||
|
||||
@@ -612,10 +612,10 @@ func (commit *Commit) IsCommit() bool {
|
||||
// Does not actually check the cryptographic signatures.
|
||||
func (commit *Commit) ValidateBasic() error {
|
||||
if commit.BlockID.IsZero() {
|
||||
return errors.New("Commit cannot be for nil block")
|
||||
return errors.New("commit cannot be for nil block")
|
||||
}
|
||||
if len(commit.Precommits) == 0 {
|
||||
return errors.New("No precommits in commit")
|
||||
return errors.New("no precommits in commit")
|
||||
}
|
||||
height, round := commit.Height(), commit.Round()
|
||||
|
||||
@@ -627,17 +627,17 @@ func (commit *Commit) ValidateBasic() error {
|
||||
}
|
||||
// Ensure that all votes are precommits.
|
||||
if precommit.Type != PrecommitType {
|
||||
return fmt.Errorf("Invalid commit vote. Expected precommit, got %v",
|
||||
return fmt.Errorf("invalid commit vote. Expected precommit, got %v",
|
||||
precommit.Type)
|
||||
}
|
||||
// Ensure that all heights are the same.
|
||||
if precommit.Height != height {
|
||||
return fmt.Errorf("Invalid commit precommit height. Expected %v, got %v",
|
||||
return fmt.Errorf("invalid commit precommit height. Expected %v, got %v",
|
||||
height, precommit.Height)
|
||||
}
|
||||
// Ensure that all rounds are the same.
|
||||
if precommit.Round != round {
|
||||
return fmt.Errorf("Invalid commit precommit round. Expected %v, got %v",
|
||||
return fmt.Errorf("invalid commit precommit round. Expected %v, got %v",
|
||||
round, precommit.Round)
|
||||
}
|
||||
}
|
||||
@@ -698,27 +698,27 @@ func (sh SignedHeader) ValidateBasic(chainID string) error {
|
||||
|
||||
// Make sure the header is consistent with the commit.
|
||||
if sh.Header == nil {
|
||||
return errors.New("SignedHeader missing header.")
|
||||
return errors.New("signedHeader missing header.")
|
||||
}
|
||||
if sh.Commit == nil {
|
||||
return errors.New("SignedHeader missing commit (precommit votes).")
|
||||
return errors.New("signedHeader missing commit (precommit votes).")
|
||||
}
|
||||
|
||||
// Check ChainID.
|
||||
if sh.ChainID != chainID {
|
||||
return fmt.Errorf("Header belongs to another chain '%s' not '%s'",
|
||||
return fmt.Errorf("header belongs to another chain '%s' not '%s'",
|
||||
sh.ChainID, chainID)
|
||||
}
|
||||
// Check Height.
|
||||
if sh.Commit.Height() != sh.Height {
|
||||
return fmt.Errorf("SignedHeader header and commit height mismatch: %v vs %v",
|
||||
return fmt.Errorf("signedHeader header and commit height mismatch: %v vs %v",
|
||||
sh.Height, sh.Commit.Height())
|
||||
}
|
||||
// Check Hash.
|
||||
hhash := sh.Hash()
|
||||
chash := sh.Commit.BlockID.Hash
|
||||
if !bytes.Equal(hhash, chash) {
|
||||
return fmt.Errorf("SignedHeader commit signs block %X, header is block %X",
|
||||
return fmt.Errorf("signedHeader commit signs block %X, header is block %X",
|
||||
chash, hhash)
|
||||
}
|
||||
// ValidateBasic on the Commit.
|
||||
@@ -854,10 +854,10 @@ func (blockID BlockID) Key() string {
|
||||
func (blockID BlockID) ValidateBasic() error {
|
||||
// Hash can be empty in case of POLBlockID in Proposal.
|
||||
if err := ValidateHash(blockID.Hash); err != nil {
|
||||
return fmt.Errorf("Wrong Hash")
|
||||
return fmt.Errorf("wrong Hash")
|
||||
}
|
||||
if err := blockID.PartsHeader.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Wrong PartsHeader: %v", err)
|
||||
return fmt.Errorf("wrong PartsHeader: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ package types
|
||||
|
||||
import (
|
||||
amino "github.com/tendermint/go-amino"
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
)
|
||||
|
||||
var cdc = amino.NewCodec()
|
||||
@@ -12,7 +12,7 @@ func init() {
|
||||
}
|
||||
|
||||
func RegisterBlockAmino(cdc *amino.Codec) {
|
||||
cryptoAmino.RegisterAmino(cdc)
|
||||
cryptoamino.RegisterAmino(cdc)
|
||||
RegisterEvidences(cdc)
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -136,13 +136,13 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e
|
||||
if dve.VoteA.Height != dve.VoteB.Height ||
|
||||
dve.VoteA.Round != dve.VoteB.Round ||
|
||||
dve.VoteA.Type != dve.VoteB.Type {
|
||||
return fmt.Errorf("DuplicateVoteEvidence Error: H/R/S does not match. Got %v and %v", dve.VoteA, dve.VoteB)
|
||||
return fmt.Errorf("duplicateVoteEvidence Error: H/R/S does not match. Got %v and %v", dve.VoteA, dve.VoteB)
|
||||
}
|
||||
|
||||
// Address must be the same
|
||||
if !bytes.Equal(dve.VoteA.ValidatorAddress, dve.VoteB.ValidatorAddress) {
|
||||
return fmt.Errorf(
|
||||
"DuplicateVoteEvidence Error: Validator addresses do not match. Got %X and %X",
|
||||
"duplicateVoteEvidence Error: Validator addresses do not match. Got %X and %X",
|
||||
dve.VoteA.ValidatorAddress,
|
||||
dve.VoteB.ValidatorAddress,
|
||||
)
|
||||
@@ -151,7 +151,7 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e
|
||||
// Index must be the same
|
||||
if dve.VoteA.ValidatorIndex != dve.VoteB.ValidatorIndex {
|
||||
return fmt.Errorf(
|
||||
"DuplicateVoteEvidence Error: Validator indices do not match. Got %d and %d",
|
||||
"duplicateVoteEvidence Error: Validator indices do not match. Got %d and %d",
|
||||
dve.VoteA.ValidatorIndex,
|
||||
dve.VoteB.ValidatorIndex,
|
||||
)
|
||||
@@ -160,7 +160,7 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e
|
||||
// BlockIDs must be different
|
||||
if dve.VoteA.BlockID.Equals(dve.VoteB.BlockID) {
|
||||
return fmt.Errorf(
|
||||
"DuplicateVoteEvidence Error: BlockIDs are the same (%v) - not a real duplicate vote",
|
||||
"duplicateVoteEvidence Error: BlockIDs are the same (%v) - not a real duplicate vote",
|
||||
dve.VoteA.BlockID,
|
||||
)
|
||||
}
|
||||
@@ -168,16 +168,16 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e
|
||||
// pubkey must match address (this should already be true, sanity check)
|
||||
addr := dve.VoteA.ValidatorAddress
|
||||
if !bytes.Equal(pubKey.Address(), addr) {
|
||||
return fmt.Errorf("DuplicateVoteEvidence FAILED SANITY CHECK - address (%X) doesn't match pubkey (%v - %X)",
|
||||
return fmt.Errorf("duplicateVoteEvidence FAILED SANITY CHECK - address (%X) doesn't match pubkey (%v - %X)",
|
||||
addr, pubKey, pubKey.Address())
|
||||
}
|
||||
|
||||
// Signatures must be valid
|
||||
if !pubKey.VerifyBytes(dve.VoteA.SignBytes(chainID), dve.VoteA.Signature) {
|
||||
return fmt.Errorf("DuplicateVoteEvidence Error verifying VoteA: %v", ErrVoteInvalidSignature)
|
||||
return fmt.Errorf("duplicateVoteEvidence Error verifying VoteA: %v", ErrVoteInvalidSignature)
|
||||
}
|
||||
if !pubKey.VerifyBytes(dve.VoteB.SignBytes(chainID), dve.VoteB.Signature) {
|
||||
return fmt.Errorf("DuplicateVoteEvidence Error verifying VoteB: %v", ErrVoteInvalidSignature)
|
||||
return fmt.Errorf("duplicateVoteEvidence Error verifying VoteB: %v", ErrVoteInvalidSignature)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -198,16 +198,16 @@ func (dve *DuplicateVoteEvidence) Equal(ev Evidence) bool {
|
||||
// ValidateBasic performs basic validation.
|
||||
func (dve *DuplicateVoteEvidence) ValidateBasic() error {
|
||||
if len(dve.PubKey.Bytes()) == 0 {
|
||||
return errors.New("Empty PubKey")
|
||||
return errors.New("empty PubKey")
|
||||
}
|
||||
if dve.VoteA == nil || dve.VoteB == nil {
|
||||
return fmt.Errorf("One or both of the votes are empty %v, %v", dve.VoteA, dve.VoteB)
|
||||
return fmt.Errorf("one or both of the votes are empty %v, %v", dve.VoteA, dve.VoteB)
|
||||
}
|
||||
if err := dve.VoteA.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Invalid VoteA: %v", err)
|
||||
return fmt.Errorf("invalid VoteA: %v", err)
|
||||
}
|
||||
if err := dve.VoteB.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Invalid VoteB: %v", err)
|
||||
return fmt.Errorf("invalid VoteB: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -271,7 +271,7 @@ type MockBadEvidence struct {
|
||||
}
|
||||
|
||||
func (e MockBadEvidence) Verify(chainID string, pubKey crypto.PubKey) error {
|
||||
return fmt.Errorf("MockBadEvidence")
|
||||
return fmt.Errorf("mockBadEvidence")
|
||||
}
|
||||
func (e MockBadEvidence) Equal(ev Evidence) bool {
|
||||
e2 := ev.(MockBadEvidence)
|
||||
|
||||
+3
-3
@@ -66,7 +66,7 @@ func (genDoc *GenesisDoc) ValidatorHash() []byte {
|
||||
// and fills in defaults for optional fields left empty
|
||||
func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
||||
if genDoc.ChainID == "" {
|
||||
return errors.New("Genesis doc must include non-empty chain_id")
|
||||
return errors.New("genesis doc must include non-empty chain_id")
|
||||
}
|
||||
if len(genDoc.ChainID) > MaxChainIDLen {
|
||||
return errors.Errorf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
|
||||
@@ -80,10 +80,10 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
||||
|
||||
for i, v := range genDoc.Validators {
|
||||
if v.Power == 0 {
|
||||
return errors.Errorf("The genesis file cannot contain validators with no voting power: %v", v)
|
||||
return errors.Errorf("the genesis file cannot contain validators with no voting power: %v", v)
|
||||
}
|
||||
if len(v.Address) > 0 && !bytes.Equal(v.PubKey.Address(), v.Address) {
|
||||
return errors.Errorf("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
|
||||
return errors.Errorf("incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
|
||||
}
|
||||
if len(v.Address) == 0 {
|
||||
genDoc.Validators[i].Address = v.PubKey.Address()
|
||||
|
||||
+5
-5
@@ -100,26 +100,26 @@ func (params *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool {
|
||||
// allowed limits, and returns an error if they are not.
|
||||
func (params *ConsensusParams) Validate() error {
|
||||
if params.Block.MaxBytes <= 0 {
|
||||
return errors.Errorf("Block.MaxBytes must be greater than 0. Got %d",
|
||||
return errors.Errorf("block.MaxBytes must be greater than 0. Got %d",
|
||||
params.Block.MaxBytes)
|
||||
}
|
||||
if params.Block.MaxBytes > MaxBlockSizeBytes {
|
||||
return errors.Errorf("Block.MaxBytes is too big. %d > %d",
|
||||
return errors.Errorf("block.MaxBytes is too big. %d > %d",
|
||||
params.Block.MaxBytes, MaxBlockSizeBytes)
|
||||
}
|
||||
|
||||
if params.Block.MaxGas < -1 {
|
||||
return errors.Errorf("Block.MaxGas must be greater or equal to -1. Got %d",
|
||||
return errors.Errorf("block.MaxGas must be greater or equal to -1. Got %d",
|
||||
params.Block.MaxGas)
|
||||
}
|
||||
|
||||
if params.Block.TimeIotaMs <= 0 {
|
||||
return errors.Errorf("Block.TimeIotaMs must be greater than 0. Got %v",
|
||||
return errors.Errorf("block.TimeIotaMs must be greater than 0. Got %v",
|
||||
params.Block.TimeIotaMs)
|
||||
}
|
||||
|
||||
if params.Evidence.MaxAge <= 0 {
|
||||
return errors.Errorf("EvidenceParams.MaxAge must be greater than 0. Got %d",
|
||||
return errors.Errorf("evidenceParams.MaxAge must be greater than 0. Got %d",
|
||||
params.Evidence.MaxAge)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -13,8 +13,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPartSetUnexpectedIndex = errors.New("Error part set unexpected index")
|
||||
ErrPartSetInvalidProof = errors.New("Error part set invalid proof")
|
||||
ErrPartSetUnexpectedIndex = errors.New("error part set unexpected index")
|
||||
ErrPartSetInvalidProof = errors.New("error part set invalid proof")
|
||||
)
|
||||
|
||||
type Part struct {
|
||||
@@ -74,7 +74,7 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
|
||||
// ValidateBasic performs basic validation.
|
||||
func (psh PartSetHeader) ValidateBasic() error {
|
||||
if psh.Total < 0 {
|
||||
return errors.New("Negative Total")
|
||||
return errors.New("negative Total")
|
||||
}
|
||||
// Hash can be empty in case of POLBlockID.PartsHeader in Proposal.
|
||||
if err := ValidateHash(psh.Hash); err != nil {
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestBasicPartSet(t *testing.T) {
|
||||
//t.Logf("\n%v", part)
|
||||
added, err := partSet2.AddPart(part)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Failed to add part %v, error: %v", i, err)
|
||||
t.Errorf("failed to add part %v, error: %v", i, err)
|
||||
}
|
||||
}
|
||||
// adding part with invalid index
|
||||
@@ -73,7 +73,7 @@ func TestWrongProof(t *testing.T) {
|
||||
part.Proof.Aunts[0][0] += byte(0x01)
|
||||
added, err := partSet2.AddPart(part)
|
||||
if added || err == nil {
|
||||
t.Errorf("Expected to fail adding a part with bad trail.")
|
||||
t.Errorf("expected to fail adding a part with bad trail.")
|
||||
}
|
||||
|
||||
// Test adding a part with wrong bytes.
|
||||
@@ -81,7 +81,7 @@ func TestWrongProof(t *testing.T) {
|
||||
part.Bytes[0] += byte(0x01)
|
||||
added, err = partSet2.AddPart(part)
|
||||
if added || err == nil {
|
||||
t.Errorf("Expected to fail adding a part with bad bytes.")
|
||||
t.Errorf("expected to fail adding a part with bad bytes.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -10,8 +10,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
|
||||
ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
|
||||
ErrInvalidBlockPartSignature = errors.New("error invalid block part signature")
|
||||
ErrInvalidBlockPartHash = errors.New("error invalid block part hash")
|
||||
)
|
||||
|
||||
// Proposal defines a block proposal for the consensus.
|
||||
@@ -46,32 +46,32 @@ func NewProposal(height int64, round int, polRound int, blockID BlockID) *Propos
|
||||
// ValidateBasic performs basic validation.
|
||||
func (p *Proposal) ValidateBasic() error {
|
||||
if p.Type != ProposalType {
|
||||
return errors.New("Invalid Type")
|
||||
return errors.New("invalid Type")
|
||||
}
|
||||
if p.Height < 0 {
|
||||
return errors.New("Negative Height")
|
||||
return errors.New("negative Height")
|
||||
}
|
||||
if p.Round < 0 {
|
||||
return errors.New("Negative Round")
|
||||
return errors.New("negative Round")
|
||||
}
|
||||
if p.POLRound < -1 {
|
||||
return errors.New("Negative POLRound (exception: -1)")
|
||||
return errors.New("negative POLRound (exception: -1)")
|
||||
}
|
||||
if err := p.BlockID.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Wrong BlockID: %v", err)
|
||||
return fmt.Errorf("wrong BlockID: %v", err)
|
||||
}
|
||||
// ValidateBasic above would pass even if the BlockID was empty:
|
||||
if !p.BlockID.IsComplete() {
|
||||
return fmt.Errorf("Expected a complete, non-empty BlockID, got: %v", p.BlockID)
|
||||
return fmt.Errorf("expected a complete, non-empty BlockID, got: %v", p.BlockID)
|
||||
}
|
||||
|
||||
// NOTE: Timestamp validation is subtle and handled elsewhere.
|
||||
|
||||
if len(p.Signature) == 0 {
|
||||
return errors.New("Signature is missing")
|
||||
return errors.New("signature is missing")
|
||||
}
|
||||
if len(p.Signature) > MaxSignatureSize {
|
||||
return fmt.Errorf("Signature is too big (max: %d)", MaxSignatureSize)
|
||||
return fmt.Errorf("signature is too big (max: %d)", MaxSignatureSize)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestProposalString(t *testing.T) {
|
||||
str := testProposal.String()
|
||||
expected := `Proposal{12345/23456 (010203:111:626C6F636B70, -1) 000000000000 @ 2018-02-11T07:09:22.765Z}`
|
||||
if str != expected {
|
||||
t.Errorf("Got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str)
|
||||
t.Errorf("got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -188,7 +188,7 @@ func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
|
||||
switch pubKey.Type {
|
||||
case ABCIPubKeyTypeEd25519:
|
||||
if len(pubKey.Data) != ed25519.PubKeyEd25519Size {
|
||||
return nil, fmt.Errorf("Invalid size for PubKeyEd25519. Got %d, expected %d",
|
||||
return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d",
|
||||
len(pubKey.Data), ed25519.PubKeyEd25519Size)
|
||||
}
|
||||
var pk ed25519.PubKeyEd25519
|
||||
@@ -196,14 +196,14 @@ func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
|
||||
return pk, nil
|
||||
case ABCIPubKeyTypeSecp256k1:
|
||||
if len(pubKey.Data) != secp256k1.PubKeySecp256k1Size {
|
||||
return nil, fmt.Errorf("Invalid size for PubKeySecp256k1. Got %d, expected %d",
|
||||
return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d",
|
||||
len(pubKey.Data), secp256k1.PubKeySecp256k1Size)
|
||||
}
|
||||
var pk secp256k1.PubKeySecp256k1
|
||||
copy(pk[:], pubKey.Data)
|
||||
return pk, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("Unknown pubkey type %v", pubKey.Type)
|
||||
return nil, fmt.Errorf("unknown pubkey type %v", pubKey.Type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -97,17 +97,17 @@ func (tp TxProof) Leaf() []byte {
|
||||
// and if the proof is internally consistent. Otherwise, it returns a sensible error.
|
||||
func (tp TxProof) Validate(dataHash []byte) error {
|
||||
if !bytes.Equal(dataHash, tp.RootHash) {
|
||||
return errors.New("Proof matches different data hash")
|
||||
return errors.New("proof matches different data hash")
|
||||
}
|
||||
if tp.Proof.Index < 0 {
|
||||
return errors.New("Proof index cannot be negative")
|
||||
return errors.New("proof index cannot be negative")
|
||||
}
|
||||
if tp.Proof.Total <= 0 {
|
||||
return errors.New("Proof total must be positive")
|
||||
return errors.New("proof total must be positive")
|
||||
}
|
||||
valid := tp.Proof.Verify(tp.RootHash, tp.Leaf())
|
||||
if valid != nil {
|
||||
return errors.New("Proof is not internally consistent")
|
||||
return errors.New("proof is not internally consistent")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ func ValidateTime(t time.Time) error {
|
||||
oneYear = 8766 * time.Hour
|
||||
)
|
||||
if t.Before(now.Add(-oneYear)) || t.After(now.Add(oneYear)) {
|
||||
return fmt.Errorf("Time drifted too much. Expected: -1 < %v < 1 year", now)
|
||||
return fmt.Errorf("time drifted too much. Expected: -1 < %v < 1 year", now)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func ValidateTime(t time.Time) error {
|
||||
// size != tmhash.Size.
|
||||
func ValidateHash(h []byte) error {
|
||||
if len(h) > 0 && len(h) != tmhash.Size {
|
||||
return fmt.Errorf("Expected size to be %d bytes, got %d bytes",
|
||||
return fmt.Errorf("expected size to be %d bytes, got %d bytes",
|
||||
tmhash.Size,
|
||||
len(h),
|
||||
)
|
||||
|
||||
@@ -605,7 +605,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height i
|
||||
return NewErrInvalidCommitHeight(height, commit.Height())
|
||||
}
|
||||
if !blockID.Equals(commit.BlockID) {
|
||||
return fmt.Errorf("Invalid commit -- wrong block id: want %v got %v",
|
||||
return fmt.Errorf("invalid commit -- wrong block id: want %v got %v",
|
||||
blockID, commit.BlockID)
|
||||
}
|
||||
|
||||
@@ -619,7 +619,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height i
|
||||
// Validate signature.
|
||||
precommitSignBytes := commit.VoteSignBytes(chainID, idx)
|
||||
if !val.PubKey.VerifyBytes(precommitSignBytes, precommit.Signature) {
|
||||
return fmt.Errorf("Invalid commit -- invalid signature: %v", precommit)
|
||||
return fmt.Errorf("invalid commit -- invalid signature: %v", precommit)
|
||||
}
|
||||
// Good precommit!
|
||||
if blockID.Equals(precommit.BlockID) {
|
||||
@@ -686,13 +686,13 @@ func (vals *ValidatorSet) VerifyFutureCommit(newSet *ValidatorSet, chainID strin
|
||||
continue
|
||||
}
|
||||
if precommit.Height != height {
|
||||
return errors.Errorf("Blocks don't match - %d vs %d", round, precommit.Round)
|
||||
return errors.Errorf("blocks don't match - %d vs %d", round, precommit.Round)
|
||||
}
|
||||
if precommit.Round != round {
|
||||
return errors.Errorf("Invalid commit -- wrong round: %v vs %v", round, precommit.Round)
|
||||
return errors.Errorf("invalid commit -- wrong round: %v vs %v", round, precommit.Round)
|
||||
}
|
||||
if precommit.Type != PrecommitType {
|
||||
return errors.Errorf("Invalid commit -- not precommit @ index %v", idx)
|
||||
return errors.Errorf("invalid commit -- not precommit @ index %v", idx)
|
||||
}
|
||||
// See if this validator is in oldVals.
|
||||
oldIdx, val := oldVals.GetByAddress(precommit.ValidatorAddress)
|
||||
@@ -704,7 +704,7 @@ func (vals *ValidatorSet) VerifyFutureCommit(newSet *ValidatorSet, chainID strin
|
||||
// Validate signature.
|
||||
precommitSignBytes := commit.VoteSignBytes(chainID, idx)
|
||||
if !val.PubKey.VerifyBytes(precommitSignBytes, precommit.Signature) {
|
||||
return errors.Errorf("Invalid commit -- invalid signature: %v", precommit)
|
||||
return errors.Errorf("invalid commit -- invalid signature: %v", precommit)
|
||||
}
|
||||
// Good precommit!
|
||||
if blockID.Equals(precommit.BlockID) {
|
||||
|
||||
@@ -141,7 +141,7 @@ func TestProposerSelection1(t *testing.T) {
|
||||
` foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo` +
|
||||
` foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo`
|
||||
if expected != strings.Join(proposers, " ") {
|
||||
t.Errorf("Expected sequence of proposers was\n%v\nbut got \n%v", expected, strings.Join(proposers, " "))
|
||||
t.Errorf("expected sequence of proposers was\n%v\nbut got \n%v", expected, strings.Join(proposers, " "))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,16 +322,16 @@ func randValidatorSet(numValidators int) *ValidatorSet {
|
||||
return NewValidatorSet(validators)
|
||||
}
|
||||
|
||||
func (valSet *ValidatorSet) toBytes() []byte {
|
||||
bz, err := cdc.MarshalBinaryLengthPrefixed(valSet)
|
||||
func (vals *ValidatorSet) toBytes() []byte {
|
||||
bz, err := cdc.MarshalBinaryLengthPrefixed(vals)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bz
|
||||
}
|
||||
|
||||
func (valSet *ValidatorSet) fromBytes(b []byte) {
|
||||
err := cdc.UnmarshalBinaryLengthPrefixed(b, &valSet)
|
||||
func (vals *ValidatorSet) fromBytes(b []byte) {
|
||||
err := cdc.UnmarshalBinaryLengthPrefixed(b, &vals)
|
||||
if err != nil {
|
||||
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
||||
panic(err)
|
||||
|
||||
+16
-16
@@ -17,13 +17,13 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrVoteUnexpectedStep = errors.New("Unexpected step")
|
||||
ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index")
|
||||
ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address")
|
||||
ErrVoteInvalidSignature = errors.New("Invalid signature")
|
||||
ErrVoteInvalidBlockHash = errors.New("Invalid block hash")
|
||||
ErrVoteNonDeterministicSignature = errors.New("Non-deterministic signature")
|
||||
ErrVoteNil = errors.New("Nil vote")
|
||||
ErrVoteUnexpectedStep = errors.New("unexpected step")
|
||||
ErrVoteInvalidValidatorIndex = errors.New("invalid validator index")
|
||||
ErrVoteInvalidValidatorAddress = errors.New("invalid validator address")
|
||||
ErrVoteInvalidSignature = errors.New("invalid signature")
|
||||
ErrVoteInvalidBlockHash = errors.New("invalid block hash")
|
||||
ErrVoteNonDeterministicSignature = errors.New("non-deterministic signature")
|
||||
ErrVoteNil = errors.New("nil vote")
|
||||
)
|
||||
|
||||
type ErrVoteConflictingVotes struct {
|
||||
@@ -124,39 +124,39 @@ func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error {
|
||||
// ValidateBasic performs basic validation.
|
||||
func (vote *Vote) ValidateBasic() error {
|
||||
if !IsVoteTypeValid(vote.Type) {
|
||||
return errors.New("Invalid Type")
|
||||
return errors.New("invalid Type")
|
||||
}
|
||||
if vote.Height < 0 {
|
||||
return errors.New("Negative Height")
|
||||
return errors.New("negative Height")
|
||||
}
|
||||
if vote.Round < 0 {
|
||||
return errors.New("Negative Round")
|
||||
return errors.New("negative Round")
|
||||
}
|
||||
|
||||
// NOTE: Timestamp validation is subtle and handled elsewhere.
|
||||
|
||||
if err := vote.BlockID.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("Wrong BlockID: %v", err)
|
||||
return fmt.Errorf("wrong BlockID: %v", err)
|
||||
}
|
||||
// BlockID.ValidateBasic would not err if we for instance have an empty hash but a
|
||||
// non-empty PartsSetHeader:
|
||||
if !vote.BlockID.IsZero() && !vote.BlockID.IsComplete() {
|
||||
return fmt.Errorf("BlockID must be either empty or complete, got: %v", vote.BlockID)
|
||||
return fmt.Errorf("blockID must be either empty or complete, got: %v", vote.BlockID)
|
||||
}
|
||||
if len(vote.ValidatorAddress) != crypto.AddressSize {
|
||||
return fmt.Errorf("Expected ValidatorAddress size to be %d bytes, got %d bytes",
|
||||
return fmt.Errorf("expected ValidatorAddress size to be %d bytes, got %d bytes",
|
||||
crypto.AddressSize,
|
||||
len(vote.ValidatorAddress),
|
||||
)
|
||||
}
|
||||
if vote.ValidatorIndex < 0 {
|
||||
return errors.New("Negative ValidatorIndex")
|
||||
return errors.New("negative ValidatorIndex")
|
||||
}
|
||||
if len(vote.Signature) == 0 {
|
||||
return errors.New("Signature is missing")
|
||||
return errors.New("signature is missing")
|
||||
}
|
||||
if len(vote.Signature) > MaxSignatureSize {
|
||||
return fmt.Errorf("Signature is too big (max: %d)", MaxSignatureSize)
|
||||
return fmt.Errorf("signature is too big (max: %d)", MaxSignatureSize)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -314,7 +314,7 @@ func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID BlockID) error {
|
||||
if existing.Equals(blockID) {
|
||||
return nil // Nothing to do
|
||||
}
|
||||
return fmt.Errorf("SetPeerMaj23: Received conflicting blockID from peer %v. Got %v, expected %v",
|
||||
return fmt.Errorf("setPeerMaj23: Received conflicting blockID from peer %v. Got %v, expected %v",
|
||||
peerID, blockID, existing)
|
||||
}
|
||||
voteSet.peerMaj23s[peerID] = blockID
|
||||
|
||||
+40
-40
@@ -75,14 +75,14 @@ func TestAddVote(t *testing.T) {
|
||||
|
||||
val0Addr := val0.GetPubKey().Address()
|
||||
if voteSet.GetByAddress(val0Addr) != nil {
|
||||
t.Errorf("Expected GetByAddress(val0.Address) to be nil")
|
||||
t.Errorf("expected GetByAddress(val0.Address) to be nil")
|
||||
}
|
||||
if voteSet.BitArray().GetIndex(0) {
|
||||
t.Errorf("Expected BitArray.GetIndex(0) to be false")
|
||||
t.Errorf("expected BitArray.GetIndex(0) to be false")
|
||||
}
|
||||
blockID, ok := voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority")
|
||||
t.Errorf("there should be no 2/3 majority")
|
||||
}
|
||||
|
||||
vote := &Vote{
|
||||
@@ -100,14 +100,14 @@ func TestAddVote(t *testing.T) {
|
||||
}
|
||||
|
||||
if voteSet.GetByAddress(val0Addr) == nil {
|
||||
t.Errorf("Expected GetByAddress(val0.Address) to be present")
|
||||
t.Errorf("expected GetByAddress(val0.Address) to be present")
|
||||
}
|
||||
if !voteSet.BitArray().GetIndex(0) {
|
||||
t.Errorf("Expected BitArray.GetIndex(0) to be true")
|
||||
t.Errorf("expected BitArray.GetIndex(0) to be true")
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority")
|
||||
t.Errorf("there should be no 2/3 majority")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func Test2_3Majority(t *testing.T) {
|
||||
}
|
||||
blockID, ok := voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority")
|
||||
t.Errorf("there should be no 2/3 majority")
|
||||
}
|
||||
|
||||
// 7th validator voted for some blockhash
|
||||
@@ -148,7 +148,7 @@ func Test2_3Majority(t *testing.T) {
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority")
|
||||
t.Errorf("there should be no 2/3 majority")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ func Test2_3Majority(t *testing.T) {
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if !ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be 2/3 majority for nil")
|
||||
t.Errorf("there should be 2/3 majority for nil")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
}
|
||||
blockID, ok := voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority")
|
||||
t.Errorf("there should be no 2/3 majority")
|
||||
}
|
||||
|
||||
// 67th validator voted for nil
|
||||
@@ -209,7 +209,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority: last vote added was nil")
|
||||
t.Errorf("there should be no 2/3 majority: last vote added was nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Hash")
|
||||
t.Errorf("there should be no 2/3 majority: last vote added had different PartSetHeader Hash")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Total")
|
||||
t.Errorf("there should be no 2/3 majority: last vote added had different PartSetHeader Total")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if ok || !blockID.IsZero() {
|
||||
t.Errorf("There should be no 2/3 majority: last vote added had different BlockHash")
|
||||
t.Errorf("there should be no 2/3 majority: last vote added had different BlockHash")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
}
|
||||
blockID, ok = voteSet.TwoThirdsMajority()
|
||||
if !ok || !blockID.Equals(BlockID{blockHash, blockPartsHeader}) {
|
||||
t.Errorf("There should be 2/3 majority")
|
||||
t.Errorf("there should be 2/3 majority")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func TestBadVotes(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 0)
|
||||
added, err := signAddVote(privValidators[0], vote, voteSet)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Expected VoteSet.Add to succeed")
|
||||
t.Errorf("expected VoteSet.Add to succeed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ func TestBadVotes(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 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.")
|
||||
t.Errorf("expected VoteSet.Add to fail, conflicting vote.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ func TestBadVotes(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 1)
|
||||
added, err := signAddVote(privValidators[1], withHeight(vote, height+1), voteSet)
|
||||
if added || err == nil {
|
||||
t.Errorf("Expected VoteSet.Add to fail, wrong height")
|
||||
t.Errorf("expected VoteSet.Add to fail, wrong height")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ func TestBadVotes(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 2)
|
||||
added, err := signAddVote(privValidators[2], withRound(vote, round+1), voteSet)
|
||||
if added || err == nil {
|
||||
t.Errorf("Expected VoteSet.Add to fail, wrong round")
|
||||
t.Errorf("expected VoteSet.Add to fail, wrong round")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ func TestBadVotes(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 3)
|
||||
added, err := signAddVote(privValidators[3], withType(vote, byte(PrecommitType)), voteSet)
|
||||
if added || err == nil {
|
||||
t.Errorf("Expected VoteSet.Add to fail, wrong type")
|
||||
t.Errorf("expected VoteSet.Add to fail, wrong type")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -359,7 +359,7 @@ func TestConflicts(t *testing.T) {
|
||||
vote := withValidator(voteProto, val0Addr, 0)
|
||||
added, err := signAddVote(privValidators[0], vote, voteSet)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Expected VoteSet.Add to succeed")
|
||||
t.Errorf("expected VoteSet.Add to succeed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,10 +368,10 @@ func TestConflicts(t *testing.T) {
|
||||
vote := withValidator(voteProto, val0Addr, 0)
|
||||
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet)
|
||||
if added {
|
||||
t.Errorf("Expected VoteSet.Add to fail, conflicting vote.")
|
||||
t.Errorf("expected VoteSet.Add to fail, conflicting vote.")
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Expected VoteSet.Add to return error, conflicting vote.")
|
||||
t.Errorf("expected VoteSet.Add to return error, conflicting vote.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,10 +383,10 @@ func TestConflicts(t *testing.T) {
|
||||
vote := withValidator(voteProto, val0Addr, 0)
|
||||
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet)
|
||||
if !added {
|
||||
t.Errorf("Expected VoteSet.Add to succeed, called SetPeerMaj23().")
|
||||
t.Errorf("expected VoteSet.Add to succeed, called SetPeerMaj23().")
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Expected VoteSet.Add to return error, conflicting vote.")
|
||||
t.Errorf("expected VoteSet.Add to return error, conflicting vote.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,10 +398,10 @@ func TestConflicts(t *testing.T) {
|
||||
vote := withValidator(voteProto, val0Addr, 0)
|
||||
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash2), voteSet)
|
||||
if added {
|
||||
t.Errorf("Expected VoteSet.Add to fail, duplicate SetPeerMaj23() from peerA")
|
||||
t.Errorf("expected VoteSet.Add to fail, duplicate SetPeerMaj23() from peerA")
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Expected VoteSet.Add to return error, conflicting vote.")
|
||||
t.Errorf("expected VoteSet.Add to return error, conflicting vote.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,16 +411,16 @@ func TestConflicts(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 1)
|
||||
added, err := signAddVote(privValidators[1], withBlockHash(vote, blockHash1), voteSet)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Expected VoteSet.Add to succeed")
|
||||
t.Errorf("expected VoteSet.Add to succeed")
|
||||
}
|
||||
}
|
||||
|
||||
// check
|
||||
if voteSet.HasTwoThirdsMajority() {
|
||||
t.Errorf("We shouldn't have 2/3 majority yet")
|
||||
t.Errorf("we shouldn't have 2/3 majority yet")
|
||||
}
|
||||
if voteSet.HasTwoThirdsAny() {
|
||||
t.Errorf("We shouldn't have 2/3 if any votes yet")
|
||||
t.Errorf("we shouldn't have 2/3 if any votes yet")
|
||||
}
|
||||
|
||||
// val2 votes for blockHash2.
|
||||
@@ -429,16 +429,16 @@ func TestConflicts(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 2)
|
||||
added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash2), voteSet)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Expected VoteSet.Add to succeed")
|
||||
t.Errorf("expected VoteSet.Add to succeed")
|
||||
}
|
||||
}
|
||||
|
||||
// check
|
||||
if voteSet.HasTwoThirdsMajority() {
|
||||
t.Errorf("We shouldn't have 2/3 majority yet")
|
||||
t.Errorf("we shouldn't have 2/3 majority yet")
|
||||
}
|
||||
if !voteSet.HasTwoThirdsAny() {
|
||||
t.Errorf("We should have 2/3 if any votes")
|
||||
t.Errorf("we should have 2/3 if any votes")
|
||||
}
|
||||
|
||||
// now attempt tracking blockHash1
|
||||
@@ -450,23 +450,23 @@ func TestConflicts(t *testing.T) {
|
||||
vote := withValidator(voteProto, addr, 2)
|
||||
added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash1), voteSet)
|
||||
if !added {
|
||||
t.Errorf("Expected VoteSet.Add to succeed")
|
||||
t.Errorf("expected VoteSet.Add to succeed")
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Expected VoteSet.Add to return error, conflicting vote")
|
||||
t.Errorf("expected VoteSet.Add to return error, conflicting vote")
|
||||
}
|
||||
}
|
||||
|
||||
// check
|
||||
if !voteSet.HasTwoThirdsMajority() {
|
||||
t.Errorf("We should have 2/3 majority for blockHash1")
|
||||
t.Errorf("we should have 2/3 majority for blockHash1")
|
||||
}
|
||||
blockIDMaj23, _ := voteSet.TwoThirdsMajority()
|
||||
if !bytes.Equal(blockIDMaj23.Hash, blockHash1) {
|
||||
t.Errorf("Got the wrong 2/3 majority blockhash")
|
||||
t.Errorf("got the wrong 2/3 majority blockhash")
|
||||
}
|
||||
if !voteSet.HasTwoThirdsAny() {
|
||||
t.Errorf("We should have 2/3 if any votes")
|
||||
t.Errorf("we should have 2/3 if any votes")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -526,12 +526,12 @@ func TestMakeCommit(t *testing.T) {
|
||||
|
||||
// Commit should have 10 elements
|
||||
if len(commit.Precommits) != 10 {
|
||||
t.Errorf("Commit Precommits should have the same number of precommits as validators")
|
||||
t.Errorf("commit Precommits should have the same number of precommits as validators")
|
||||
}
|
||||
|
||||
// Ensure that Commit precommits are ordered.
|
||||
if err := commit.ValidateBasic(); err != nil {
|
||||
t.Errorf("Error in Commit.ValidateBasic(): %v", err)
|
||||
t.Errorf("error in Commit.ValidateBasic(): %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -199,7 +199,7 @@ func TestIsVoteTypeValid(t *testing.T) {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(st *testing.T) {
|
||||
if rs := IsVoteTypeValid(tt.in); rs != tt.out {
|
||||
t.Errorf("Got unexpected Vote type. Expected:\n%v\nGot:\n%v", rs, tt.out)
|
||||
t.Errorf("got unexpected Vote type. Expected:\n%v\nGot:\n%v", rs, tt.out)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -258,13 +258,13 @@ func TestVoteString(t *testing.T) {
|
||||
str := examplePrecommit().String()
|
||||
expected := `Vote{56789:6AF1F4111082 12345/02/2(Precommit) 8B01023386C3 000000000000 @ 2017-12-25T03:00:01.234Z}`
|
||||
if str != expected {
|
||||
t.Errorf("Got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str)
|
||||
t.Errorf("got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str)
|
||||
}
|
||||
|
||||
str2 := examplePrevote().String()
|
||||
expected = `Vote{56789:6AF1F4111082 12345/02/1(Prevote) 8B01023386C3 000000000000 @ 2017-12-25T03:00:01.234Z}`
|
||||
if str2 != expected {
|
||||
t.Errorf("Got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str2)
|
||||
t.Errorf("got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user