node_announcement_test.go 840 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package lnwire
  2. import "testing"
  3. // TestNodeAliasValidation tests that the NewNodeAlias method will only accept
  4. // valid node announcements.
  5. func TestNodeAliasValidation(t *testing.T) {
  6. t.Parallel()
  7. var testCases = []struct {
  8. alias string
  9. valid bool
  10. }{
  11. // UTF-8 alias with valid length.
  12. {
  13. alias: "meruem",
  14. valid: true,
  15. },
  16. // UTF-8 alias with invalid length.
  17. {
  18. alias: "p3kysxqr23swl33m6h5grmzddgw5nsgkky3g52zc6frpwz",
  19. valid: false,
  20. },
  21. // String with non UTF-8 characters.
  22. {
  23. alias: "\xE0\x80\x80",
  24. valid: false,
  25. },
  26. }
  27. for i, testCase := range testCases {
  28. _, err := NewNodeAlias(testCase.alias)
  29. switch {
  30. case err != nil && testCase.valid:
  31. t.Fatalf("#%v: alias should have been invalid", i)
  32. case err == nil && !testCase.valid:
  33. t.Fatalf("#%v: invalid alias was missed", i)
  34. }
  35. }
  36. }