diff --git a/rpc/backend/account_info.go b/rpc/backend/account_info.go index 452b3fafa2..8d1e7b4474 100644 --- a/rpc/backend/account_info.go +++ b/rpc/backend/account_info.go @@ -37,14 +37,17 @@ func (b *Backend) GetCode(address common.Address, blockNrOrHash rpctypes.BlockNu // GetHexProofs returns list of hex data of proof op func GetHexProofs(proof *crypto.ProofOps) []string { + if proof == nil { + return []string{""} + } var proofs []string // check for proof - if proof != nil { - for _, p := range proof.Ops { - if len(p.Data) > 0 { - proofs = append(proofs, hexutil.Encode(p.Data)) - } + for _, p := range proof.Ops { + proof := "" + if len(p.Data) > 0 { + proof = hexutil.Encode(p.Data) } + proofs = append(proofs, proof) } return proofs } diff --git a/rpc/backend/account_info_test.go b/rpc/backend/account_info_test.go index f214d30ee7..4b6d8a0b7a 100644 --- a/rpc/backend/account_info_test.go +++ b/rpc/backend/account_info_test.go @@ -395,6 +395,7 @@ func mookProofs(num int, withData bool) *crypto.ProofOps { } func (suite *BackendTestSuite) TestGetHexProofs() { + defaultRes := []string{""} testCases := []struct { name string proof *crypto.ProofOps @@ -403,12 +404,12 @@ func (suite *BackendTestSuite) TestGetHexProofs() { { "no proof provided", mookProofs(0, false), - nil, + defaultRes, }, { "no proof data provided", - mookProofs(0, false), - nil, + mookProofs(1, false), + defaultRes, }, { "valid proof provided",