From 897bdca51272de4873c50b32ee8ac9d417ad3471 Mon Sep 17 00:00:00 2001 From: Doc Ritezel Date: Wed, 14 Feb 2018 14:53:57 -0800 Subject: [PATCH] Add a TransactionReceiptImporter test for always-pending transactions --- .../importers/transaction_receipt_importer.ex | 10 +++---- .../transaction_receipt_importer_test.exs | 8 +++++ ...transaction_importer_import_1_pending.json | 30 +++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 test/support/fixture/vcr_cassettes/transaction_importer_import_1_pending.json diff --git a/lib/explorer/importers/transaction_receipt_importer.ex b/lib/explorer/importers/transaction_receipt_importer.ex index b08f97e6fc..b0c4e8fd30 100644 --- a/lib/explorer/importers/transaction_receipt_importer.ex +++ b/lib/explorer/importers/transaction_receipt_importer.ex @@ -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 diff --git a/test/explorer/importers/transaction_receipt_importer_test.exs b/test/explorer/importers/transaction_receipt_importer_test.exs index 58317f3069..ca42783fcf 100644 --- a/test/explorer/importers/transaction_receipt_importer_test.exs +++ b/test/explorer/importers/transaction_receipt_importer_test.exs @@ -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 diff --git a/test/support/fixture/vcr_cassettes/transaction_importer_import_1_pending.json b/test/support/fixture/vcr_cassettes/transaction_importer_import_1_pending.json new file mode 100644 index 0000000000..f1f6f5dff8 --- /dev/null +++ b/test/support/fixture/vcr_cassettes/transaction_importer_import_1_pending.json @@ -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" + } + } +] \ No newline at end of file