ValidateBasic performs basic validation.
()
| 157 | |
| 158 | // ValidateBasic performs basic validation. |
| 159 | func (vote *Vote) ValidateBasic() error { |
| 160 | if !IsVoteTypeValid(vote.Type) { |
| 161 | return errors.New("invalid Type") |
| 162 | } |
| 163 | |
| 164 | if vote.Height < 0 { |
| 165 | return errors.New("negative Height") |
| 166 | } |
| 167 | |
| 168 | if vote.Round < 0 { |
| 169 | return errors.New("negative Round") |
| 170 | } |
| 171 | |
| 172 | // NOTE: Timestamp validation is subtle and handled elsewhere. |
| 173 | |
| 174 | if err := vote.BlockID.ValidateBasic(); err != nil { |
| 175 | return fmt.Errorf("wrong BlockID: %v", err) |
| 176 | } |
| 177 | |
| 178 | // BlockID.ValidateBasic would not err if we for instance have an empty hash but a |
| 179 | // non-empty PartsSetHeader: |
| 180 | if !vote.BlockID.IsZero() && !vote.BlockID.IsComplete() { |
| 181 | return fmt.Errorf("blockID must be either empty or complete, got: %v", vote.BlockID) |
| 182 | } |
| 183 | |
| 184 | if len(vote.ValidatorAddress) != crypto.AddressSize { |
| 185 | return fmt.Errorf("expected ValidatorAddress size to be %d bytes, got %d bytes", |
| 186 | crypto.AddressSize, |
| 187 | len(vote.ValidatorAddress), |
| 188 | ) |
| 189 | } |
| 190 | if vote.ValidatorIndex < 0 { |
| 191 | return errors.New("negative ValidatorIndex") |
| 192 | } |
| 193 | if len(vote.Signature) == 0 { |
| 194 | return errors.New("signature is missing") |
| 195 | } |
| 196 | |
| 197 | if len(vote.Signature) > MaxSignatureSize { |
| 198 | return fmt.Errorf("signature is too big (max: %d)", MaxSignatureSize) |
| 199 | } |
| 200 | |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | // ToProto converts the handwritten type to proto generated type |
| 205 | // return type, nil if everything converts safely, otherwise nil, error |
no test coverage detected