mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
migrates some helper functions from beacon API to apiutil (#15125)
* migration and changelog * missed valid root * removing unneeded test, more optimization * adding strict dependency * linting * fixing 1 more test * bastin's suggestion
This commit is contained in:
@@ -3,6 +3,7 @@ package bytesutil_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
||||
)
|
||||
@@ -27,3 +28,53 @@ func TestIsHex(t *testing.T) {
|
||||
assert.Equal(t, tt.b, isHex)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeHexWithLength_Root(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
valid bool
|
||||
}{
|
||||
{
|
||||
name: "correct format",
|
||||
input: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
name: "root too small",
|
||||
input: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "root too big",
|
||||
input: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f22",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "empty root",
|
||||
input: "",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "no 0x prefix",
|
||||
input: "cf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
name: "invalid characters",
|
||||
input: "0xzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := bytesutil.DecodeHexWithLength(tt.input, fieldparams.RootLength)
|
||||
if tt.valid {
|
||||
assert.NoError(t, err)
|
||||
} else {
|
||||
assert.Equal(t, true, err != nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user