diff --git a/data/esdt/common.go b/data/esdt/common.go index d2467ec4..7d240b51 100644 --- a/data/esdt/common.go +++ b/data/esdt/common.go @@ -35,7 +35,7 @@ func IsValidPrefixedToken(token string) (string, bool) { } tokenRandSeq := tokenSplit[2] - if !(len(tokenRandSeq) >= esdtTickerNumRandChars) { + if !IsRandomSeqValid(tokenRandSeq) { return "", false } @@ -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 +} diff --git a/data/esdt/common_test.go b/data/esdt/common_test.go index 8052c23a..0e65fd9d 100644 --- a/data/esdt/common_test.go +++ b/data/esdt/common_test.go @@ -7,19 +7,19 @@ 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) @@ -27,7 +27,7 @@ func TestIsValidPrefixedToken(t *testing.T) { 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) }