From 160a0e5bfc5f4e95ace07db51c5ebf45b6b47537 Mon Sep 17 00:00:00 2001 From: Jason Paulos Date: Thu, 22 Jun 2023 14:41:04 -0700 Subject: [PATCH] prefer nil instead of empty byte array for easier comparison --- daemon/algod/api/server/v2/account.go | 8 ++++++-- daemon/algod/api/server/v2/account_test.go | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/daemon/algod/api/server/v2/account.go b/daemon/algod/api/server/v2/account.go index 96385c191c..6ab51e549b 100644 --- a/daemon/algod/api/server/v2/account.go +++ b/daemon/algod/api/server/v2/account.go @@ -147,14 +147,18 @@ func convertTKVToGenerated(tkv *basics.TealKeyValue) *model.TealKeyValueStore { converted := make(model.TealKeyValueStore, 0, len(*tkv)) for k, v := range *tkv { - converted = append(converted, model.TealKeyValue{ + convertedKv := model.TealKeyValue{ Key: []byte(k), Value: model.TealValue{ Type: uint64(v.Type), Bytes: []byte(v.Bytes), Uint: v.Uint, }, - }) + } + if len(convertedKv.Value.Bytes) == 0 { + convertedKv.Value.Bytes = nil + } + converted = append(converted, convertedKv) } sort.Slice(converted, func(i, j int) bool { return bytes.Compare(converted[i].Key, converted[j].Key) < 0 diff --git a/daemon/algod/api/server/v2/account_test.go b/daemon/algod/api/server/v2/account_test.go index b3b049d2d4..32def1c34b 100644 --- a/daemon/algod/api/server/v2/account_test.go +++ b/daemon/algod/api/server/v2/account_test.go @@ -137,12 +137,12 @@ func TestAccount(t *testing.T) { makeTKV := func(k string, v interface{}) model.TealKeyValue { value := model.TealValue{} - switch v.(type) { + switch vKnown := v.(type) { case int: - value.Uint = uint64(v.(int)) + value.Uint = uint64(vKnown) value.Type = uint64(basics.TealUintType) case string: - value.Bytes = []byte(v.(string)) + value.Bytes = []byte(vKnown) value.Type = uint64(basics.TealBytesType) default: panic(fmt.Sprintf("Unknown teal type %v", t))