From 98fa8d60eab4db58ad1ec76f2fffa1d594813637 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 26 Oct 2020 10:31:21 +0300 Subject: [PATCH 1/2] Handle exchange rates request throttled --- .dialyzer-ignore | 2 +- CHANGELOG.md | 1 + .../lib/explorer/exchange_rates/exchange_rates.ex | 10 +++++++--- apps/explorer/lib/explorer/exchange_rates/source.ex | 8 +++++--- .../explorer/exchange_rates/exchange_rates_test.exs | 5 ++++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.dialyzer-ignore b/.dialyzer-ignore index bf2a526f58..0ad50fe2a7 100644 --- a/.dialyzer-ignore +++ b/.dialyzer-ignore @@ -23,7 +23,7 @@ lib/block_scout_web/controllers/api/rpc/transaction_controller.ex:21 lib/block_scout_web/controllers/api/rpc/transaction_controller.ex:22 lib/explorer/smart_contract/reader.ex:330 lib/indexer/fetcher/token_total_supply_on_demand.ex:16 -lib/explorer/exchange_rates/source.ex:41 +lib/explorer/exchange_rates/source.ex:45 lib/explorer/exchange_rates/source/coin_gecko.ex:148 lib/explorer/exchange_rates/source/coin_gecko.ex:169 lib/explorer/smart_contract/verifier.ex:89 diff --git a/CHANGELOG.md b/CHANGELOG.md index efeb5176ca..6d2226bd1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Fixes +- [#3396](https://github.com/poanetwork/blockscout/pull/3396) - Handle exchange rates request throttled - [#3382](https://github.com/poanetwork/blockscout/pull/3382) - Check ets table exists for know tokens - [#3376](https://github.com/poanetwork/blockscout/pull/3376) - Fix contract nested inputs - [#3375](https://github.com/poanetwork/blockscout/pull/3375) - Prevent terminating of tokens/contracts process diff --git a/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex b/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex index f0ed6f0f54..fba8977fac 100644 --- a/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex +++ b/apps/explorer/lib/explorer/exchange_rates/exchange_rates.ex @@ -2,7 +2,7 @@ defmodule Explorer.ExchangeRates do @moduledoc """ Local cache for token exchange rates. - Exchange rate data is updated every 5 minutes. + Exchange rate data is updated every 10 minutes. """ use GenServer @@ -12,7 +12,7 @@ defmodule Explorer.ExchangeRates do alias Explorer.Chain.Events.Publisher alias Explorer.ExchangeRates.{Source, Token} - @interval :timer.minutes(5) + @interval :timer.minutes(10) @table_name :exchange_rates @impl GenServer @@ -42,7 +42,7 @@ defmodule Explorer.ExchangeRates do def handle_info({_ref, {:error, reason}}, state) do Logger.warn(fn -> "Failed to get exchange rates with reason '#{reason}'." end) - fetch_rates() + schedule_next_consolidation() {:noreply, state} end @@ -77,6 +77,10 @@ defmodule Explorer.ExchangeRates do GenServer.start_link(__MODULE__, opts, name: __MODULE__) end + defp schedule_next_consolidation do + Process.send_after(self(), :update, :timer.minutes(1)) + end + @doc """ Lists exchange rates for the tracked tickers. """ diff --git a/apps/explorer/lib/explorer/exchange_rates/source.ex b/apps/explorer/lib/explorer/exchange_rates/source.ex index 20422a0b33..470458a657 100644 --- a/apps/explorer/lib/explorer/exchange_rates/source.ex +++ b/apps/explorer/lib/explorer/exchange_rates/source.ex @@ -33,7 +33,11 @@ defmodule Explorer.ExchangeRates.Source do {:ok, result} {:ok, %Response{body: body, status_code: status_code}} when status_code in 400..499 -> - {:error, decode_json(body)["error"]} + if is_map(decode_json(body)) do + {:error, decode_json(body)["error"]} + else + {:error, body} + end {:error, %Error{reason: reason}} -> {:error, reason} @@ -41,8 +45,6 @@ defmodule Explorer.ExchangeRates.Source do {:error, :nxdomain} -> {:error, "CoinGecko is not responsive"} end - after - {:error, ""} end @doc """ diff --git a/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs b/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs index d1bed67de1..26ae7f1e5b 100644 --- a/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs +++ b/apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs @@ -106,7 +106,10 @@ defmodule Explorer.ExchangeRatesTest do assert {:noreply, ^state} = ExchangeRates.handle_info({nil, {:error, "some error"}}, state) - assert_receive {_, {:ok, _}} + assert_receive :update + + assert {:noreply, ^state} = ExchangeRates.handle_info(:update, state) + assert_receive {_, {:ok, [%Token{}]}} end end From bd71a822a5f79bcbcca6dad5ce9e4a15c9ff9132 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 26 Oct 2020 13:05:44 +0300 Subject: [PATCH 2/2] Gas usage per day --- CHANGELOG.md | 1 + .../templates/chain/show.html.eex | 13 +++++++++- .../lib/block_scout_web/views/layout_view.ex | 4 ++-- apps/block_scout_web/priv/gettext/default.pot | 22 ++++++++--------- .../priv/gettext/en/LC_MESSAGES/default.po | 22 ++++++++--------- .../views/layout_view_test.exs | 24 +++++++++---------- .../chain/transaction/history/historian.ex | 4 +++- .../transaction/history/transaction_stats.ex | 5 +++- ...transactions_stat_add_gas_usage_column.exs | 9 +++++++ .../transaction/history/historian_test.exs | 14 ++++++----- 10 files changed, 73 insertions(+), 45 deletions(-) create mode 100644 apps/explorer/priv/repo/migrations/20201026093652_transactions_stat_add_gas_usage_column.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d2226bd1a..a8fd3a2304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#3398](https://github.com/poanetwork/blockscout/pull/3398) - Collect and display gas usage per day at the main page - [#3385](https://github.com/poanetwork/blockscout/pull/3385), [#3397](https://github.com/poanetwork/blockscout/pull/3397) - Total gas usage at the main page - [#3384](https://github.com/poanetwork/blockscout/pull/3384), [#3386](https://github.com/poanetwork/blockscout/pull/3386) - Address total gas usage - [#3377](https://github.com/poanetwork/blockscout/pull/3377) - Add links to contract libraries diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index f3ad057ebf..84601a7d66 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -91,7 +91,18 @@ <%= gettext "Tx/day" %> - <%= BlockScoutWeb.Cldr.Number.to_string!(Enum.at(@transaction_stats, 0).number_of_transactions, format: "#,###") %> + <% num_of_transactions = BlockScoutWeb.Cldr.Number.to_string!(Enum.at(@transaction_stats, 0).number_of_transactions, format: "#,###") %> + <%= num_of_transactions %> + <%= if Enum.at(@transaction_stats, 0).gas_used do %> + "> + + + <% end %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex index 465be7bec7..e6cb9a2b70 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/layout_view.ex @@ -11,7 +11,7 @@ defmodule BlockScoutWeb.LayoutView do url: "https://blockscout.com/poa/core" }, %{ - title: "POA Sokol", + title: "Sokol", url: "https://blockscout.com/poa/sokol", test_net?: true }, @@ -47,7 +47,7 @@ defmodule BlockScoutWeb.LayoutView do end def subnetwork_title do - Keyword.get(application_config(), :subnetwork) || "POA Sokol" + Keyword.get(application_config(), :subnetwork) || "Sokol" end def network_title do diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index d17e6bafba..d16fa400c3 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -151,7 +151,7 @@ msgid "Anything not in this list is not supported. Click on the method to be tak msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:110 +#: lib/block_scout_web/templates/chain/show.html.eex:121 msgid "Average block time" msgstr "" @@ -236,7 +236,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:165 +#: lib/block_scout_web/templates/chain/show.html.eex:176 #: lib/block_scout_web/templates/layout/_topnav.html.eex:34 #: lib/block_scout_web/templates/layout/_topnav.html.eex:38 msgid "Blocks" @@ -1065,7 +1065,7 @@ msgid "More internal transactions have come in" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:226 +#: lib/block_scout_web/templates/chain/show.html.eex:237 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:12 #: lib/block_scout_web/templates/transaction/index.html.eex:18 msgid "More transactions have come in" @@ -1309,7 +1309,7 @@ msgstr "" #: lib/block_scout_web/templates/address_transaction/index.html.eex:48 #: lib/block_scout_web/templates/address_validation/index.html.eex:22 #: lib/block_scout_web/templates/block_transaction/index.html.eex:23 -#: lib/block_scout_web/templates/chain/show.html.eex:169 +#: lib/block_scout_web/templates/chain/show.html.eex:180 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:21 #: lib/block_scout_web/templates/stakes/_table.html.eex:44 #: lib/block_scout_web/templates/tokens/holder/index.html.eex:22 @@ -1324,7 +1324,7 @@ msgid "Something went wrong, click to reload." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:232 +#: lib/block_scout_web/templates/chain/show.html.eex:243 msgid "Something went wrong, click to retry." msgstr "" @@ -1453,7 +1453,7 @@ msgid "Total Supply" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:140 +#: lib/block_scout_web/templates/chain/show.html.eex:151 msgid "Total blocks" msgstr "" @@ -1593,12 +1593,12 @@ msgid "Version" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:164 +#: lib/block_scout_web/templates/chain/show.html.eex:175 msgid "View All Blocks" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:222 +#: lib/block_scout_web/templates/chain/show.html.eex:233 msgid "View All Transactions" msgstr "" @@ -1640,7 +1640,7 @@ msgid "WEI" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:148 +#: lib/block_scout_web/templates/chain/show.html.eex:159 msgid "Wallet addresses" msgstr "" @@ -1780,7 +1780,7 @@ msgid "Module" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:119 +#: lib/block_scout_web/templates/chain/show.html.eex:130 msgid "Total transactions" msgstr "" @@ -1867,7 +1867,7 @@ msgstr "" #: lib/block_scout_web/templates/address_transaction/index.html.eex:15 #: lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 -#: lib/block_scout_web/templates/chain/show.html.eex:223 +#: lib/block_scout_web/templates/chain/show.html.eex:234 #: lib/block_scout_web/templates/layout/_topnav.html.eex:53 #: lib/block_scout_web/views/address_view.ex:349 msgid "Transactions" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index d17e6bafba..d16fa400c3 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -151,7 +151,7 @@ msgid "Anything not in this list is not supported. Click on the method to be tak msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:110 +#: lib/block_scout_web/templates/chain/show.html.eex:121 msgid "Average block time" msgstr "" @@ -236,7 +236,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:165 +#: lib/block_scout_web/templates/chain/show.html.eex:176 #: lib/block_scout_web/templates/layout/_topnav.html.eex:34 #: lib/block_scout_web/templates/layout/_topnav.html.eex:38 msgid "Blocks" @@ -1065,7 +1065,7 @@ msgid "More internal transactions have come in" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:226 +#: lib/block_scout_web/templates/chain/show.html.eex:237 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:12 #: lib/block_scout_web/templates/transaction/index.html.eex:18 msgid "More transactions have come in" @@ -1309,7 +1309,7 @@ msgstr "" #: lib/block_scout_web/templates/address_transaction/index.html.eex:48 #: lib/block_scout_web/templates/address_validation/index.html.eex:22 #: lib/block_scout_web/templates/block_transaction/index.html.eex:23 -#: lib/block_scout_web/templates/chain/show.html.eex:169 +#: lib/block_scout_web/templates/chain/show.html.eex:180 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:21 #: lib/block_scout_web/templates/stakes/_table.html.eex:44 #: lib/block_scout_web/templates/tokens/holder/index.html.eex:22 @@ -1324,7 +1324,7 @@ msgid "Something went wrong, click to reload." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:232 +#: lib/block_scout_web/templates/chain/show.html.eex:243 msgid "Something went wrong, click to retry." msgstr "" @@ -1453,7 +1453,7 @@ msgid "Total Supply" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:140 +#: lib/block_scout_web/templates/chain/show.html.eex:151 msgid "Total blocks" msgstr "" @@ -1593,12 +1593,12 @@ msgid "Version" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:164 +#: lib/block_scout_web/templates/chain/show.html.eex:175 msgid "View All Blocks" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:222 +#: lib/block_scout_web/templates/chain/show.html.eex:233 msgid "View All Transactions" msgstr "" @@ -1640,7 +1640,7 @@ msgid "WEI" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:148 +#: lib/block_scout_web/templates/chain/show.html.eex:159 msgid "Wallet addresses" msgstr "" @@ -1780,7 +1780,7 @@ msgid "Module" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:119 +#: lib/block_scout_web/templates/chain/show.html.eex:130 msgid "Total transactions" msgstr "" @@ -1867,7 +1867,7 @@ msgstr "" #: lib/block_scout_web/templates/address_transaction/index.html.eex:15 #: lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 -#: lib/block_scout_web/templates/chain/show.html.eex:223 +#: lib/block_scout_web/templates/chain/show.html.eex:234 #: lib/block_scout_web/templates/layout/_topnav.html.eex:53 #: lib/block_scout_web/views/address_view.ex:349 msgid "Transactions" diff --git a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs index 0c9fafa75a..840e41ef6b 100644 --- a/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/layout_view_test.exs @@ -33,7 +33,7 @@ defmodule BlockScoutWeb.LayoutViewTest do end test "use the default subnetwork title when there is no env configured for it" do - assert LayoutView.subnetwork_title() == "POA Sokol" + assert LayoutView.subnetwork_title() == "Sokol" end end @@ -91,7 +91,7 @@ defmodule BlockScoutWeb.LayoutViewTest do end end - @supported_chains_pattern ~s([ { "title": "RSK Mainnet", "url": "https://blockscout.com/rsk/mainnet", "other?": true }, { "title": "POA Sokol", "url": "https://blockscout.com/poa/sokol", "test_net?": true }, { "title": "POA Core", "url": "https://blockscout.com/poa/core" }, { "title": "LUKSO L14 testnet", "url": "https://blockscout.com/lukso/l14", "test_net?": true, "hide_in_dropdown?": true } ]) + @supported_chains_pattern ~s([ { "title": "RSK", "url": "https://blockscout.com/rsk/mainnet", "other?": true }, { "title": "Sokol", "url": "https://blockscout.com/poa/sokol", "test_net?": true }, { "title": "POA", "url": "https://blockscout.com/poa/core" }, { "title": "LUKSO L14", "url": "https://blockscout.com/lukso/l14", "test_net?": true, "hide_in_dropdown?": true } ]) describe "other_networks/0" do test "get networks list based on env variables" do @@ -99,16 +99,16 @@ defmodule BlockScoutWeb.LayoutViewTest do assert LayoutView.other_networks() == [ %{ - title: "POA Core", + title: "POA", url: "https://blockscout.com/poa/core" }, %{ - title: "RSK Mainnet", + title: "RSK", url: "https://blockscout.com/rsk/mainnet", other?: true }, %{ - title: "LUKSO L14 testnet", + title: "LUKSO L14", url: "https://blockscout.com/lukso/l14", test_net?: true, hide_in_dropdown?: true @@ -129,11 +129,11 @@ defmodule BlockScoutWeb.LayoutViewTest do assert LayoutView.main_nets(LayoutView.other_networks()) == [ %{ - title: "POA Core", + title: "POA", url: "https://blockscout.com/poa/core" }, %{ - title: "RSK Mainnet", + title: "RSK", url: "https://blockscout.com/rsk/mainnet", other?: true } @@ -147,7 +147,7 @@ defmodule BlockScoutWeb.LayoutViewTest do assert LayoutView.test_nets(LayoutView.other_networks()) == [ %{ - title: "LUKSO L14 testnet", + title: "LUKSO L14", url: "https://blockscout.com/lukso/l14", test_net?: true, hide_in_dropdown?: true @@ -162,11 +162,11 @@ defmodule BlockScoutWeb.LayoutViewTest do assert LayoutView.dropdown_nets() == [ %{ - title: "POA Core", + title: "POA", url: "https://blockscout.com/poa/core" }, %{ - title: "RSK Mainnet", + title: "RSK", url: "https://blockscout.com/rsk/mainnet", other?: true } @@ -180,7 +180,7 @@ defmodule BlockScoutWeb.LayoutViewTest do assert LayoutView.dropdown_head_main_nets() == [ %{ - title: "POA Core", + title: "POA", url: "https://blockscout.com/poa/core" } ] @@ -193,7 +193,7 @@ defmodule BlockScoutWeb.LayoutViewTest do assert LayoutView.dropdown_other_nets() == [ %{ - title: "RSK Mainnet", + title: "RSK", url: "https://blockscout.com/rsk/mainnet", other?: true } diff --git a/apps/explorer/lib/explorer/chain/transaction/history/historian.ex b/apps/explorer/lib/explorer/chain/transaction/history/historian.ex index 3639bbadf0..5d70143760 100644 --- a/apps/explorer/lib/explorer/chain/transaction/history/historian.ex +++ b/apps/explorer/lib/explorer/chain/transaction/history/historian.ex @@ -63,7 +63,9 @@ defmodule Explorer.Chain.Transaction.History.Historian do ) num_transactions = Repo.aggregate(query, :count, :hash, timeout: :infinity) - records = [%{date: day_to_fetch, number_of_transactions: num_transactions} | records] + gas_used = Repo.aggregate(query, :sum, :gas_used, timeout: :infinity) + + records = [%{date: day_to_fetch, number_of_transactions: num_transactions, gas_used: gas_used} | records] compile_records(num_days - 1, records) else records = [%{date: day_to_fetch, number_of_transactions: 0} | records] diff --git a/apps/explorer/lib/explorer/chain/transaction/history/transaction_stats.ex b/apps/explorer/lib/explorer/chain/transaction/history/transaction_stats.ex index 80a0299166..c74ea1c526 100644 --- a/apps/explorer/lib/explorer/chain/transaction/history/transaction_stats.ex +++ b/apps/explorer/lib/explorer/chain/transaction/history/transaction_stats.ex @@ -17,16 +17,19 @@ defmodule Explorer.Chain.Transaction.History.TransactionStats do schema "transaction_stats" do field(:date, :date) field(:number_of_transactions, :integer) + field(:gas_used, :decimal) end @typedoc """ The recorded values of the number of transactions for a single day. * `:date` - The date in UTC. * `:number_of_transactions` - Number of transactions processed by the vm for a given date. + * `:gas_used` - Gas used in transactions per single day """ @type t :: %__MODULE__{ date: Date.t(), - number_of_transactions: integer() + number_of_transactions: integer(), + gas_used: non_neg_integer() } @spec by_date_range(Date.t(), Date.t()) :: [__MODULE__] diff --git a/apps/explorer/priv/repo/migrations/20201026093652_transactions_stat_add_gas_usage_column.exs b/apps/explorer/priv/repo/migrations/20201026093652_transactions_stat_add_gas_usage_column.exs new file mode 100644 index 0000000000..2c57675f4e --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20201026093652_transactions_stat_add_gas_usage_column.exs @@ -0,0 +1,9 @@ +defmodule Explorer.Repo.Migrations.TransactionsStatAddGasUsageColumn do + use Ecto.Migration + + def change do + alter table(:transaction_stats) do + add(:gas_used, :numeric, precision: 100, null: true) + end + end +end diff --git a/apps/explorer/test/explorer/chain/transaction/history/historian_test.exs b/apps/explorer/test/explorer/chain/transaction/history/historian_test.exs index 8f9d8261ed..379852c30b 100644 --- a/apps/explorer/test/explorer/chain/transaction/history/historian_test.exs +++ b/apps/explorer/test/explorer/chain/transaction/history/historian_test.exs @@ -28,9 +28,9 @@ defmodule Explorer.Chain.Transaction.History.HistorianTest do insert(:block, timestamp: DateTime.from_unix!(days_to_secs(1))) ] - insert(:transaction) |> with_block(Enum.at(blocks, 0)) - insert(:transaction) |> with_block(Enum.at(blocks, 1)) - insert(:transaction) |> with_block(Enum.at(blocks, 2)) + transaction_1 = insert(:transaction) |> with_block(Enum.at(blocks, 0)) + transaction_2 = insert(:transaction) |> with_block(Enum.at(blocks, 1)) + transaction_3 = insert(:transaction) |> with_block(Enum.at(blocks, 2)) expected = [ %{date: ~D[1970-01-04], number_of_transactions: 0} @@ -38,17 +38,19 @@ defmodule Explorer.Chain.Transaction.History.HistorianTest do assert {:ok, ^expected} = Historian.compile_records(1) + total_gas_used_1 = Decimal.add(transaction_1.gas_used, transaction_2.gas_used) + expected = [ %{date: ~D[1970-01-04], number_of_transactions: 0}, - %{date: ~D[1970-01-03], number_of_transactions: 2} + %{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2} ] assert {:ok, ^expected} = Historian.compile_records(2) expected = [ %{date: ~D[1970-01-04], number_of_transactions: 0}, - %{date: ~D[1970-01-03], number_of_transactions: 2}, - %{date: ~D[1970-01-02], number_of_transactions: 1} + %{date: ~D[1970-01-03], gas_used: total_gas_used_1, number_of_transactions: 2}, + %{date: ~D[1970-01-02], gas_used: transaction_3.gas_used, number_of_transactions: 1} ] assert {:ok, ^expected} = Historian.compile_records(3)