rename method

pull/4312/head
nikitosing 3 years ago
parent 22ac5c2c10
commit d7c0131016
  1. 2
      apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex
  2. 4
      apps/explorer/lib/explorer/chain.ex
  3. 30
      apps/explorer/test/explorer/chain_test.exs

@ -36,7 +36,7 @@ defmodule BlockScoutWeb.AddressTransactionController do
|> Keyword.merge(paging_options(params)) |> Keyword.merge(paging_options(params))
|> Keyword.merge(current_filter(params)) |> Keyword.merge(current_filter(params))
results_plus_one = Chain.address_to_mined_transactions_with_rewards(address_hash, options) results_plus_one = Chain.address_to_transactions_with_rewards(address_hash, options)
{results, next_page} = split_list_by_page(results_plus_one) {results, next_page} = split_list_by_page(results_plus_one)
next_page_url = next_page_url =

@ -332,11 +332,11 @@ defmodule Explorer.Chain do
the `block_number` and `index` that are passed. the `block_number` and `index` that are passed.
""" """
@spec address_to_mined_transactions_with_rewards(Hash.Address.t(), [paging_options | necessity_by_association_option]) :: @spec address_to_transactions_with_rewards(Hash.Address.t(), [paging_options | necessity_by_association_option]) ::
[ [
Transaction.t() Transaction.t()
] ]
def address_to_mined_transactions_with_rewards(address_hash, options \\ []) when is_list(options) do def address_to_transactions_with_rewards(address_hash, options \\ []) when is_list(options) do
paging_options = Keyword.get(options, :paging_options, @default_paging_options) paging_options = Keyword.get(options, :paging_options, @default_paging_options)
if Application.get_env(:block_scout_web, BlockScoutWeb.Chain)[:has_emission_funds] do if Application.get_env(:block_scout_web, BlockScoutWeb.Chain)[:has_emission_funds] do

@ -383,13 +383,13 @@ defmodule Explorer.ChainTest do
end end
end end
describe "address_to_mined_transactions_with_rewards/2" do describe "address_to_transactions_with_rewards/2" do
test "without transactions" do test "without transactions" do
%Address{hash: address_hash} = insert(:address) %Address{hash: address_hash} = insert(:address)
assert Repo.aggregate(Transaction, :count, :hash) == 0 assert Repo.aggregate(Transaction, :count, :hash) == 0
assert [] == Chain.address_to_mined_transactions_with_rewards(address_hash) assert [] == Chain.address_to_transactions_with_rewards(address_hash)
end end
test "with from transactions" do test "with from transactions" do
@ -401,7 +401,7 @@ defmodule Explorer.ChainTest do
|> with_block() |> with_block()
assert [transaction] == assert [transaction] ==
Chain.address_to_mined_transactions_with_rewards(address_hash, direction: :from) Chain.address_to_transactions_with_rewards(address_hash, direction: :from)
|> Repo.preload([:block, :to_address, :from_address]) |> Repo.preload([:block, :to_address, :from_address])
end end
@ -414,7 +414,7 @@ defmodule Explorer.ChainTest do
|> with_block() |> with_block()
assert [transaction] == assert [transaction] ==
Chain.address_to_mined_transactions_with_rewards(address_hash, direction: :to) Chain.address_to_transactions_with_rewards(address_hash, direction: :to)
|> Repo.preload([:block, :to_address, :from_address]) |> Repo.preload([:block, :to_address, :from_address])
end end
@ -428,7 +428,7 @@ defmodule Explorer.ChainTest do
# only contains "from" transaction # only contains "from" transaction
assert [transaction] == assert [transaction] ==
Chain.address_to_mined_transactions_with_rewards(address_hash, direction: :from) Chain.address_to_transactions_with_rewards(address_hash, direction: :from)
|> Repo.preload([:block, :to_address, :from_address]) |> Repo.preload([:block, :to_address, :from_address])
end end
@ -441,7 +441,7 @@ defmodule Explorer.ChainTest do
|> with_block() |> with_block()
assert [transaction] == assert [transaction] ==
Chain.address_to_mined_transactions_with_rewards(address_hash, direction: :to) Chain.address_to_transactions_with_rewards(address_hash, direction: :to)
|> Repo.preload([:block, :to_address, :from_address]) |> Repo.preload([:block, :to_address, :from_address])
end end
@ -460,7 +460,7 @@ defmodule Explorer.ChainTest do
|> with_block(block) |> with_block(block)
assert [transaction2, transaction1] == assert [transaction2, transaction1] ==
Chain.address_to_mined_transactions_with_rewards(address_hash) Chain.address_to_transactions_with_rewards(address_hash)
|> Repo.preload([:block, :to_address, :from_address]) |> Repo.preload([:block, :to_address, :from_address])
end end
@ -481,7 +481,7 @@ defmodule Explorer.ChainTest do
transaction_index: transaction.index transaction_index: transaction.index
) )
assert [] == Chain.address_to_mined_transactions_with_rewards(address.hash) assert [] == Chain.address_to_transactions_with_rewards(address.hash)
end end
test "returns transactions that have token transfers for the given to_address" do test "returns transactions that have token transfers for the given to_address" do
@ -499,7 +499,7 @@ defmodule Explorer.ChainTest do
) )
assert [transaction.hash] == assert [transaction.hash] ==
Chain.address_to_mined_transactions_with_rewards(address_hash) Chain.address_to_transactions_with_rewards(address_hash)
|> Enum.map(& &1.hash) |> Enum.map(& &1.hash)
end end
@ -519,7 +519,7 @@ defmodule Explorer.ChainTest do
assert second_page_hashes == assert second_page_hashes ==
address_hash address_hash
|> Chain.address_to_mined_transactions_with_rewards( |> Chain.address_to_transactions_with_rewards(
paging_options: %PagingOptions{ paging_options: %PagingOptions{
key: {block_number, index}, key: {block_number, index},
page_size: 2 page_size: 2
@ -568,7 +568,7 @@ defmodule Explorer.ChainTest do
result = result =
address_hash address_hash
|> Chain.address_to_mined_transactions_with_rewards() |> Chain.address_to_transactions_with_rewards()
|> Enum.map(& &1.hash) |> Enum.map(& &1.hash)
assert [fourth, third, second, first, sixth, fifth] == result assert [fourth, third, second, first, sixth, fifth] == result
@ -619,7 +619,7 @@ defmodule Explorer.ChainTest do
end end
) )
res = Chain.address_to_mined_transactions_with_rewards(block.miner.hash) res = Chain.address_to_transactions_with_rewards(block.miner.hash)
assert [{_, _}] = res assert [{_, _}] = res
@ -683,7 +683,7 @@ defmodule Explorer.ChainTest do
end end
) )
assert [_, {_, _}] = Chain.address_to_mined_transactions_with_rewards(block.miner.hash, direction: :to) assert [_, {_, _}] = Chain.address_to_transactions_with_rewards(block.miner.hash, direction: :to)
on_exit(fn -> on_exit(fn ->
Application.put_env(:block_scout_web, BlockScoutWeb.Chain, has_emission_funds: false) Application.put_env(:block_scout_web, BlockScoutWeb.Chain, has_emission_funds: false)
@ -719,7 +719,7 @@ defmodule Explorer.ChainTest do
|> with_block() |> with_block()
|> Repo.preload(:token_transfers) |> Repo.preload(:token_transfers)
assert [_] = Chain.address_to_mined_transactions_with_rewards(block.miner.hash, direction: :from) assert [_] = Chain.address_to_transactions_with_rewards(block.miner.hash, direction: :from)
Application.put_env(:block_scout_web, BlockScoutWeb.Chain, has_emission_funds: false) Application.put_env(:block_scout_web, BlockScoutWeb.Chain, has_emission_funds: false)
end end
@ -743,7 +743,7 @@ defmodule Explorer.ChainTest do
address_type: :emission_funds address_type: :emission_funds
) )
assert [] == Chain.address_to_mined_transactions_with_rewards(block.miner.hash) assert [] == Chain.address_to_transactions_with_rewards(block.miner.hash)
end end
end end

Loading…
Cancel
Save