Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update barnard #339

Merged
merged 8 commits into from
Dec 13, 2024
20 changes: 19 additions & 1 deletion data/esdt/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func IsValidPrefixedToken(token string) (string, bool) {
}

tokenRandSeq := tokenSplit[2]
if !(len(tokenRandSeq) >= esdtTickerNumRandChars) {
if !IsRandomSeqValid(tokenRandSeq) {
return "", false
}

Expand Down Expand Up @@ -83,3 +83,21 @@ func IsTickerValid(ticker string) bool {
func IsTokenTickerLenCorrect(tokenTickerLen int) bool {
return !(tokenTickerLen < minLengthForTickerName || tokenTickerLen > maxLengthForTickerName)
}

// IsRandomSeqValid checks if the token random sequence is valid
func IsRandomSeqValid(randomSeq string) bool {
if len(randomSeq) != esdtTickerNumRandChars {
return false
}

for _, ch := range randomSeq {
isSmallCharacter := ch >= 'a' && ch <= 'f'
isNumber := ch >= '0' && ch <= '9'
isReadable := isSmallCharacter || isNumber
if !isReadable {
return false
}
}

return true
}
10 changes: 5 additions & 5 deletions data/esdt/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import (
)

func TestIsValidPrefixedToken(t *testing.T) {
prefix, valid := IsValidPrefixedToken("sov1-TKN-coffee")
prefix, valid := IsValidPrefixedToken("sov1-TKN-c0ffee")
require.True(t, valid)
require.Equal(t, "sov1", prefix)

prefix, valid = IsValidPrefixedToken("sOv1-TKN-coffee")
prefix, valid = IsValidPrefixedToken("sOv1-TKN-c0ffee")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("sov1-TkN-coffee")
prefix, valid = IsValidPrefixedToken("sov1-TkN-c0ffee")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("sov1-TKN-coffe")
prefix, valid = IsValidPrefixedToken("sov1-TKN-c0ffe")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("sov1-TKN")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("TKN-coffee")
prefix, valid = IsValidPrefixedToken("TKN-c0ffee")
require.False(t, valid)
require.Equal(t, "", prefix)
}
Expand Down
Loading
Loading