From dce0b0cffbd470adfda568912ca7b03b0e8f77e5 Mon Sep 17 00:00:00 2001 From: MichaelWang Date: Thu, 21 Jan 2021 01:33:05 +0800 Subject: [PATCH] evm: fix pointer in ResultData.String() (#733) --- x/evm/types/utils.go | 12 +++++++++--- x/evm/types/utils_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/x/evm/types/utils.go b/x/evm/types/utils.go index 8f06eed3..051b7dae 100644 --- a/x/evm/types/utils.go +++ b/x/evm/types/utils.go @@ -68,13 +68,19 @@ type ResultData struct { // String implements fmt.Stringer interface. func (rd ResultData) String() string { + var logsStr string + logsLen := len(rd.Logs) + for i := 0; i < logsLen; i++ { + logsStr = fmt.Sprintf("%s\t\t%v\n ", logsStr, *rd.Logs[i]) + } + return strings.TrimSpace(fmt.Sprintf(`ResultData: ContractAddress: %s Bloom: %s - Logs: %v Ret: %v - TxHash: %s -`, rd.ContractAddress.String(), rd.Bloom.Big().String(), rd.Logs, rd.Ret, rd.TxHash.String())) + TxHash: %s + Logs: +%s`, rd.ContractAddress.String(), rd.Bloom.Big().String(), rd.Ret, rd.TxHash.String(), logsStr)) } // EncodeResultData takes all of the necessary data from the EVM execution diff --git a/x/evm/types/utils_test.go b/x/evm/types/utils_test.go index 32d9b8bb..609a9678 100644 --- a/x/evm/types/utils_test.go +++ b/x/evm/types/utils_test.go @@ -1,6 +1,7 @@ package types import ( + "strings" "testing" "github.com/stretchr/testify/require" @@ -34,3 +35,34 @@ func TestEvmDataEncoding(t *testing.T) { require.Equal(t, data.Logs, res.Logs) require.Equal(t, ret, res.Ret) } + +func TestResultData_String(t *testing.T) { + const expectedResultDataStr = `ResultData: + ContractAddress: 0x5dE8a020088a2D6d0a23c204FFbeD02790466B49 + Bloom: 259 + Ret: [5 8] + TxHash: 0x0000000000000000000000000000000000000000000000000000000000000000 + Logs: + {0x0000000000000000000000000000000000000000 [] [1 2 3 4] 17 0x0000000000000000000000000000000000000000000000000000000000000000 0 0x0000000000000000000000000000000000000000000000000000000000000000 0 false} + {0x0000000000000000000000000000000000000000 [] [5 6 7 8] 18 0x0000000000000000000000000000000000000000000000000000000000000000 0 0x0000000000000000000000000000000000000000000000000000000000000000 0 false}` + addr := ethcmn.HexToAddress("0x5dE8a020088a2D6d0a23c204FFbeD02790466B49") + bloom := ethtypes.BytesToBloom([]byte{0x1, 0x3}) + ret := []byte{0x5, 0x8} + + data := ResultData{ + ContractAddress: addr, + Bloom: bloom, + Logs: []*ethtypes.Log{ + { + Data: []byte{1, 2, 3, 4}, + BlockNumber: 17, + }, + { + Data: []byte{5, 6, 7, 8}, + BlockNumber: 18, + }}, + Ret: ret, + } + + require.True(t, strings.EqualFold(expectedResultDataStr, data.String())) +}