nns: allow hyphen in domain names

Port https://github.com/nspcc-dev/neofs-contract/pull/183.
This commit is contained in:
Anna Shaleva 2022-09-05 17:30:43 +03:00
parent ce66610369
commit e97467726c
2 changed files with 12 additions and 4 deletions

View file

@ -507,6 +507,8 @@ func checkCommittee() {
}
// checkFragment validates root or a part of domain name.
// 1. Root domain must start with a letter.
// 2. All other fragments must start and end in a letter or a digit.
func checkFragment(v string, isRoot bool) bool {
maxLength := maxDomainNameFragmentLength
if isRoot {
@ -525,12 +527,12 @@ func checkFragment(v string, isRoot bool) bool {
return false
}
}
for i := 1; i < len(v); i++ {
if !isAlNum(v[i]) {
for i := 1; i < len(v)-1; i++ {
if v[i] != '-' && !isAlNum(v[i]) {
return false
}
}
return true
return isAlNum(v[len(v)-1])
}
// isAlNum checks whether provided char is a lowercase letter or a number.

View file

@ -173,11 +173,17 @@ func TestRegisterAndRenew(t *testing.T) {
c.Invoke(t, false, "register", "neo.com", e.CommitteeHash)
c.Invoke(t, false, "isAvailable", "neo.com")
t.Run("domain names with hyphen", func(t *testing.T) {
c.InvokeFail(t, "invalid domain name format", "register", "-testdomain.com", e.CommitteeHash)
c.InvokeFail(t, "invalid domain name format", "register", "testdomain-.com", e.CommitteeHash)
c.Invoke(t, true, "register", "test-domain.com", e.CommitteeHash)
})
props := stackitem.NewMap()
props.Add(stackitem.Make("name"), stackitem.Make("neo.com"))
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))
c.Invoke(t, props, "properties", "neo.com")
c.Invoke(t, 2, "balanceOf", e.CommitteeHash)
c.Invoke(t, 3, "balanceOf", e.CommitteeHash)
c.Invoke(t, e.CommitteeHash.BytesBE(), "ownerOf", []byte("neo.com"))
t.Run("invalid token ID", func(t *testing.T) {