Move call type into fragment

Ecto does not compose the multiple or_where conditions the way that we
need for the filtering and excluding to work correctly.
pull/221/head
Tim Mecklem 7 years ago
parent 9844ca27ad
commit 64f6e921c6
  1. 7
      apps/explorer/lib/explorer/chain.ex
  2. 17
      apps/explorer/test/explorer/chain_test.exs

@ -1856,11 +1856,12 @@ defmodule Explorer.Chain do
defp where_transaction_has_multiple_internal_transactions(query) do
query
|> where([it], it.type == ^:create)
|> or_where(
|> where(
[it, transaction],
fragment(
"(SELECT COUNT(sibling.id) FROM internal_transactions as sibling WHERE sibling.transaction_hash = ?) > 1",
"(? = ? OR (SELECT COUNT(sibling.id) FROM internal_transactions as sibling WHERE sibling.transaction_hash = ?) > 1)",
it.type,
"create",
transaction.hash
)
)

@ -483,7 +483,7 @@ defmodule Explorer.ChainTest do
%InternalTransaction{id: second_id} =
insert(:internal_transaction, index: 1, transaction_hash: transaction.hash, to_address_hash: address.hash)
result = address |> Chain.address_to_internal_transactions() |> Enum.map(&(&1.id))
result = address |> Chain.address_to_internal_transactions() |> Enum.map(& &1.id)
assert Enum.member?(result, first_id)
assert Enum.member?(result, second_id)
end
@ -606,7 +606,7 @@ defmodule Explorer.ChainTest do
address
|> Chain.address_to_internal_transactions()
|> Map.get(:entries, [])
|> Enum.map(&(&1.id))
|> Enum.map(& &1.id)
assert [second_pending, first_pending, sixth, fifth, fourth, third, second, first] == result
end
@ -624,7 +624,14 @@ defmodule Explorer.ChainTest do
address = insert(:address)
block = insert(:block)
transaction = insert(:transaction, block_hash: block.hash, index: 0, to_address_hash: address.hash)
expected = insert(:internal_transaction_create, index: 0, from_address_hash: address.hash, transaction_hash: transaction.hash)
expected =
insert(
:internal_transaction_create,
index: 0,
from_address_hash: address.hash,
transaction_hash: transaction.hash
)
actual = Enum.at(Chain.address_to_internal_transactions(address), 0)
@ -655,7 +662,7 @@ defmodule Explorer.ChainTest do
transaction.hash
|> Chain.transaction_hash_to_internal_transactions()
|> Map.get(:entries, [])
|> Enum.map(&(&1.id))
|> Enum.map(& &1.id)
assert 2 == length(results)
assert Enum.member?(results, first.id)
@ -723,7 +730,7 @@ defmodule Explorer.ChainTest do
result =
hash
|> Chain.transaction_hash_to_internal_transactions()
|> Enum.map(&(&1.id))
|> Enum.map(& &1.id)
assert [first_id, second_id] == result
end

Loading…
Cancel
Save