You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

  1. package blockchain
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"
  6. )
  7. func TestBcBlockRequestMessageValidateBasic(t *testing.T) {
  8. testCases := []struct {
  9. testName string
  10. requestHeight int64
  11. expectErr bool
  12. }{
  13. {"Valid Request Message", 0, false},
  14. {"Valid Request Message", 1, false},
  15. {"Invalid Request Message", -1, true},
  16. }
  17. for _, tc := range testCases {
  18. tc := tc
  19. t.Run(tc.testName, func(t *testing.T) {
  20. request := bcproto.BlockRequest{Height: tc.requestHeight}
  21. assert.Equal(t, tc.expectErr, ValidateMsg(&request) != nil, "Validate Basic had an unexpected result")
  22. })
  23. }
  24. }
  25. func TestBcNoBlockResponseMessageValidateBasic(t *testing.T) {
  26. testCases := []struct {
  27. testName string
  28. nonResponseHeight int64
  29. expectErr bool
  30. }{
  31. {"Valid Non-Response Message", 0, false},
  32. {"Valid Non-Response Message", 1, false},
  33. {"Invalid Non-Response Message", -1, true},
  34. }
  35. for _, tc := range testCases {
  36. tc := tc
  37. t.Run(tc.testName, func(t *testing.T) {
  38. nonResponse := bcproto.NoBlockResponse{Height: tc.nonResponseHeight}
  39. assert.Equal(t, tc.expectErr, ValidateMsg(&nonResponse) != nil, "Validate Basic had an unexpected result")
  40. })
  41. }
  42. }
  43. func TestBcStatusRequestMessageValidateBasic(t *testing.T) {
  44. testCases := []struct {
  45. testName string
  46. requestHeight int64
  47. expectErr bool
  48. }{
  49. {"Valid Request Message", 0, false},
  50. {"Valid Request Message", 1, false},
  51. {"Invalid Request Message", -1, true},
  52. }
  53. for _, tc := range testCases {
  54. tc := tc
  55. t.Run(tc.testName, func(t *testing.T) {
  56. request := bcproto.StatusRequest{Height: tc.requestHeight}
  57. assert.Equal(t, tc.expectErr, ValidateMsg(&request) != nil, "Validate Basic had an unexpected result")
  58. })
  59. }
  60. }
  61. func TestBcStatusResponseMessageValidateBasic(t *testing.T) {
  62. testCases := []struct {
  63. testName string
  64. responseHeight int64
  65. expectErr bool
  66. }{
  67. {"Valid Response Message", 0, false},
  68. {"Valid Response Message", 1, false},
  69. {"Invalid Response Message", -1, true},
  70. }
  71. for _, tc := range testCases {
  72. tc := tc
  73. t.Run(tc.testName, func(t *testing.T) {
  74. response := bcproto.StatusResponse{Height: tc.responseHeight}
  75. assert.Equal(t, tc.expectErr, ValidateMsg(&response) != nil, "Validate Basic had an unexpected result")
  76. })
  77. }
  78. }