mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
fix marshaling of empty values
This commit is contained in:
parent
2db37b9471
commit
04965a36a0
2 changed files with 23 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ package ethapi
|
|||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
|
@ -1107,7 +1108,16 @@ type callResult struct {
|
|||
Logs []*types.Log `json:"logs"`
|
||||
Transfers []transfer `json:"transfers,omitempty"`
|
||||
GasUsed hexutil.Uint64 `json:"gasUsed"`
|
||||
Error string `json:"error"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r *callResult) MarshalJSON() ([]byte, error) {
|
||||
type callResultAlias callResult
|
||||
// Marshal logs to be an empty array instead of nil when empty
|
||||
if r.Logs == nil {
|
||||
r.Logs = []*types.Log{}
|
||||
}
|
||||
return json.Marshal((*callResultAlias)(r))
|
||||
}
|
||||
|
||||
// Multicall executes series of transactions on top of a base state.
|
||||
|
|
|
|||
|
|
@ -670,10 +670,12 @@ func TestMulticall(t *testing.T) {
|
|||
res{
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
},
|
||||
res{
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
},
|
||||
}},
|
||||
}, {
|
||||
|
|
@ -715,19 +717,23 @@ func TestMulticall(t *testing.T) {
|
|||
res{
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
},
|
||||
res{
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
},
|
||||
}, {
|
||||
res{
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
},
|
||||
res{
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x0",
|
||||
Logs: []types.Log{},
|
||||
Error: fmt.Sprintf("err: insufficient funds for gas * price + value: address %s have 0 want 1000 (supplied gas 9937000)", randomAccounts[3].addr.String()),
|
||||
},
|
||||
},
|
||||
|
|
@ -766,11 +772,13 @@ func TestMulticall(t *testing.T) {
|
|||
res{
|
||||
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000b",
|
||||
GasUsed: "0xe891",
|
||||
Logs: []types.Log{},
|
||||
},
|
||||
}, {
|
||||
res{
|
||||
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000c",
|
||||
GasUsed: "0xe891",
|
||||
Logs: []types.Log{},
|
||||
},
|
||||
}},
|
||||
},
|
||||
|
|
@ -830,9 +838,11 @@ func TestMulticall(t *testing.T) {
|
|||
want: [][]res{{{
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0xaacc",
|
||||
Logs: []types.Log{},
|
||||
}, {
|
||||
ReturnValue: "0x0000000000000000000000000000000000000000000000000000000000000005",
|
||||
GasUsed: "0x5bb7",
|
||||
Logs: []types.Log{},
|
||||
}}},
|
||||
},
|
||||
// Test logs output.
|
||||
|
|
@ -920,6 +930,7 @@ func TestMulticall(t *testing.T) {
|
|||
// Caller is in this case the contract that invokes ecrecover.
|
||||
ReturnValue: strings.ToLower(randomAccounts[2].addr.String()),
|
||||
GasUsed: "0x52f6",
|
||||
Logs: []types.Log{},
|
||||
}}},
|
||||
},
|
||||
// Test ether transfers.
|
||||
|
|
@ -965,6 +976,7 @@ func TestMulticall(t *testing.T) {
|
|||
Value: big.NewInt(100),
|
||||
},
|
||||
},
|
||||
Logs: []types.Log{},
|
||||
}}},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue