|
|
|
@ -3,10 +3,9 @@ defmodule Indexer.Block.UncatalogedRewards.ImporterTest do |
|
|
|
|
use Explorer.DataCase |
|
|
|
|
|
|
|
|
|
import Mox |
|
|
|
|
import EthereumJSONRPC, only: [integer_to_quantity: 1] |
|
|
|
|
import EthereumJSONRPC.Case |
|
|
|
|
|
|
|
|
|
alias Explorer.Chain |
|
|
|
|
alias Explorer.Chain.Wei |
|
|
|
|
alias Explorer.Chain.Block.Reward |
|
|
|
|
alias Indexer.Block.UncatalogedRewards.Importer |
|
|
|
|
|
|
|
|
|
describe "fetch_and_import_rewards/1" do |
|
|
|
@ -49,7 +48,7 @@ defmodule Indexer.Block.UncatalogedRewards.ImporterTest do |
|
|
|
|
{:ok, |
|
|
|
|
[ |
|
|
|
|
ok: %{ |
|
|
|
|
"insert_0" => %Explorer.Chain.Block.Reward{ |
|
|
|
|
"insert_0" => %Reward{ |
|
|
|
|
address_hash: address.hash, |
|
|
|
|
block_hash: block.hash, |
|
|
|
|
address_type: :validator |
|
|
|
@ -60,5 +59,47 @@ defmodule Indexer.Block.UncatalogedRewards.ImporterTest do |
|
|
|
|
result = Importer.fetch_and_import_rewards([block]) |
|
|
|
|
assert result = expected |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@tag :no_geth |
|
|
|
|
test "replaces reward on conflict" 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 -> |
|
|
|
|
{:ok, |
|
|
|
|
[ |
|
|
|
|
%{ |
|
|
|
|
id: id, |
|
|
|
|
result: [ |
|
|
|
|
%{ |
|
|
|
|
"action" => %{ |
|
|
|
|
"author" => to_string(miner), |
|
|
|
|
"rewardType" => "external", |
|
|
|
|
"value" => value |
|
|
|
|
}, |
|
|
|
|
"blockHash" => to_string(block_hash), |
|
|
|
|
"blockNumber" => block.number, |
|
|
|
|
"result" => nil, |
|
|
|
|
"subtraces" => 0, |
|
|
|
|
"traceAddress" => [], |
|
|
|
|
"transactionHash" => nil, |
|
|
|
|
"transactionPosition" => nil, |
|
|
|
|
"type" => "reward" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
]} |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
{:ok, reward} = Wei.cast(value) |
|
|
|
|
|
|
|
|
|
assert {:ok, |
|
|
|
|
[ok: %{"insert_0" => %Reward{block_hash: ^block_hash, address_type: ^address_type, reward: ^reward}}]} = |
|
|
|
|
Importer.fetch_and_import_rewards([block]) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|