From fd6649d32f04e25dc5820dd27c5b1ffd2ebc18c8 Mon Sep 17 00:00:00 2001 From: ryo_kikuchi Date: Wed, 25 Sep 2024 07:09:30 +0900 Subject: [PATCH] Fix json encoding for transaction result (#1768) --- internal/transactions/transactions.go | 4 +++- internal/transactions/transactions_test.go | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/transactions/transactions.go b/internal/transactions/transactions.go index 64dc90ab2..fb195fb2b 100644 --- a/internal/transactions/transactions.go +++ b/internal/transactions/transactions.go @@ -32,6 +32,8 @@ import ( "github.com/onflow/flow-cli/internal/command" "github.com/onflow/flow-cli/internal/events" "github.com/onflow/flow-cli/internal/util" + + jsoncdc "github.com/onflow/cadence/encoding/json" ) var Cmd = &cobra.Command{ @@ -82,7 +84,7 @@ func (r *transactionResult) JSON() any { "index": event.EventIndex, "type": event.Type, "values": json.RawMessage( - event.Payload, + jsoncdc.MustEncode(event.Value), ), }) } diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index a7637efcc..fd7d635c4 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -323,7 +323,6 @@ func Test_Result(t *testing.T) { []cadence.Field{{Type: cadence.StringType, Identifier: "bar"}}, []cadence.Value{cadence.NewInt(1)}, ) - event.Payload = []byte("mock_payload") withdrawFlowEvent := tests.NewEvent( 1, @@ -446,7 +445,7 @@ Fee Events (hidden, use --include fee-events)`, output.OkEmoji()), "\n") map[string]any{ "index": 0, "type": "A.foo", - "values": json.RawMessage{0x6d, 0x6f, 0x63, 0x6b, 0x5f, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64}, + "values": json.RawMessage{0x7b, 0x22, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x22, 0x41, 0x2e, 0x66, 0x6f, 0x6f, 0x22, 0x2c, 0x22, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x22, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x49, 0x6e, 0x74, 0x22, 0x7d, 0x2c, 0x22, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x61, 0x72, 0x22, 0x7d, 0x5d, 0x7d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x22, 0x7d, 0xa}, }, }, "id": "e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f",