From 94f6acc65135dba05ad740ba2dcdd778c83cc83f Mon Sep 17 00:00:00 2001 From: noot <36753753+noot@users.noreply.github.com> Date: Wed, 17 Jun 2020 12:14:21 -0400 Subject: [PATCH] rpc: return 0x0 as extra data in block instead of nil (#333) * return 0x0 extra data instead of nil * add fix for getBlock * add tests --- rpc/eth_api.go | 2 +- tests/rpc_test.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rpc/eth_api.go b/rpc/eth_api.go index c10ef046..6586675c 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -526,7 +526,7 @@ func formatBlock( "miner": common.Address{}, "difficulty": nil, "totalDifficulty": nil, - "extraData": nil, + "extraData": hexutil.Uint64(0), "size": hexutil.Uint64(size), "gasLimit": hexutil.Uint64(gasLimit), // Static gas limit "gasUsed": (*hexutil.Big)(gasUsed), diff --git a/tests/rpc_test.go b/tests/rpc_test.go index 7b556292..a677a553 100644 --- a/tests/rpc_test.go +++ b/tests/rpc_test.go @@ -634,11 +634,11 @@ func TestBlockBloom(t *testing.T) { } func TestBlockBloom_Hash(t *testing.T) { - t.Skip() - // TODO: get this to work hash := deployTestContractWithFunction(t) receipt := waitForReceipt(t, hash) + time.Sleep(time.Second * 3) + blockHash := receipt["blockHash"].(string) param := []interface{}{blockHash, false} @@ -685,3 +685,13 @@ func TestEth_EstimateGas(t *testing.T) { require.Equal(t, hexutil.Bytes{0xf7, 0xa6}, gas) } + +func TestEth_GetBlockByNumber(t *testing.T) { + param := []interface{}{"0x1", false} + rpcRes := call(t, "eth_getBlockByNumber", param) + + block := make(map[string]interface{}) + err := json.Unmarshal(rpcRes.Result, &block) + require.NoError(t, err) + require.Equal(t, "0x0", block["extraData"].(string)) +}