Merge branch 'master' into ab-cache-max-min-block-number

pull/1388/head
Ayrat Badykov 6 years ago committed by GitHub
commit b13466a046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/explorer/lib/explorer/chain/import/runner/blocks.ex
  2. 6
      apps/explorer/lib/explorer/chain/import/runner/internal_transactions.ex
  3. 55
      apps/explorer/test/explorer/chain/import_test.exs

@ -66,7 +66,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
where_forked: where_forked where_forked: where_forked
}) })
end) end)
|> Multi.run(:lose_consenus, fn repo, _ -> |> Multi.run(:lose_consensus, fn repo, _ ->
lose_consensus(repo, ordered_consensus_block_numbers, insert_options) lose_consensus(repo, ordered_consensus_block_numbers, insert_options)
end) end)
|> Multi.run(:delete_address_token_balances, fn repo, _ -> |> Multi.run(:delete_address_token_balances, fn repo, _ ->

@ -51,10 +51,8 @@ defmodule Explorer.Chain.Import.Runner.InternalTransactions do
|> Multi.run(:internal_transactions, fn repo, _ -> |> Multi.run(:internal_transactions, fn repo, _ ->
insert(repo, changes_list, insert_options) insert(repo, changes_list, insert_options)
end) end)
|> Multi.run(:internal_transactions_indexed_at_transactions, fn repo, |> Multi.run(:internal_transactions_indexed_at_transactions, fn repo, _ ->
%{internal_transactions: internal_transactions} update_transactions(repo, changes_list, update_transactions_options)
when is_list(internal_transactions) ->
update_transactions(repo, internal_transactions, update_transactions_options)
end) end)
end end

@ -565,6 +565,61 @@ defmodule Explorer.Chain.ImportTest do
assert address.contract_code != smart_contract_bytecode assert address.contract_code != smart_contract_bytecode
end end
test "updates `error`, `status` and `internal_transaction_indexed_at` even if internal transactions were alreader inserted" do
address_hash = "0x1c494fa496f1cfd918b5ff190835af3aaf609899"
from_address = insert(:address, hash: address_hash)
block = insert(:block, consensus: true)
transaction =
:transaction
|> insert(error: nil, internal_transactions_indexed_at: nil, status: nil, from_address: from_address, status: 0)
|> with_block(block, status: :error)
internal_transacton =
insert(:internal_transaction,
transaction_hash: transaction.hash,
error: "Bad Instruction",
index: 0,
gas_used: nil,
output: nil,
gas: 19,
type: "call"
)
options = %{
internal_transactions: %{
params: [
%{
block_number: internal_transacton.block_number,
call_type: internal_transacton.type,
gas: internal_transacton.gas,
gas_used: internal_transacton.gas_used,
index: internal_transacton.index,
output: internal_transacton.output,
transaction_hash: internal_transacton.transaction_hash,
type: internal_transacton.type,
from_address_hash: address_hash,
to_address_hash: address_hash,
trace_address: [],
value: 0,
transaction_index: 0,
error: internal_transacton.error,
input: internal_transacton.input
}
]
}
}
{:ok, _} = Import.all(options)
assert result =
%Transaction{error: "Bad Instruction", status: :error} =
Repo.one!(from(t in Transaction, where: t.hash == ^transaction.hash))
assert result.internal_transactions_indexed_at
end
test "with internal_transactions updates Transaction internal_transactions_indexed_at" do test "with internal_transactions updates Transaction internal_transactions_indexed_at" do
block_hash = "0xe52d77084cab13a4e724162bcd8c6028e5ecfaa04d091ee476e96b9958ed6b47" block_hash = "0xe52d77084cab13a4e724162bcd8c6028e5ecfaa04d091ee476e96b9958ed6b47"
block_number = 34 block_number = 34

Loading…
Cancel
Save