|
|
- package blockchain
-
- import (
- "testing"
-
- "github.com/stretchr/testify/assert"
- bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"
- )
-
- func TestBcBlockRequestMessageValidateBasic(t *testing.T) {
- testCases := []struct {
- testName string
- requestHeight int64
- expectErr bool
- }{
- {"Valid Request Message", 0, false},
- {"Valid Request Message", 1, false},
- {"Invalid Request Message", -1, true},
- }
-
- for _, tc := range testCases {
- tc := tc
- t.Run(tc.testName, func(t *testing.T) {
- request := bcproto.BlockRequest{Height: tc.requestHeight}
- assert.Equal(t, tc.expectErr, ValidateMsg(&request) != nil, "Validate Basic had an unexpected result")
- })
- }
- }
-
- func TestBcNoBlockResponseMessageValidateBasic(t *testing.T) {
- testCases := []struct {
- testName string
- nonResponseHeight int64
- expectErr bool
- }{
- {"Valid Non-Response Message", 0, false},
- {"Valid Non-Response Message", 1, false},
- {"Invalid Non-Response Message", -1, true},
- }
-
- for _, tc := range testCases {
- tc := tc
- t.Run(tc.testName, func(t *testing.T) {
- nonResponse := bcproto.NoBlockResponse{Height: tc.nonResponseHeight}
- assert.Equal(t, tc.expectErr, ValidateMsg(&nonResponse) != nil, "Validate Basic had an unexpected result")
- })
- }
- }
-
- func TestBcStatusRequestMessageValidateBasic(t *testing.T) {
- testCases := []struct {
- testName string
- requestHeight int64
- expectErr bool
- }{
- {"Valid Request Message", 0, false},
- {"Valid Request Message", 1, false},
- {"Invalid Request Message", -1, true},
- }
-
- for _, tc := range testCases {
- tc := tc
- t.Run(tc.testName, func(t *testing.T) {
- request := bcproto.StatusRequest{Height: tc.requestHeight}
- assert.Equal(t, tc.expectErr, ValidateMsg(&request) != nil, "Validate Basic had an unexpected result")
- })
- }
- }
-
- func TestBcStatusResponseMessageValidateBasic(t *testing.T) {
- testCases := []struct {
- testName string
- responseHeight int64
- expectErr bool
- }{
- {"Valid Response Message", 0, false},
- {"Valid Response Message", 1, false},
- {"Invalid Response Message", -1, true},
- }
-
- for _, tc := range testCases {
- tc := tc
- t.Run(tc.testName, func(t *testing.T) {
- response := bcproto.StatusResponse{Height: tc.responseHeight}
- assert.Equal(t, tc.expectErr, ValidateMsg(&response) != nil, "Validate Basic had an unexpected result")
- })
- }
- }
|