From ae9f4140ea002fa56a3b934f2102f00595630467 Mon Sep 17 00:00:00 2001 From: svenski123 Date: Sat, 3 Nov 2018 03:41:24 +0000 Subject: [PATCH] Fixup test cases --- .../controllers/address_controller_test.exs | 4 +++- apps/explorer/lib/explorer/chain.ex | 17 +++++++++-------- apps/explorer/test/explorer/chain_test.exs | 12 ++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs index 1ad14d2952..071667cf77 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs @@ -10,7 +10,9 @@ defmodule BlockScoutWeb.AddressControllerTest do conn = get(conn, address_path(conn, :index)) - assert conn.assigns.addresses |> Enum.map(& &1.hash) == address_hashes + assert conn.assigns.address_tx_count_pairs + |> Enum.map(fn {address, _transaction_count} -> address end) + |> Enum.map(& &1.hash) == address_hashes end end diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index e48eeb957a..8cfb97bfcf 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -923,14 +923,15 @@ defmodule Explorer.Chain do @spec list_top_addresses :: [{Address.t(), non_neg_integer()}] def list_top_addresses do query = - from a in Address, - left_join: t in Transaction, - on: a.hash == t.from_address_hash, - where: a.fetched_coin_balance > ^0, - group_by: [a.hash, a.fetched_coin_balance], - order_by: [desc: a.fetched_coin_balance, asc: a.hash], - select: {a, fragment("coalesce(1 + max(?), 0)", t.nonce)}, - limit: 250 + from(a in Address, + left_join: t in Transaction, + on: a.hash == t.from_address_hash, + where: a.fetched_coin_balance > ^0, + group_by: [a.hash, a.fetched_coin_balance], + order_by: [desc: a.fetched_coin_balance, asc: a.hash], + select: {a, fragment("coalesce(1 + max(?), 0)", t.nonce)}, + limit: 250 + ) Repo.all(query) end diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index a27a28df6f..0ed17acb4e 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -1183,9 +1183,9 @@ defmodule Explorer.ChainTest do |> Enum.map(& &1.hash) assert address_hashes == - Chain.list_top_addresses() - |> Enum.map(fn {address, _transaction_count} -> address end) - |> Enum.map(& &1.hash) + Chain.list_top_addresses() + |> Enum.map(fn {address, _transaction_count} -> address end) + |> Enum.map(& &1.hash) end test "with top addresses in order with matching value" do @@ -1205,9 +1205,9 @@ defmodule Explorer.ChainTest do |> Map.fetch!(:hash) assert [first_result_hash | tail] == - Chain.list_top_addresses() - |> Enum.map(fn {address, _transaction_count} -> address end) - |> Enum.map(& &1.hash) + Chain.list_top_addresses() + |> Enum.map(fn {address, _transaction_count} -> address end) + |> Enum.map(& &1.hash) end end