Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MarshalJSON undefined for non-pointer Uint160 #971

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading