Add 'block_number' and 'transaction_index' in 'internal_transaction'

* Denormalize the internal_transaction table so we don't need to join the 'transactions' table to know the block_number and index
pull/928/head
Amanda Sposito 6 years ago
parent b86335cf34
commit 1acebdc7f7
  1. 22
      apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs
  2. 27
      apps/explorer/lib/explorer/chain.ex
  3. 41
      apps/explorer/lib/explorer/chain/internal_transaction.ex
  4. 17
      apps/explorer/priv/repo/migrations/20181011193212_add_fields_to_internal_transactions.exs
  5. 35
      apps/explorer/test/explorer/chain/import_test.exs
  6. 3
      apps/explorer/test/explorer/chain/internal_transaction_test.exs
  7. 296
      apps/explorer/test/explorer/chain_test.exs
  8. 108
      apps/explorer/test/explorer/etherscan_test.exs
  9. 4
      apps/explorer/test/explorer/repo_test.exs

@ -81,7 +81,9 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
:internal_transaction,
transaction: transaction_1,
from_address: address,
index: index
index: index,
block_number: transaction_1.block_number,
transaction_index: transaction_1.index
)
end)
|> Enum.map(&"#{&1.transaction_hash}.#{&1.index}")
@ -93,7 +95,9 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
:internal_transaction,
transaction: transaction_2,
from_address: address,
index: index
index: index,
block_number: transaction_2.block_number,
transaction_index: transaction_2.index
)
end)
|> Enum.map(&"#{&1.transaction_hash}.#{&1.index}")
@ -105,7 +109,9 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
:internal_transaction,
transaction: transaction_3,
from_address: address,
index: index
index: index,
block_number: transaction_3.block_number,
transaction_index: transaction_3.index
)
end)
|> Enum.map(&"#{&1.transaction_hash}.#{&1.index}")
@ -113,8 +119,14 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do
second_page_hashes = transaction_1_hashes ++ transaction_2_hashes ++ transaction_3_hashes
%InternalTransaction{index: index} =
:internal_transaction
|> insert(transaction: transaction_3, from_address: address, index: 11)
insert(
:internal_transaction,
transaction: transaction_3,
from_address: address,
index: 11,
block_number: transaction_3.block_number,
transaction_index: transaction_3.index
)
conn =
get(conn, address_internal_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{

@ -96,8 +96,8 @@ defmodule Explorer.Chain do
@doc """
`t:Explorer.Chain.InternalTransaction/0`s from `address`.
This function excludes any internal transactions in the results where the internal transaction has no siblings within
the parent transaction.
This function excludes any internal transactions in the results where the
internal transaction has no siblings within the parent transaction.
## Options
@ -122,20 +122,14 @@ defmodule Explorer.Chain do
paging_options = Keyword.get(options, :paging_options, @default_paging_options)
InternalTransaction
|> join(
:inner,
[internal_transaction],
transaction in assoc(internal_transaction, :transaction)
)
|> join(:left, [internal_transaction, transaction], block in assoc(transaction, :block))
|> InternalTransaction.where_address_fields_match(hash, direction)
|> where_transaction_has_multiple_internal_transactions()
|> page_internal_transaction(paging_options)
|> limit(^paging_options.page_size)
|> order_by(
[it, transaction, block],
desc: block.number,
desc: transaction.index,
[it],
desc: it.block_number,
desc: it.transaction_index,
desc: it.index
)
|> preload(transaction: :block)
@ -1838,11 +1832,12 @@ defmodule Explorer.Chain do
defp page_internal_transaction(query, %PagingOptions{key: {block_number, transaction_index, index}}) do
where(
query,
[internal_transaction, transaction],
transaction.block_number < ^block_number or
(transaction.block_number == ^block_number and transaction.index < ^transaction_index) or
(transaction.block_number == ^block_number and transaction.index == ^transaction_index and
internal_transaction.index < ^index)
[internal_transaction],
internal_transaction.block_number < ^block_number or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index < ^transaction_index) or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index == ^transaction_index and internal_transaction.index < ^index)
)
end

@ -62,6 +62,8 @@ defmodule Explorer.Chain.InternalTransaction do
field(:trace_address, {:array, :integer})
field(:type, Type)
field(:value, Wei)
field(:block_number, :integer)
field(:transaction_index, :integer)
timestamps()
@ -112,7 +114,8 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [],
...> transaction_hash: "0x3a3eb134e6792ce9403ea4188e5e79693de9e4c94e499db132be086400da79e6",
...> type: "create",
...> value: 0
...> value: 0,
...> block_number: 35
...> }
...> )
iex> changeset.valid?
@ -151,6 +154,7 @@ defmodule Explorer.Chain.InternalTransaction do
...> transaction_hash: "0x3c624bb4852fb5e35a8f45644cec7a486211f6ba89034768a2b763194f22f97d",
...> type: "create",
...> value: 0,
...> block_number: 35,
...> transaction_index: 0
...> }
iex> )
@ -177,7 +181,9 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [],
...> transaction_hash: "0x3a3eb134e6792ce9403ea4188e5e79693de9e4c94e499db132be086400da79e6",
...> type: "call",
...> value: 0
...> value: 0,
...> block_number: 35,
...> transaction_index: 0
...> }
...> )
iex> changeset.valid?
@ -197,7 +203,9 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [],
...> transaction_hash: "0xcd7c15dbbc797722bef6e1d551edfd644fc7f4fb2ccd6a7947b2d1ade9ed140b",
...> type: "call",
...> value: 10000000000000000
...> value: 10000000000000000,
...> block_number: 35,
...> transaction_index: 0
...> }
...> )
iex> changeset.valid?
@ -220,7 +228,9 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [],
...> transaction_hash: "0xcd7c15dbbc797722bef6e1d551edfd644fc7f4fb2ccd6a7947b2d1ade9ed140b",
...> type: "call",
...> value: 10000000000000000
...> value: 10000000000000000,
...> block_number: 35,
...> transaction_index: 0
...> }
...> )
iex> changeset.valid?
@ -244,7 +254,9 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [],
...> transaction_hash: "0xcd7c15dbbc797722bef6e1d551edfd644fc7f4fb2ccd6a7947b2d1ade9ed140b",
...> type: "call",
...> value: 10000000000000000
...> value: 10000000000000000,
...> block_number: 35,
...> transaction_index: 0
...> }
...> )
iex> changeset.valid?
@ -272,7 +284,9 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [],
...> transaction_hash: "0x3c624bb4852fb5e35a8f45644cec7a486211f6ba89034768a2b763194f22f97d",
...> type: "create",
...> value: 0
...> value: 0,
...> block_number: 35,
...> transaction_index: 0
...> }
iex> )
iex> changeset.valid?
@ -296,7 +310,9 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [],
...> transaction_hash: "0x3a3eb134e6792ce9403ea4188e5e79693de9e4c94e499db132be086400da79e6",
...> type: "create",
...> value: 0
...> value: 0,
...> block_number: 35,
...> transaction_index: 0
...> }
...> )
iex> changeset.valid?
@ -319,7 +335,9 @@ defmodule Explorer.Chain.InternalTransaction do
...> trace_address: [0],
...> transaction_hash: "0xb012b8c53498c669d87d85ed90f57385848b86d3f44ed14b2784ec685d6fda98",
...> type: "suicide",
...> value: 0
...> value: 0,
...> block_number: 35,
...> transaction_index: 0
...> }
...> )
iex> changeset.valid?
@ -339,7 +357,7 @@ defmodule Explorer.Chain.InternalTransaction do
type_changeset(changeset, attrs, type)
end
@call_optional_fields ~w(error gas_used output)
@call_optional_fields ~w(error gas_used output block_number transaction_index)
@call_required_fields ~w(call_type from_address_hash gas index to_address_hash trace_address transaction_hash value)a
@call_allowed_fields @call_optional_fields ++ @call_required_fields
@ -354,7 +372,7 @@ defmodule Explorer.Chain.InternalTransaction do
|> unique_constraint(:index)
end
@create_optional_fields ~w(error created_contract_code created_contract_address_hash gas_used)
@create_optional_fields ~w(error created_contract_code created_contract_address_hash gas_used block_number transaction_index)
@create_required_fields ~w(from_address_hash gas index init trace_address transaction_hash value)a
@create_allowed_fields @create_optional_fields ++ @create_required_fields
@ -369,8 +387,9 @@ defmodule Explorer.Chain.InternalTransaction do
|> unique_constraint(:index)
end
@suicide_optional_fields ~w(block_number transaction_index)
@suicide_required_fields ~w(from_address_hash index to_address_hash trace_address transaction_hash type value)a
@suicide_allowed_fields @suicide_required_fields
@suicide_allowed_fields @suicide_optional_fields ++ @suicide_required_fields
defp type_changeset(changeset, attrs, :suicide) do
changeset

@ -0,0 +1,17 @@
defmodule Explorer.Repo.Migrations.AddFieldsToInternalTransactions do
use Ecto.Migration
def up do
alter table("internal_transactions") do
add(:block_number, :integer)
add(:transaction_index, :integer)
end
end
def down do
alter table("internal_transactions") do
remove(:block_number)
remove(:transaction_index)
end
end
end

@ -56,7 +56,9 @@ defmodule Explorer.Chain.ImportTest do
trace_address: [],
transaction_hash: "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
type: "call",
value: 0
value: 0,
block_number: 35,
transaction_index: 0
},
%{
call_type: "call",
@ -69,7 +71,9 @@ defmodule Explorer.Chain.ImportTest do
trace_address: [],
transaction_hash: "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
type: "call",
value: 0
value: 0,
block_number: 35,
transaction_index: 1
}
],
timeout: 5
@ -497,7 +501,9 @@ defmodule Explorer.Chain.ImportTest do
trace_address: [],
transaction_hash: transaction_string_hash,
type: "create",
value: 0
value: 0,
block_number: 35,
transaction_index: 0
}
]
}
@ -580,6 +586,7 @@ defmodule Explorer.Chain.ImportTest do
transaction_hash: transaction_hash,
type: "call",
value: 0,
transaction_block_number: 35,
transaction_index: 0
}
]
@ -765,7 +772,9 @@ defmodule Explorer.Chain.ImportTest do
trace_address: [],
transaction_hash: "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
type: "create",
value: 0
value: 0,
block_number: 35,
transaction_index: 0
},
%{
created_contract_address_hash: "0xffc87239eb0267bc3ca2cd51d12fbf278e02ccb5",
@ -780,7 +789,9 @@ defmodule Explorer.Chain.ImportTest do
trace_address: [],
transaction_hash: "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
type: "create",
value: 0
value: 0,
block_number: 35,
transaction_index: 1
}
],
timeout: 5
@ -951,7 +962,8 @@ defmodule Explorer.Chain.ImportTest do
transaction_hash: "0x1a263224a95275d77bc30a7e131bc64d948777946a790c0915ab293791fbcb61",
type: "create",
value: 0,
transaction_index: 0
transaction_index: 0,
transaction_block_number: 35
},
%{
block_number: 6_546_180,
@ -964,7 +976,8 @@ defmodule Explorer.Chain.ImportTest do
transaction_hash: "0xab349efbe1ddc6d85d84a993aa52bdaadce66e8ee166dd10013ce3f2a94ca724",
type: "create",
value: 0,
transaction_index: 0
transaction_index: 0,
transaction_block_number: 35
}
]
}
@ -1445,7 +1458,9 @@ defmodule Explorer.Chain.ImportTest do
transaction_hash: transaction_hash,
index: 0,
from_address_hash: from_address_hash,
to_address_hash: to_address_hash
to_address_hash: to_address_hash,
block_number: 35,
transaction_index: 0
)
],
timeout: 1
@ -1711,7 +1726,9 @@ defmodule Explorer.Chain.ImportTest do
to_address_hash: to_address_hash_before,
trace_address: [],
value: 0,
error: error
error: error,
block_number: 35,
transaction_index: 0
}
]
}

@ -22,7 +22,8 @@ defmodule Explorer.Chain.InternalTransactionTest do
trace_address: [0, 1],
transaction_hash: transaction.hash,
type: "call",
value: 100
value: 100,
block_number: 35
})
assert changeset.valid?

@ -193,7 +193,12 @@ defmodule Explorer.ChainTest do
|> with_block()
%InternalTransaction{created_contract_address: address} =
insert(:internal_transaction_create, transaction: transaction, index: 0)
insert(:internal_transaction_create,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
assert [] == Chain.address_to_transactions(address)
end
@ -687,10 +692,20 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block()
insert(:internal_transaction, transaction: transaction, index: 0)
insert(:internal_transaction,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
Enum.each(1..3, fn index ->
insert(:internal_transaction_create, transaction: transaction, index: index)
insert(:internal_transaction_create,
transaction: transaction,
index: index,
block_number: transaction.block_number,
transaction_index: transaction.index
)
end)
assert {:ok, %Transaction{hash: ^hash_with_block}} = Chain.hash_to_transaction(hash_with_block)
@ -1250,10 +1265,22 @@ defmodule Explorer.ChainTest do
transaction = insert(:transaction)
%InternalTransaction{id: first_id} =
insert(:internal_transaction, index: 0, transaction: transaction, to_address: address)
insert(:internal_transaction,
index: 0,
transaction: transaction,
to_address: address,
block_number: transaction.block_number,
transaction_index: transaction.index
)
%InternalTransaction{id: second_id} =
insert(:internal_transaction, index: 1, transaction: transaction, to_address: address)
insert(:internal_transaction,
index: 1,
transaction: transaction,
to_address: address,
block_number: transaction.block_number,
transaction_index: transaction.index
)
result = address |> Chain.address_to_internal_transactions() |> Enum.map(& &1.id)
assert Enum.member?(result, first_id)
@ -1263,8 +1290,22 @@ defmodule Explorer.ChainTest do
test "loads associations in necessity_by_association" do
address = insert(:address)
transaction = insert(:transaction, to_address: address)
insert(:internal_transaction, transaction: transaction, to_address: address, index: 0)
insert(:internal_transaction, transaction: transaction, to_address: address, index: 1)
insert(:internal_transaction,
transaction: transaction,
to_address: address,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
insert(:internal_transaction,
transaction: transaction,
to_address: address,
index: 1,
block_number: transaction.block_number,
transaction_index: transaction.index
)
assert [
%InternalTransaction{
@ -1303,7 +1344,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: pending_transaction,
to_address: address,
index: 0
index: 1,
block_number: pending_transaction.block_number,
transaction_index: pending_transaction.index
)
%InternalTransaction{id: second_pending} =
@ -1311,7 +1354,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: pending_transaction,
to_address: address,
index: 1
index: 2,
block_number: pending_transaction.block_number,
transaction_index: pending_transaction.index
)
a_block = insert(:block, number: 2000)
@ -1326,7 +1371,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_a_transaction,
to_address: address,
index: 0
index: 1,
block_number: first_a_transaction.block_number,
transaction_index: first_a_transaction.index
)
%InternalTransaction{id: second} =
@ -1334,7 +1381,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_a_transaction,
to_address: address,
index: 1
index: 2,
block_number: first_a_transaction.block_number,
transaction_index: first_a_transaction.index
)
second_a_transaction =
@ -1347,7 +1396,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: second_a_transaction,
to_address: address,
index: 0
index: 1,
block_number: second_a_transaction.block_number,
transaction_index: second_a_transaction.index
)
%InternalTransaction{id: fourth} =
@ -1355,7 +1406,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: second_a_transaction,
to_address: address,
index: 1
index: 2,
block_number: second_a_transaction.block_number,
transaction_index: second_a_transaction.index
)
b_block = insert(:block, number: 6000)
@ -1370,7 +1423,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_b_transaction,
to_address: address,
index: 0
index: 1,
block_number: first_b_transaction.block_number,
transaction_index: first_b_transaction.index
)
%InternalTransaction{id: sixth} =
@ -1378,7 +1433,15 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_b_transaction,
to_address: address,
index: 1
<<<<<<< HEAD
index: 1,
transaction_index: first_b_transaction.index,
block_number: first_b_transaction.block_number
=======
index: 2,
block_number: first_b_transaction.block_number,
transaction_index: first_b_transaction.index
>>>>>>> c06b04ad... fixup! Add 'block_number' and 'transaction_index' in 'internal_transaction'
)
result =
@ -1398,14 +1461,24 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: pending_transaction,
to_address: address,
index: 0
<<<<<<< HEAD
index: 0,
transaction_index: pending_transaction.index
=======
index: 1,
>>>>>>> c06b04ad... fixup! Add 'block_number' and 'transaction_index' in 'internal_transaction'
)
insert(
:internal_transaction,
transaction: pending_transaction,
to_address: address,
index: 1
<<<<<<< HEAD
index: 1,
transaction_index: pending_transaction.index
=======
index: 2,
>>>>>>> c06b04ad... fixup! Add 'block_number' and 'transaction_index' in 'internal_transaction'
)
a_block = insert(:block, number: 2000)
@ -1420,7 +1493,15 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_a_transaction,
to_address: address,
index: 0
<<<<<<< HEAD
index: 0,
transaction_index: first_a_transaction.index,
block_number: first_a_transaction.block_number
=======
index: 1,
block_number: first_a_transaction.block_number,
transaction_index: first_a_transaction.index
>>>>>>> c06b04ad... fixup! Add 'block_number' and 'transaction_index' in 'internal_transaction'
)
%InternalTransaction{id: second} =
@ -1428,7 +1509,15 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_a_transaction,
to_address: address,
index: 1
<<<<<<< HEAD
index: 1,
transaction_index: first_a_transaction.index,
block_number: first_a_transaction.block_number
=======
index: 2,
block_number: first_a_transaction.block_number,
transaction_index: first_a_transaction.index
>>>>>>> c06b04ad... fixup! Add 'block_number' and 'transaction_index' in 'internal_transaction'
)
second_a_transaction =
@ -1441,7 +1530,15 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: second_a_transaction,
to_address: address,
index: 0
<<<<<<< HEAD
index: 0,
transaction_index: second_a_transaction.index,
block_number: second_a_transaction.block_number
=======
index: 1,
block_number: second_a_transaction.block_number,
transaction_index: second_a_transaction.index
>>>>>>> c06b04ad... fixup! Add 'block_number' and 'transaction_index' in 'internal_transaction'
)
%InternalTransaction{id: fourth} =
@ -1449,7 +1546,15 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: second_a_transaction,
to_address: address,
index: 1
<<<<<<< HEAD
index: 1,
transaction_index: second_a_transaction.index,
block_number: second_a_transaction.block_number
=======
index: 2,
block_number: second_a_transaction.block_number,
transaction_index: second_a_transaction.index
>>>>>>> c06b04ad... fixup! Add 'block_number' and 'transaction_index' in 'internal_transaction'
)
b_block = insert(:block, number: 6000)
@ -1464,7 +1569,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_b_transaction,
to_address: address,
index: 0
index: 1,
block_number: first_b_transaction.block_number,
transaction_index: first_b_transaction.index
)
%InternalTransaction{id: sixth} =
@ -1472,7 +1579,9 @@ defmodule Explorer.ChainTest do
:internal_transaction,
transaction: first_b_transaction,
to_address: address,
index: 1
index: 2,
block_number: first_b_transaction.block_number,
transaction_index: first_b_transaction.index
)
# When paged, internal transactions need an associated block number, so `second_pending` and `first_pending` are
@ -1517,7 +1626,13 @@ defmodule Explorer.ChainTest do
|> insert(to_address: address)
|> with_block()
insert(:internal_transaction, index: 0, to_address: address, transaction: transaction)
insert(:internal_transaction,
index: 0,
to_address: address,
transaction: transaction,
block_number: transaction.block_number,
transaction_index: transaction.index
)
assert Enum.empty?(Chain.address_to_internal_transactions(address))
end
@ -1535,7 +1650,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
index: 0,
from_address: address,
transaction: transaction
transaction: transaction,
block_number: transaction.block_number,
transaction_index: transaction.index
)
actual = Enum.at(Chain.address_to_internal_transactions(address), 0)
@ -1592,8 +1709,21 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block(block)
first = insert(:internal_transaction, transaction: transaction, index: 0)
second = insert(:internal_transaction, transaction: transaction, index: 1)
first =
insert(:internal_transaction,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
second =
insert(:internal_transaction,
transaction: transaction,
index: 1,
block_number: transaction.block_number,
transaction_index: transaction.index
)
results = [internal_transaction | _] = Chain.transaction_to_internal_transactions(transaction)
@ -1604,7 +1734,13 @@ defmodule Explorer.ChainTest do
test "with transaction with internal transactions loads associations with in necessity_by_association" do
transaction = insert(:transaction)
insert(:internal_transaction_create, transaction: transaction, index: 0)
insert(:internal_transaction_create,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
assert [
%InternalTransaction{
@ -1637,7 +1773,12 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block()
insert(:internal_transaction, transaction: transaction, index: 0)
insert(:internal_transaction,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
result = Chain.transaction_to_internal_transactions(transaction)
@ -1650,7 +1791,13 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block()
expected = insert(:internal_transaction_create, index: 0, transaction: transaction)
expected =
insert(:internal_transaction_create,
index: 0,
transaction: transaction,
block_number: transaction.block_number,
transaction_index: transaction.index
)
actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0)
@ -1663,7 +1810,14 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block()
expected = insert(:internal_transaction, index: 0, transaction: transaction, type: :reward)
expected =
insert(:internal_transaction,
index: 0,
transaction: transaction,
type: :reward,
block_number: transaction.block_number,
transaction_index: transaction.index
)
actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0)
@ -1676,7 +1830,15 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block()
expected = insert(:internal_transaction, index: 0, transaction: transaction, gas: nil, type: :suicide)
expected =
insert(:internal_transaction,
index: 0,
transaction: transaction,
gas: nil,
type: :suicide,
block_number: transaction.block_number,
transaction_index: transaction.index
)
actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0)
@ -1689,8 +1851,21 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block()
%InternalTransaction{id: first_id} = insert(:internal_transaction, transaction: transaction, index: 0)
%InternalTransaction{id: second_id} = insert(:internal_transaction, transaction: transaction, index: 1)
%InternalTransaction{id: first_id} =
insert(:internal_transaction,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
%InternalTransaction{id: second_id} =
insert(:internal_transaction,
transaction: transaction,
index: 1,
block_number: transaction.block_number,
transaction_index: transaction.index
)
result =
transaction
@ -1706,8 +1881,21 @@ defmodule Explorer.ChainTest do
|> insert()
|> with_block()
%InternalTransaction{id: first_id} = insert(:internal_transaction, transaction: transaction, index: 0)
%InternalTransaction{id: second_id} = insert(:internal_transaction, transaction: transaction, index: 1)
%InternalTransaction{id: first_id} =
insert(:internal_transaction,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
%InternalTransaction{id: second_id} =
insert(:internal_transaction,
transaction: transaction,
index: 1,
block_number: transaction.block_number,
transaction_index: transaction.index
)
assert [^first_id, ^second_id] =
transaction
@ -1993,7 +2181,9 @@ defmodule Explorer.ChainTest do
transaction: transaction,
index: 0,
created_contract_address: created_contract_address,
created_contract_code: smart_contract_bytecode
created_contract_code: smart_contract_bytecode,
block_number: transaction.block_number,
transaction_index: transaction.index
)
assert Chain.smart_contract_bytecode(created_contract_address.hash) == smart_contract_bytecode
@ -2022,7 +2212,9 @@ defmodule Explorer.ChainTest do
transaction: transaction,
index: 0,
created_contract_address: created_contract_address,
created_contract_code: smart_contract_bytecode
created_contract_code: smart_contract_bytecode,
block_number: transaction.block_number,
transaction_index: transaction.index
)
valid_attrs = %{
@ -2220,7 +2412,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
created_contract_address: created_contract_address,
index: 0,
transaction: transaction
transaction: transaction,
block_number: transaction.block_number,
transaction_index: transaction.index
)
balance = insert(:unfetched_balance, address_hash: created_contract_address.hash, block_number: block.number)
@ -2264,7 +2458,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
from_address: from_address,
index: 0,
transaction: transaction
transaction: transaction,
block_number: transaction.block_number,
transaction_index: transaction.index
)
balance = insert(:unfetched_balance, address_hash: from_address.hash, block_number: block.number)
@ -2302,7 +2498,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
to_address: to_address,
index: 0,
transaction: transaction
transaction: transaction,
block_number: transaction.block_number,
transaction_index: transaction.index
)
balance = insert(:unfetched_balance, address_hash: to_address.hash, block_number: block.number)
@ -2369,7 +2567,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
from_address: miner,
index: 0,
transaction: from_internal_transaction_transaction
transaction: from_internal_transaction_transaction,
block_number: from_internal_transaction_transaction.block_number,
transaction_index: from_internal_transaction_transaction.index
)
insert(:unfetched_balance, address_hash: miner.hash, block_number: from_internal_transaction_block.number)
@ -2385,7 +2585,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
index: 0,
to_address: miner,
transaction: to_internal_transaction_transaction
transaction: to_internal_transaction_transaction,
block_number: to_internal_transaction_transaction.block_number,
transaction_index: to_internal_transaction_transaction.index
)
insert(:unfetched_balance, address_hash: miner.hash, block_number: to_internal_transaction_block.number)
@ -2439,7 +2641,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
from_address: miner,
index: 0,
transaction: from_internal_transaction_transaction
transaction: from_internal_transaction_transaction,
block_number: from_internal_transaction_transaction.block_number,
transaction_index: from_internal_transaction_transaction.index
)
to_internal_transaction_transaction =
@ -2451,7 +2655,9 @@ defmodule Explorer.ChainTest do
:internal_transaction_create,
to_address: miner,
index: 0,
transaction: to_internal_transaction_transaction
transaction: to_internal_transaction_transaction,
block_number: to_internal_transaction_transaction.block_number,
transaction_index: to_internal_transaction_transaction.index
)
{:ok, balance_fields_list} =

@ -64,7 +64,12 @@ defmodule Explorer.EtherscanTest do
%{created_contract_address_hash: contract_address_hash} =
:internal_transaction_create
|> insert(transaction: transaction, index: 0)
|> insert(
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
|> with_contract_creation(contract_address)
[found_transaction] = Etherscan.list_transactions(contract_address_hash)
@ -135,7 +140,12 @@ defmodule Explorer.EtherscanTest do
%{created_contract_address_hash: contract_hash} =
:internal_transaction_create
|> insert(transaction: transaction, index: 0)
|> insert(
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index
)
|> with_contract_creation(contract_address)
[found_transaction] = Etherscan.list_transactions(address.hash)
@ -470,7 +480,13 @@ defmodule Explorer.EtherscanTest do
internal_transaction =
:internal_transaction_create
|> insert(transaction: transaction, index: 0, from_address: address)
|> insert(
transaction: transaction,
index: 0,
from_address: address,
block_number: transaction.block_number,
transaction_index: transaction.index
)
|> with_contract_creation(contract_address)
[found_internal_transaction] = Etherscan.list_internal_transactions(transaction.hash)
@ -507,7 +523,12 @@ defmodule Explorer.EtherscanTest do
|> with_block()
for index <- 0..2 do
insert(:internal_transaction, transaction: transaction, index: index)
insert(:internal_transaction,
transaction: transaction,
index: index,
block_number: transaction.block_number,
transaction_index: transaction.index
)
end
found_internal_transactions = Etherscan.list_internal_transactions(transaction.hash)
@ -526,9 +547,27 @@ defmodule Explorer.EtherscanTest do
|> insert()
|> with_block()
insert(:internal_transaction, transaction: transaction1, index: 0)
insert(:internal_transaction, transaction: transaction1, index: 1)
insert(:internal_transaction, transaction: transaction2, index: 0, type: :reward)
insert(:internal_transaction,
transaction: transaction1,
index: 0,
block_number: transaction1.block_number,
transaction_index: transaction1.index
)
insert(:internal_transaction,
transaction: transaction1,
index: 1,
block_number: transaction1.block_number,
transaction_index: transaction1.index
)
insert(:internal_transaction,
transaction: transaction2,
index: 0,
type: :reward,
block_number: transaction2.block_number,
transaction_index: transaction2.index
)
internal_transactions1 = Etherscan.list_internal_transactions(transaction1.hash)
@ -573,7 +612,13 @@ defmodule Explorer.EtherscanTest do
internal_transaction =
:internal_transaction_create
|> insert(transaction: transaction, index: 0, from_address: address)
|> insert(
transaction: transaction,
index: 0,
from_address: address,
block_number: transaction.block_number,
transaction_index: transaction.index
)
|> with_contract_creation(contract_address)
[found_internal_transaction] = Etherscan.list_internal_transactions(address.hash)
@ -616,7 +661,9 @@ defmodule Explorer.EtherscanTest do
internal_transaction_details = %{
transaction: transaction,
index: index,
from_address: address
from_address: address,
block_number: transaction.block_number,
transaction_index: transaction.index
}
insert(:internal_transaction, internal_transaction_details)
@ -636,10 +683,37 @@ defmodule Explorer.EtherscanTest do
|> insert()
|> with_block()
insert(:internal_transaction, transaction: transaction, index: 0, created_contract_address: address1)
insert(:internal_transaction, transaction: transaction, index: 1, from_address: address1)
insert(:internal_transaction, transaction: transaction, index: 2, to_address: address1)
insert(:internal_transaction, transaction: transaction, index: 3, from_address: address2)
insert(:internal_transaction,
transaction: transaction,
index: 0,
block_number: transaction.block_number,
transaction_index: transaction.index,
created_contract_address: address1
)
insert(:internal_transaction,
transaction: transaction,
index: 1,
block_number: transaction.block_number,
transaction_index: transaction.index,
from_address: address1
)
insert(:internal_transaction,
transaction: transaction,
index: 2,
block_number: transaction.block_number,
transaction_index: transaction.index,
to_address: address1
)
insert(:internal_transaction,
transaction: transaction,
index: 3,
block_number: transaction.block_number,
transaction_index: transaction.index,
from_address: address2
)
internal_transactions1 = Etherscan.list_internal_transactions(address1.hash)
@ -662,7 +736,9 @@ defmodule Explorer.EtherscanTest do
internal_transaction_details = %{
transaction: transaction,
index: index,
from_address: address
from_address: address,
block_number: transaction.block_number,
transaction_index: transaction.index
}
insert(:internal_transaction, internal_transaction_details)
@ -700,7 +776,9 @@ defmodule Explorer.EtherscanTest do
internal_transaction_details = %{
transaction: transaction,
index: index,
from_address: address
from_address: address,
block_number: transaction.block_number,
transaction_index: transaction.index
}
insert(:internal_transaction, internal_transaction_details)

@ -18,7 +18,9 @@ defmodule Explorer.RepoTest do
from_address_hash: insert(:address).hash,
to_address_hash: insert(:address).hash,
transaction_hash: transaction.hash,
index: 0
index: 0,
block_number: 35,
transaction_index: 0
)
%Changeset{valid?: true, changes: changes} = InternalTransaction.changeset(%InternalTransaction{}, params)

Loading…
Cancel
Save