fix: Error on internal transactions CSV export (#10495)

pull/10502/head
nikitosing 4 months ago committed by GitHub
parent c6ff374d8c
commit 2984bcf5b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      apps/explorer/lib/explorer/chain/csv_export/address_internal_transaction_csv_exporter.ex
  2. 118
      apps/explorer/test/explorer/chain/csv_export/address_internal_transaction_csv_exporter_test.exs

@ -95,7 +95,8 @@ defmodule Explorer.Chain.CSVExport.AddressInternalTransactionCsvExporter do
internal_transaction.input,
internal_transaction.output,
internal_transaction.error,
gas_price && gas_price |> Wei.mult(internal_transaction.gas_used) |> Wei.to(:wei)
gas_price && internal_transaction.gas_used &&
gas_price |> Wei.mult(internal_transaction.gas_used) |> Wei.to(:wei)
]
end)

@ -196,5 +196,123 @@ defmodule Explorer.Chain.CSVExport.AddressInternalTransactionCsvExporterTest do
assert Enum.count(result) == 600
end
test "don't fall on is_nil(gas_used)" do
address = insert(:address)
transaction =
:transaction
|> insert()
|> with_block()
internal_transaction =
insert(:internal_transaction,
index: 1,
transaction: transaction,
from_address: address,
block_number: transaction.block_number,
block_hash: transaction.block_hash,
block_index: 1,
transaction_index: transaction.index,
error: "reverted",
gas_used: nil,
output: nil
)
from_period = Timex.format!(Timex.shift(Timex.now(), minutes: -1), "%Y-%m-%d", :strftime)
to_period = Timex.format!(Timex.now(), "%Y-%m-%d", :strftime)
res =
address.hash
|> AddressInternalTransactionCsvExporter.export(from_period, to_period)
|> Enum.to_list()
|> Enum.drop(1)
[result] =
res
|> Enum.map(fn [
[[], transaction_hash],
_,
[[], index],
_,
[[], block_number],
_,
[[], block_hash],
_,
[[], block_index],
_,
[[], transaction_index],
_,
[[], timestamp],
_,
[[], from_address_hash],
_,
[[], to_address_hash],
_,
[[], created_contract_address_hash],
_,
[[], type],
_,
[[], call_type],
_,
[[], gas],
_,
[[], gas_used],
_,
[[], value],
_,
[[], input],
_,
[[], output],
_,
[[], error],
_,
[[], fee],
_
] ->
%{
transaction_hash: transaction_hash,
index: index,
block_number: block_number,
block_index: block_index,
block_hash: block_hash,
transaction_index: transaction_index,
timestamp: timestamp,
from_address_hash: from_address_hash,
to_address_hash: to_address_hash,
created_contract_address_hash: created_contract_address_hash,
type: type,
call_type: call_type,
gas: gas,
gas_used: gas_used,
value: value,
input: input,
output: output,
error: error,
fee: fee
}
end)
assert result.transaction_hash == to_string(internal_transaction.transaction_hash)
assert result.index == to_string(internal_transaction.index)
assert result.block_number == to_string(internal_transaction.block_number)
assert result.block_index == to_string(internal_transaction.block_index)
assert result.block_hash == to_string(internal_transaction.block_hash)
assert result.transaction_index == to_string(internal_transaction.transaction_index)
assert result.timestamp
assert result.from_address_hash == Address.checksum(internal_transaction.from_address_hash)
assert result.to_address_hash == Address.checksum(internal_transaction.to_address_hash)
assert result.created_contract_address_hash == to_string(internal_transaction.created_contract_address_hash)
assert result.type == to_string(internal_transaction.type)
assert result.call_type == to_string(internal_transaction.call_type)
assert result.gas == to_string(internal_transaction.gas)
assert result.gas_used == ""
assert result.value == internal_transaction.value |> Wei.to(:wei) |> to_string()
assert result.input == to_string(internal_transaction.input)
assert result.output == to_string(internal_transaction.output)
assert result.error == to_string(internal_transaction.error)
assert result.fee == ""
end
end
end

Loading…
Cancel
Save