Add a TransactionReceiptImporter test for always-pending transactions

pull/4/head
Doc Ritezel 7 years ago
parent 063f6069f8
commit 897bdca512
  1. 10
      lib/explorer/importers/transaction_receipt_importer.ex
  2. 8
      test/explorer/importers/transaction_receipt_importer_test.exs
  3. 30
      test/support/fixture/vcr_cassettes/transaction_importer_import_1_pending.json

@ -18,11 +18,11 @@ defmodule Explorer.TransactionReceiptImporter do
@dialyzer {:nowarn_function, download_receipt: 1}
defp download_receipt(hash) do
{:ok, receipt} = eth_get_transaction_receipt(hash)
receipt
receipt || %{}
end
defp ingest_receipt(receipt) do
hash = String.downcase(receipt["transactionHash"])
hash = String.downcase("#{receipt["transactionHash"]}")
query = from transaction in Transaction,
left_join: receipt in assoc(transaction, :receipt),
where: fragment("lower(?)", transaction.hash) == ^hash,
@ -51,8 +51,8 @@ defmodule Explorer.TransactionReceiptImporter do
}
end
defp decode_integer_field(hex) do
{"0x", base_16} = String.split_at(hex, 2)
String.to_integer(base_16, 16)
defp decode_integer_field("0x" <> hex) when is_binary(hex) do
String.to_integer(hex, 16)
end
defp decode_integer_field(field), do: field
end

@ -29,5 +29,13 @@ defmodule Explorer.TransactionReceiptImporterTest do
assert Repo.all(TransactionReceipt) |> Enum.count() == 0
end
end
test "does not process a forever-pending receipt" do
insert(:transaction, hash: "0xde791cfcde3900d4771e5fcf8c11dc305714118df7aa7e42f84576e64dbf6246")
use_cassette "transaction_importer_import_1_pending" do
TransactionReceiptImporter.import("0xde791cfcde3900d4771e5fcf8c11dc305714118df7aa7e42f84576e64dbf6246")
assert Repo.all(TransactionReceipt) |> Enum.count() == 0
end
end
end
end

@ -0,0 +1,30 @@
[
{
"request": {
"body": "{\"params\":[\"0xde791cfcde3900d4771e5fcf8c11dc305714118df7aa7e42f84576e64dbf6246\"],\"method\":\"eth_getTransactionReceipt\",\"jsonrpc\":\"2.0\",\"id\":0}",
"headers": {
"Content-Type": "application/json"
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://sokol.poa.network"
},
"response": {
"binary": false,
"body": "{\"jsonrpc\":\"2.0\",\"result\":null,\"id\":0}\n",
"headers": {
"Date": "Wed, 14 Feb 2018 22:44:27 GMT",
"Content-Type": "application/json",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive",
"Set-Cookie": "__cfduid=d7190cf3b5f318c3eeb548439c39114181518648267; expires=Thu, 14-Feb-19 22:44:27 GMT; path=/; domain=.poa.network; HttpOnly; Secure",
"Expect-CT": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
"Server": "cloudflare",
"CF-RAY": "3ed38d582f866cbe-SJC"
},
"status_code": 200,
"type": "ok"
}
}
]
Loading…
Cancel
Save