Skip to content

Commit

Permalink
fix MarshalJSON undefined for non-pointer Uint160
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed May 19, 2024
1 parent dff2b99 commit 61e25eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/uint160.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func IsValidHexAddr(s []byte) bool {
return false
}

func (f *Uint160) MarshalJSON() ([]byte, error) {
func (f Uint160) MarshalJSON() ([]byte, error) {
str, err := f.ToAddress()
return []byte("\"" + str + "\""), err
}
Expand Down
12 changes: 11 additions & 1 deletion common/uint160_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"encoding/hex"
"encoding/json"
"testing"
)

Expand All @@ -23,7 +24,16 @@ func TestMarshalJSON(t *testing.T) {
// Expected value after Marshalling
expected := []byte(NKNADDRESS)

bytes, err := f.MarshalJSON()
bytes, err := json.Marshal(f)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

if !bytesEqual(bytes, expected) {
t.Fatalf("Expected %v, got %v", expected, bytes)
}

bytes, err = json.Marshal(*f)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down

0 comments on commit 61e25eb

Please sign in to comment.