Failing regression tests for #1337

pull/1376/head
Luke Imhoff 6 years ago
parent 7098f4b78d
commit 229df065b4
  1. 1
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity/fetched_beneficiaries.ex
  2. 2
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc/parity/fetched_beneficiaries_test.exs
  3. 102
      apps/indexer/test/indexer/block/catchup/fetcher_test.exs
  4. 44
      apps/indexer/test/indexer/block/uncataloged_rewards/importer_test.exs

@ -30,7 +30,6 @@ defmodule EthereumJSONRPC.Parity.FetchedBeneficiaries do
...> }, ...> },
...> %{ ...> %{
...> "action" => %{"author" => "0x2", "rewardType" => "external", "value" => "0x0"}, ...> "action" => %{"author" => "0x2", "rewardType" => "external", "value" => "0x0"},
...> "blockHash" => "0x52a8d2185282506ce681364d2aa0c085ba45fdeb5d6c0ddec1131617a71ee2ca",
...> "blockHash" => "0xFFF", ...> "blockHash" => "0xFFF",
...> "blockNumber" => 12, ...> "blockNumber" => 12,
...> "result" => nil, ...> "result" => nil,

@ -41,7 +41,7 @@ defmodule EthereumJSONRPC.Parity.FetchedBeneficiariesTest do
block_number = 1_000 block_number = 1_000
block_quantity = EthereumJSONRPC.integer_to_quantity(block_number) block_quantity = EthereumJSONRPC.integer_to_quantity(block_number)
hash1 = "0xef481b4e2c3ed62265617f2e9dfcdf3cf3efc11a" hash1 = "0xef481b4e2c3ed62265617f2e9dfcdf3cf3efc11a"
hash2 = "0x523b6539ff08d72a6c8bb598af95bf50c1ea839c" hash2 = "0xef481b4e2c3ed62265617f2e9dfcdf3cf3efc11a"
reward = "0xde0b6b3a7640000" reward = "0xde0b6b3a7640000"
responses = [ responses = [

@ -2,6 +2,7 @@ defmodule Indexer.Block.Catchup.FetcherTest do
use EthereumJSONRPC.Case, async: false use EthereumJSONRPC.Case, async: false
use Explorer.DataCase use Explorer.DataCase
import EthereumJSONRPC, only: [integer_to_quantity: 1]
import Mox import Mox
alias Indexer.{Block, CoinBalance, InternalTransaction, Token, TokenBalance} alias Indexer.{Block, CoinBalance, InternalTransaction, Token, TokenBalance}
@ -111,4 +112,105 @@ defmodule Indexer.Block.Catchup.FetcherTest do
assert_receive {:uncles, [^uncle_hash]} assert_receive {:uncles, [^uncle_hash]}
end end
end end
describe "task/1" do
test "ignores fetched beneficiaries with different hash for same number", %{
json_rpc_named_arguments: json_rpc_named_arguments
} do
latest_block_number = 1
latest_block_quantity = integer_to_quantity(latest_block_number)
block_number = latest_block_number - 1
block_hash = block_hash()
block_quantity = integer_to_quantity(block_number)
miner_hash = address_hash()
miner_hash_data = to_string(miner_hash)
new_block_hash = block_hash()
refute block_hash == new_block_hash
EthereumJSONRPC.Mox
|> expect(:json_rpc, fn %{method: "eth_getBlockByNumber", params: ["latest", false]}, _options ->
{:ok, %{"number" => latest_block_quantity}}
end)
|> expect(:json_rpc, fn [
%{
id: id,
jsonrpc: "2.0",
method: "eth_getBlockByNumber",
params: [^block_quantity, true]
}
],
_options ->
{:ok,
[
%{
id: id,
jsonrpc: "2.0",
result: %{
"hash" => to_string(block_hash),
"number" => block_quantity,
"difficulty" => "0x0",
"gasLimit" => "0x0",
"gasUsed" => "0x0",
"extraData" => "0x0",
"logsBloom" => "0x0",
"miner" => miner_hash_data,
"parentHash" =>
block_hash()
|> to_string(),
"receiptsRoot" => "0x0",
"size" => "0x0",
"sha3Uncles" => "0x0",
"stateRoot" => "0x0",
"timestamp" => "0x0",
"totalDifficulty" => "0x0",
"transactions" => [],
"transactionsRoot" => "0x0",
"uncles" => []
}
}
]}
end)
|> expect(:json_rpc, fn [%{id: id, jsonrpc: "2.0", method: "trace_block", params: [^block_quantity]}], _options ->
{
:ok,
[
%{
id: id,
jsonrpc: "2.0",
result: [
%{
"action" => %{
"author" => miner_hash_data,
"rewardType" => "external",
"value" => "0x0"
},
"blockHash" => to_string(new_block_hash),
"blockNumber" => block_number,
"result" => nil,
"subtraces" => 0,
"traceAddress" => [],
"transactionHash" => nil,
"transactionPosition" => nil,
"type" => "reward"
}
]
}
]
}
end)
assert {:ok, _} =
Fetcher.task(%Fetcher{
blocks_batch_size: 1,
block_fetcher: %Block.Fetcher{
callback_module: Fetcher,
json_rpc_named_arguments: json_rpc_named_arguments
}
})
end
end
end end

@ -97,5 +97,49 @@ defmodule Indexer.Block.UncatalogedRewards.ImporterTest do
assert {:ok, [%Reward{block_hash: ^block_hash, address_type: ^address_type, reward: ^reward}]} = assert {:ok, [%Reward{block_hash: ^block_hash, address_type: ^address_type, reward: ^reward}]} =
Importer.fetch_and_import_rewards([block]) Importer.fetch_and_import_rewards([block])
end end
# regression test for https://github.com/poanetwork/blockscout/issues/1337
test "with different block hash due to consensus switch between database query and trace_block" do
miner = insert(:address)
block = insert(:block, miner: miner)
block_hash = block.hash
address_type = :validator
insert(:reward, block_hash: block_hash, address_hash: miner.hash, address_type: address_type, reward: 1)
value = "0x2"
expect(EthereumJSONRPC.Mox, :json_rpc, fn [%{id: id, method: "trace_block"}], _options ->
trace_block_block_hash = block_hash()
refute trace_block_block_hash == block_hash
{:ok,
[
%{
id: id,
result: [
%{
"action" => %{
"author" => to_string(miner),
"rewardType" => "external",
"value" => value
},
"blockHash" => to_string(trace_block_block_hash),
"blockNumber" => block.number,
"result" => nil,
"subtraces" => 0,
"traceAddress" => [],
"transactionHash" => nil,
"transactionPosition" => nil,
"type" => "reward"
}
]
}
]}
end)
{:ok, reward} = Wei.cast(value)
assert {:ok, []} = Importer.fetch_and_import_rewards([block])
end
end end
end end

Loading…
Cancel
Save