Skip to content

Commit

Permalink
Add eth RPC methods for getting uncles
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Dec 22, 2023
1 parent 42be5cd commit 130b167
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,23 @@ func (s *BlockChainAPI) EstimateGas(
) (hexutil.Uint64, error) {
return hexutil.Uint64(105), nil
}

// eth_getUncleByBlockHashAndIndex
// GetUncleByBlockHashAndIndex returns the uncle block for the given block hash and index.
func (s *BlockChainAPI) GetUncleByBlockHashAndIndex(
ctx context.Context,
blockHash common.Hash,
index hexutil.Uint,
) (map[string]interface{}, error) {
return map[string]interface{}{}, nil
}

// eth_getUncleByBlockNumberAndIndex
// GetUncleByBlockNumberAndIndex returns the uncle block for the given block hash and index.
func (s *BlockChainAPI) GetUncleByBlockNumberAndIndex(
ctx context.Context,
blockNumber rpc.BlockNumber,
index hexutil.Uint,
) (map[string]interface{}, error) {
return map[string]interface{}{}, nil
}
22 changes: 22 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,26 @@ func TestBlockChainAPI(t *testing.T) {

assert.Equal(t, hexutil.Uint64(105), gasEstimate)
})

t.Run("GetUncleByBlockHashAndIndex", func(t *testing.T) {
uncle, err := blockchainAPI.GetUncleByBlockHashAndIndex(
context.Background(),
common.HexToHash("0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d"),
hexutil.Uint(105),
)
require.NoError(t, err)

assert.Equal(t, map[string]interface{}{}, uncle)
})

t.Run("GetUncleByBlockNumberAndIndex", func(t *testing.T) {
uncle, err := blockchainAPI.GetUncleByBlockNumberAndIndex(
context.Background(),
rpc.FinalizedBlockNumber,
hexutil.Uint(115),
)
require.NoError(t, err)

assert.Equal(t, map[string]interface{}{}, uncle)
})
}
4 changes: 4 additions & 0 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var requests = []string{
`{"jsonrpc":"2.0","id":28,"method":"eth_accounts","params":[]}`,
`{"jsonrpc":"2.0","id":29,"method":"eth_call","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]}`,
`{"jsonrpc":"2.0","id":30,"method":"eth_estimateGas","params":[{"from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas":"0x76c0","gasPrice":"0x9184e72a000","value":"0x9184e72a","input":"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]}`,
`{"jsonrpc":"2.0","id":31,"method":"eth_getUncleByBlockHashAndIndex","params":["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x45"]}`,
`{"jsonrpc":"2.0","id":32,"method":"eth_getUncleByBlockNumberAndIndex","params":["0xe8", "0x45"]}`,
}

var expectedResponses = []string{
Expand Down Expand Up @@ -81,6 +83,8 @@ var expectedResponses = []string{
`{"jsonrpc":"2.0","id":28,"result":["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]}`,
`{"jsonrpc":"2.0","id":29,"result":"0x00010203040506070809"}`,
`{"jsonrpc":"2.0","id":30,"result":"0x69"}`,
`{"jsonrpc":"2.0","id":31,"result":{}}`,
`{"jsonrpc":"2.0","id":32,"result":{}}`,
}

func TestServerJSONRPCOveHTTPHandler(t *testing.T) {
Expand Down

0 comments on commit 130b167

Please sign in to comment.