Skip to content

Commit

Permalink
Adds eth_get_code and fixes return for fee_history.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesduncombe committed Mar 11, 2024
1 parent b30b265 commit 271c824
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
3 changes: 3 additions & 0 deletions lib/tt_eth/behaviours/chain_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ defmodule TTEth.Behaviours.ChainClient do

@callback eth_get_block_by_number(block_id) :: any
@callback eth_get_block_by_number(block_id, boolean) :: any

@callback eth_get_code(address, block :: binary(), opts) :: {:ok, any} | {:error, any}
@callback eth_get_code(address, block :: binary()) :: {:ok, any} | {:error, any}
end
4 changes: 4 additions & 0 deletions lib/tt_eth/chain_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ defmodule TTEth.ChainClient do
def eth_get_block_by_number("" <> block, tx_detail \\ false),
do: block |> HttpClient.eth_get_block_by_number(tx_detail)

@impl ChainClient
def eth_get_code("" <> address, block \\ "latest", opts \\ []),
do: address |> HttpClient.eth_get_code(block, opts)

## Helpers outside of the ChainClient behaviour.

def eth_get_transaction_receipt("" <> tx_hash, opts \\ []),
Expand Down
56 changes: 29 additions & 27 deletions lib/tt_eth/chain_client_mock_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,40 @@ defmodule TTEth.ChainClientMockImpl do
def eth_fee_history(_block_count, _newest_block, _reward_percentiles, _opts \\ []),
do:
{:ok,
[
%{
"oldestBlock" => "0x54",
"reward" => [
[
"0x174876e800",
"0x174876e800"
],
[
"0x174876e800",
"0x174876e800"
],
[
"0x174876e800",
"0x174876e800"
]
%{
"oldestBlock" => "0x54",
"reward" => [
[
"0x174876e800",
"0x174876e800"
],
"baseFeePerGas" => [
"0x0",
"0x0",
"0x0",
"0x0"
[
"0x174876e800",
"0x174876e800"
],
"gasUsedRatio" => [
0.0010253063265735019,
0.006479788956353575,
0.00006763590977418037
[
"0x174876e800",
"0x174876e800"
]
}
]}
],
"baseFeePerGas" => [
"0x0",
"0x0",
"0x0",
"0x0"
],
"gasUsedRatio" => [
0.0010253063265735019,
0.006479788956353575,
0.00006763590977418037
]
}}

@impl ChainClient
def eth_get_block_by_number(_block, _tx_detail \\ false),
do: {:ok, %{"number" => "0x1", "baseFeePerGas" => "0x10"}}

@impl ChainClient
def eth_get_code(_address, _block \\ "latest", _opts \\ []),
do: {:ok, "0x60806040523661000b57005b600080357fffffffff"}
end

0 comments on commit 271c824

Please sign in to comment.