Remove FakeAdapter for count estimation and just assert that an integer is returned from count estimation functions.

pull/744/head
Stamates 6 years ago
parent 4169cac864
commit e000921433
  1. 2
      apps/block_scout_web/config/test.exs
  2. 6
      apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex
  3. 4
      apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex
  4. 3
      apps/block_scout_web/lib/block_scout_web/notifier.ex
  5. 2
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  6. 2
      apps/block_scout_web/test/block_scout_web/channels/address_channel_test.exs
  7. 2
      apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs
  8. 8
      apps/block_scout_web/test/support/fake_adapter.ex
  9. 4
      apps/explorer/lib/explorer/chain.ex
  10. 6
      apps/explorer/test/explorer/chain_test.exs

@ -15,5 +15,3 @@ config :logger, :block_scout_web,
# Configure wallaby
config :wallaby, screenshot_on_failure: true
config :block_scout_web, :fake_adapter, BlockScoutWeb.FakeAdapter

@ -6,11 +6,9 @@ defmodule BlockScoutWeb.AddressController do
alias Explorer.ExchangeRates.Token
def index(conn, _params) do
address_count_module = Application.get_env(:block_scout_web, :fake_adapter) || Chain
render(conn, "index.html",
addresses: Chain.list_top_addresses(),
address_estimated_count: address_count_module.address_estimated_count(),
address_estimated_count: Chain.address_estimated_count(),
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null()
)
end
@ -20,6 +18,6 @@ defmodule BlockScoutWeb.AddressController do
end
def transaction_count(%Address{} = address) do
Chain.address_to_transaction_count_estimate(address)
Chain.address_to_transactions_estimated_count(address)
end
end

@ -7,8 +7,6 @@ defmodule BlockScoutWeb.ChainController do
alias Explorer.Market
def show(conn, _params) do
address_count_module = Application.get_env(:block_scout_web, :fake_adapter) || Chain
blocks =
[paging_options: %PagingOptions{page_size: 4}]
|> Chain.list_blocks()
@ -38,7 +36,7 @@ defmodule BlockScoutWeb.ChainController do
render(
conn,
"show.html",
address_estimated_count: address_count_module.address_estimated_count(),
address_estimated_count: Chain.address_estimated_count(),
average_block_time: Chain.average_block_time(),
blocks: blocks,
exchange_rate: exchange_rate,

@ -9,8 +9,7 @@ defmodule BlockScoutWeb.Notifier do
alias BlockScoutWeb.Endpoint
def handle_event({:chain_event, :addresses, addresses}) do
address_count_module = Application.get_env(:block_scout_web, :fake_adapter) || Chain
Endpoint.broadcast("addresses:new_address", "count", %{count: address_count_module.address_estimated_count()})
Endpoint.broadcast("addresses:new_address", "count", %{count: Chain.address_estimated_count()})
addresses
|> Stream.reject(fn %Address{fetched_coin_balance: fetched_coin_balance} -> is_nil(fetched_coin_balance) end)

@ -164,7 +164,7 @@ defmodule BlockScoutWeb.AddressView do
def token_title(%Token{name: name, symbol: symbol}), do: "#{name} (#{symbol})"
def transaction_count(%Address{} = address) do
Chain.address_to_transaction_count_estimate(address)
Chain.address_to_transactions_estimated_count(address)
end
def trimmed_hash(%Hash{} = hash) do

@ -12,7 +12,7 @@ defmodule BlockScoutWeb.AddressChannelTest do
Notifier.handle_event({:chain_event, :addresses, [address]})
receive do
%Phoenix.Socket.Broadcast{topic: ^topic, event: "count", payload: %{count: 1}} ->
%Phoenix.Socket.Broadcast{topic: ^topic, event: "count", payload: %{count: _}} ->
assert true
after
5_000 ->

@ -1,8 +1,6 @@
defmodule BlockScoutWeb.AddressControllerTest do
use BlockScoutWeb.ConnCase
alias Explorer.Chain.{Address, Wei}
describe "GET index/2" do
test "returns top addresses", %{conn: conn} do
address_hashes =

@ -1,8 +0,0 @@
defmodule BlockScoutWeb.FakeAdapter do
alias Explorer.Chain.Address
alias Explorer.Repo
def address_estimated_count do
Repo.aggregate(Address, :count, :hash)
end
end

@ -137,8 +137,8 @@ defmodule Explorer.Chain do
Gets an estimated count of `t:Explorer.Chain.Transaction.t/0` to or from the `address` based on the estimated rows
resulting in an EXPLAIN of the query plan for the count query.
"""
@spec address_to_transaction_count_estimate(Address.t()) :: non_neg_integer()
def address_to_transaction_count_estimate(%Address{hash: address_hash}) do
@spec address_to_transactions_estimated_count(Address.t()) :: non_neg_integer()
def address_to_transactions_estimated_count(%Address{hash: address_hash}) do
{:ok, %Postgrex.Result{rows: result}} =
Repo.query(
"""

@ -277,6 +277,12 @@ defmodule Explorer.ChainTest do
end
end
describe "address_to_transactions_estimated_count/1" do
test "returns integer" do
assert is_integer(Chain.address_to_transactions_estimated_count(build(:address)))
end
end
describe "average_block_time/0" do
test "without blocks duration is 0" do
assert Chain.average_block_time() == Timex.Duration.parse!("PT0S")

Loading…
Cancel
Save