From ee4f1b4656bdab9174589b9fbe16e3abaac80b4d Mon Sep 17 00:00:00 2001 From: Peter Broadhurst Date: Sun, 20 Oct 2024 15:23:14 -0400 Subject: [PATCH] Formalize base64 serializer Signed-off-by: Peter Broadhurst --- pkg/abi/outputserialization.go | 5 +++++ pkg/abi/outputserialization_test.go | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/abi/outputserialization.go b/pkg/abi/outputserialization.go index da6c57fc..1882673f 100644 --- a/pkg/abi/outputserialization.go +++ b/pkg/abi/outputserialization.go @@ -18,6 +18,7 @@ package abi import ( "context" + "encoding/base64" "encoding/hex" "encoding/json" "fmt" @@ -151,6 +152,10 @@ func HexByteSerializer0xPrefix(b []byte) interface{} { return "0x" + hex.EncodeToString(b) } +func Base64ByteSerializer(b []byte) interface{} { + return base64.StdEncoding.EncodeToString(b) +} + func NumericDefaultNameGenerator(idx int) string { return strconv.FormatInt(int64(idx), 10) } diff --git a/pkg/abi/outputserialization_test.go b/pkg/abi/outputserialization_test.go index 0da2f595..4066561b 100644 --- a/pkg/abi/outputserialization_test.go +++ b/pkg/abi/outputserialization_test.go @@ -18,7 +18,6 @@ package abi import ( "context" - "encoding/base64" "math/big" "strconv" "testing" @@ -78,9 +77,7 @@ func TestJSONSerializationFormatsTuple(t *testing.T) { SetIntSerializer(func(i *big.Int) interface{} { return "0o" + i.Text(8) }). - SetByteSerializer(func(b []byte) interface{} { - return base64.StdEncoding.EncodeToString(b) - }). + SetByteSerializer(Base64ByteSerializer). SerializeJSON(v) assert.NoError(t, err) assert.JSONEq(t, `[