more cleanup
int
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
package commands
|
||||
|
||||
import "encoding/hex"
|
||||
|
||||
// Returns true for non-empty hex-string prefixed with "0x"
|
||||
func isHex(s string) bool {
|
||||
if len(s) > 2 && s[:2] == "0x" {
|
||||
_, err := hex.DecodeString(s[2:])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// StripHex remove the first two hex bytes
|
||||
func StripHex(s string) string {
|
||||
if isHex(s) {
|
||||
return s[2:]
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestHex(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
//test isHex
|
||||
hexNoPrefix := hex.EncodeToString([]byte("foobar"))
|
||||
hexWPrefix := "0x" + hexNoPrefix
|
||||
str := "foobar"
|
||||
strWPrefix := "0xfoobar"
|
||||
|
||||
assert.True(isHex(hexWPrefix), "isHex not identifying hex with 0x prefix")
|
||||
assert.False(isHex(hexNoPrefix), "isHex shouldn't identify hex without 0x prefix")
|
||||
assert.False(isHex(str), "isHex shouldn't identify non-hex string")
|
||||
assert.False(isHex(strWPrefix), "isHex shouldn't identify non-hex string with 0x prefix")
|
||||
assert.True(StripHex(hexWPrefix) == hexNoPrefix, "StripHex doesn't remove first two characters")
|
||||
}
|
||||
Reference in New Issue
Block a user