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.

40 lines
1.1 KiB

  1. package types
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func newConsensusParams(blockSize, partSize int) ConsensusParams {
  7. return ConsensusParams{
  8. BlockSizeParams: BlockSizeParams{MaxBytes: blockSize},
  9. BlockGossipParams: BlockGossipParams{BlockPartSizeBytes: partSize},
  10. }
  11. }
  12. func TestConsensusParamsValidation(t *testing.T) {
  13. testCases := []struct {
  14. params ConsensusParams
  15. valid bool
  16. }{
  17. {newConsensusParams(1, 1), true},
  18. {newConsensusParams(1, 0), false},
  19. {newConsensusParams(0, 1), false},
  20. {newConsensusParams(0, 0), false},
  21. {newConsensusParams(0, 10), false},
  22. {newConsensusParams(10, -1), false},
  23. {newConsensusParams(47*1024*1024, 400), true},
  24. {newConsensusParams(10, 400), true},
  25. {newConsensusParams(100*1024*1024, 400), true},
  26. {newConsensusParams(101*1024*1024, 400), false},
  27. {newConsensusParams(1024*1024*1024, 400), false},
  28. }
  29. for _, testCase := range testCases {
  30. if testCase.valid {
  31. assert.NoError(t, testCase.params.Validate(), "expected no error for valid params")
  32. } else {
  33. assert.Error(t, testCase.params.Validate(), "expected error for non valid params")
  34. }
  35. }
  36. }