Skip to content

Commit

Permalink
fix: show creating internal transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 28, 2019
1 parent 608485f commit 6f3accc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- [#2017](https://github.com/poanetwork/blockscout/pull/2017) - fix: fix to/from filters on tx list pages
- [#2008](https://github.com/poanetwork/blockscout/pull/2008) - add new function clause for xDai network beneficiaries
- [#2009](https://github.com/poanetwork/blockscout/pull/2009) - addresses page improvements
- [#2047](https://github.com/poanetwork/blockscout/pull/2047) - fix: show creating internal transactions

### Chore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,49 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
end)
end

test "returns internal an transaction that created the address", %{conn: conn} do
address = insert(:address)

transaction =
:transaction
|> insert()
|> with_block(insert(:block, number: 1))

from_internal_transaction =
insert(:internal_transaction,
transaction: transaction,
from_address: address,
index: 1,
block_number: transaction.block_number,
transaction_index: transaction.index
)

to_internal_transaction =
insert(:internal_transaction,
transaction: transaction,
to_address: nil,
created_contract_address: address,
index: 2,
block_number: transaction.block_number,
transaction_index: transaction.index
)

path = address_internal_transaction_path(conn, :index, address, %{"filter" => "to", "type" => "JSON"})
conn = get(conn, path)

internal_transaction_tiles = json_response(conn, 200)["items"]

assert Enum.any?(internal_transaction_tiles, fn tile ->
String.contains?(tile, to_string(to_internal_transaction.transaction_hash)) &&
String.contains?(tile, "data-internal-transaction-index=\"#{to_internal_transaction.index}\"")
end)

refute Enum.any?(internal_transaction_tiles, fn tile ->
String.contains?(tile, to_string(from_internal_transaction.transaction_hash)) &&
String.contains?(tile, "data-internal-transaction-index=\"#{from_internal_transaction.index}\"")
end)
end

test "returns next page of results based on last seen internal transaction", %{conn: conn} do
address = insert(:address)

Expand Down
7 changes: 6 additions & 1 deletion apps/explorer/lib/explorer/chain/internal_transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,12 @@ defmodule Explorer.Chain.InternalTransaction do
from_address_hash, created_contract_address_hash from internal_transactions' table.
"""
def where_address_fields_match(query, address_hash, :to) do
where(query, [t], t.to_address_hash == ^address_hash)
where(
query,
[t],
t.to_address_hash == ^address_hash or
(is_nil(t.to_address_hash) and t.created_contract_address_hash == ^address_hash)
)
end

def where_address_fields_match(query, address_hash, :from) do
Expand Down

0 comments on commit 6f3accc

Please sign in to comment.