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.

58 lines
1.3 KiB

  1. package core
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestBlockchainInfo(t *testing.T) {
  8. cases := []struct {
  9. min, max int64
  10. height int64
  11. limit int64
  12. resultLength int64
  13. wantErr bool
  14. }{
  15. // min > max
  16. {0, 0, 0, 10, 0, true}, // min set to 1
  17. {0, 1, 0, 10, 0, true}, // max set to height (0)
  18. {0, 0, 1, 10, 1, false}, // max set to height (1)
  19. {2, 0, 1, 10, 0, true}, // max set to height (1)
  20. {2, 1, 5, 10, 0, true},
  21. // negative
  22. {1, 10, 14, 10, 10, false}, // control
  23. {-1, 10, 14, 10, 0, true},
  24. {1, -10, 14, 10, 0, true},
  25. {-9223372036854775808, -9223372036854775788, 100, 20, 0, true},
  26. // check limit and height
  27. {1, 1, 1, 10, 1, false},
  28. {1, 1, 5, 10, 1, false},
  29. {2, 2, 5, 10, 1, false},
  30. {1, 2, 5, 10, 2, false},
  31. {1, 5, 1, 10, 1, false},
  32. {1, 5, 10, 10, 5, false},
  33. {1, 15, 10, 10, 10, false},
  34. {1, 15, 15, 10, 10, false},
  35. {1, 15, 15, 20, 15, false},
  36. {1, 20, 15, 20, 15, false},
  37. {1, 20, 20, 20, 20, false},
  38. }
  39. for i, c := range cases {
  40. caseString := fmt.Sprintf("test %d failed", i)
  41. min, max, err := filterMinMax(c.height, c.min, c.max, c.limit)
  42. if c.wantErr {
  43. require.Error(t, err, caseString)
  44. } else {
  45. require.NoError(t, err, caseString)
  46. require.Equal(t, 1+max-min, c.resultLength, caseString)
  47. }
  48. }
  49. }