Skip to content

Commit

Permalink
Fixed NewUref constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhmakAS committed Mar 25, 2024
1 parent 7f7e952 commit c021926
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/types/cl_value/uref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func Test_NewURefFromString_toBytes(t *testing.T) {
assert.Equal(t, "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f07", hex.EncodeToString(res.Bytes()))
}

func Test_NewURefFromString_IncorrectFormat(t *testing.T) {
source := "01506f4df2ac64a2233e787c430dc91dad5cee8eabd7d64555f64bdc1a4b4044d7"
_, err := key.NewURef(source)
require.Error(t, err)
assert.Equal(t, err, key.ErrIncorrectPurseFormat)
}

func Test_FromBytesByType_URef(t *testing.T) {
source := "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f07"
inBytes, err := hex.DecodeString(source)
Expand Down
8 changes: 8 additions & 0 deletions types/key/uref.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

type UrefAccess = byte

var (
ErrIncorrectPurseFormat = errors.New("incorrect uref format")
)

const (
UrefAccessNone = iota
UrefAccessRead
Expand Down Expand Up @@ -85,6 +89,10 @@ func (v URef) GobEncode() ([]byte, error) {

func NewURef(source string) (res URef, err error) {
parts := strings.Split(source, "-")
if len(parts) != 3 {
return res, ErrIncorrectPurseFormat
}

payloadInBytes, err := hex.DecodeString(parts[1])
if err != nil {
return res, err
Expand Down

0 comments on commit c021926

Please sign in to comment.