From a92df4cbf5b7c1b840310ddb86df96f6899845e1 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 22 Feb 2019 15:13:57 +0300 Subject: [PATCH] fix query --- .../explorer/chain/import/runner/addresses.ex | 2 +- .../temporary/failed_created_addresses.ex | 2 +- .../failed_created_addresses_test.exs | 53 +++++++++++++++++-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/addresses.ex b/apps/explorer/lib/explorer/chain/import/runner/addresses.ex index 23530a74e7..8a3ab2eb02 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/addresses.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/addresses.ex @@ -87,7 +87,7 @@ defmodule Explorer.Chain.Import.Runner.Addresses do from(address in Address, update: [ set: [ - contract_code: fragment("COALESCE(?, EXCLUDED.contract_code)", address.contract_code), + contract_code: fragment("COALESCE(EXCLUDED.contract_code, ?)", address.contract_code), # ARGMAX on two columns fetched_coin_balance: fragment( diff --git a/apps/indexer/lib/indexer/temporary/failed_created_addresses.ex b/apps/indexer/lib/indexer/temporary/failed_created_addresses.ex index ebed35ddfa..00b7a45960 100644 --- a/apps/indexer/lib/indexer/temporary/failed_created_addresses.ex +++ b/apps/indexer/lib/indexer/temporary/failed_created_addresses.ex @@ -24,7 +24,7 @@ defmodule Indexer.Temporary.FailedCreatedAddresses do |> code_entry() |> Indexer.Code.Fetcher.run(json_rpc_named_arguments) - internal_transaction.transaction_index + internal_transaction.transaction |> transaction_entry() |> Indexer.InternalTransaction.Fetcher.run(json_rpc_named_arguments) end) diff --git a/apps/indexer/test/indexer/temporary/failed_created_addresses_test.exs b/apps/indexer/test/indexer/temporary/failed_created_addresses_test.exs index 4880cc3e05..ac4591dd0b 100644 --- a/apps/indexer/test/indexer/temporary/failed_created_addresses_test.exs +++ b/apps/indexer/test/indexer/temporary/failed_created_addresses_test.exs @@ -4,9 +4,12 @@ defmodule Indexer.Temporary.FailedCreatedAddressesTest do import Mox + import Ecto.Query + alias Explorer.Repo - alias Explorer.Chain.InternalTransaction + alias Explorer.Chain.{Address, InternalTransaction, Transaction} alias Indexer.Temporary.FailedCreatedAddresses + alias Indexer.CoinBalance @moduletag capture_log: true @@ -15,9 +18,27 @@ defmodule Indexer.Temporary.FailedCreatedAddressesTest do setup :verify_on_exit! describe "run/1" do + @tag :no_parity + @tag :no_geth test "updates failed replaced transactions", %{json_rpc_named_arguments: json_rpc_named_arguments} do - transaction = :transaction |> insert(status: 0, error: "Reverted") |> with_block() - address = insert(:address) + CoinBalance.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) + + block = insert(:block) + + transaction = + :transaction + |> insert( + status: 0, + error: "Reverted", + internal_transactions_indexed_at: DateTime.utc_now(), + block: block, + block_number: block.number, + cumulative_gas_used: 200, + gas_used: 100, + index: 0 + ) + + address = insert(:address, contract_code: "0x0102030405") internal_transaction = insert(:internal_transaction, @@ -63,8 +84,7 @@ defmodule Indexer.Temporary.FailedCreatedAddressesTest do "action" => %{ "from" => "0x2d07e106b5d280e4ccc2d10deee62441c91d4340", "gas" => "0xb2ab", - "init" => - "0x608060405234801561001057600080fd5b5060d38061001f6000396000f3fe6080604052600436106038577c010000000000000000000000000000000000000000000000000000000060003504633ccfd60b8114604f575b3360009081526020819052604090208025434019055005b348015605a57600080fd5b5060616063565b005b33600081815260208190526040808220805490839055905190929183156108fc02918491818181858888f1935050505015801560a3573d6000803e3d6000fd5b505056fea165627a7a72305820e9a226f249def650de957dd8b4127b85a3049d6bfa818cadc4e2d3c44b6a53530029", + "init" => "0x4bb278f3", "value" => "0x0" }, "result" => %{ @@ -86,6 +106,29 @@ defmodule Indexer.Temporary.FailedCreatedAddressesTest do end FailedCreatedAddresses.run(json_rpc_named_arguments) + + query = + from(t in Transaction, + where: t.hash == ^transaction.hash, + preload: [internal_transactions: :created_contract_address] + ) + + fetched_transaction = Repo.one(query) + + assert Enum.count(fetched_transaction.internal_transactions) == 2 + + assert Enum.all?(fetched_transaction.internal_transactions, fn it -> + it.error && is_nil(it.created_contract_address_hash) + end) + + fetched_address = + Repo.one( + from(a in Address, + where: a.hash == ^address.hash + ) + ) + + assert fetched_address.contract_code == %Explorer.Chain.Data{bytes: ""} end end end