|
|
|
@ -9,6 +9,7 @@ defmodule Indexer.Block.Catchup.FetcherTest do |
|
|
|
|
alias Explorer.Chain.Block.Reward |
|
|
|
|
alias Explorer.Chain.Hash |
|
|
|
|
alias Explorer.Utility.MissingRangesManipulator |
|
|
|
|
alias Explorer.Utility.MissingBlockRange |
|
|
|
|
alias Indexer.Block |
|
|
|
|
alias Indexer.Block.Catchup.Fetcher |
|
|
|
|
alias Indexer.Block.Catchup.MissingRangesCollector |
|
|
|
@ -606,6 +607,63 @@ defmodule Indexer.Block.Catchup.FetcherTest do |
|
|
|
|
|
|
|
|
|
assert_receive {:block_numbers, [^block_number]}, 5_000 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "failed blocks handles correctly", %{json_rpc_named_arguments: json_rpc_named_arguments} do |
|
|
|
|
Application.put_env(:indexer, Indexer.Block.Catchup.Fetcher, batch_size: 2, concurrency: 10) |
|
|
|
|
Application.put_env(:indexer, :block_ranges, "0..1") |
|
|
|
|
start_supervised!({Task.Supervisor, name: Indexer.Block.Catchup.TaskSupervisor}) |
|
|
|
|
MissingRangesCollector.start_link([]) |
|
|
|
|
MissingRangesManipulator.start_link([]) |
|
|
|
|
|
|
|
|
|
EthereumJSONRPC.Mox |
|
|
|
|
|> expect(:json_rpc, 2, fn |
|
|
|
|
[ |
|
|
|
|
%{ |
|
|
|
|
id: id_1, |
|
|
|
|
jsonrpc: "2.0", |
|
|
|
|
method: "eth_getBlockByNumber", |
|
|
|
|
params: ["0x1", true] |
|
|
|
|
}, |
|
|
|
|
%{ |
|
|
|
|
id: id_2, |
|
|
|
|
jsonrpc: "2.0", |
|
|
|
|
method: "eth_getBlockByNumber", |
|
|
|
|
params: ["0x0", true] |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
_options -> |
|
|
|
|
{:ok, |
|
|
|
|
[ |
|
|
|
|
%{ |
|
|
|
|
id: id_1, |
|
|
|
|
jsonrpc: "2.0", |
|
|
|
|
error: %{message: "error"} |
|
|
|
|
}, |
|
|
|
|
%{ |
|
|
|
|
id: id_2, |
|
|
|
|
jsonrpc: "2.0", |
|
|
|
|
error: %{message: "error"} |
|
|
|
|
} |
|
|
|
|
]} |
|
|
|
|
|
|
|
|
|
[], _options -> |
|
|
|
|
{:ok, []} |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
Process.sleep(50) |
|
|
|
|
|
|
|
|
|
assert %{first_block_number: 1, last_block_number: 0, missing_block_count: 2, shrunk: false} = |
|
|
|
|
Fetcher.task(%Fetcher{ |
|
|
|
|
block_fetcher: %Block.Fetcher{ |
|
|
|
|
callback_module: Fetcher, |
|
|
|
|
json_rpc_named_arguments: json_rpc_named_arguments |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
Process.sleep(1000) |
|
|
|
|
|
|
|
|
|
assert %{from_number: 1, to_number: 0} = Repo.one(MissingBlockRange) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp count(schema) do |
|
|
|
|