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