Rename block_rewards to emission_rewards

pull/1184/head
William Sanches 6 years ago
parent 17292ad89b
commit 23bd2b0049
No known key found for this signature in database
GPG Key ID: 27250E49FB133014
  1. 12
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs
  2. 4
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/block_controller_test.exs
  3. 10
      apps/explorer/lib/explorer/chain.ex
  4. 27
      apps/explorer/lib/explorer/chain/block/emission_reward.ex
  5. 8
      apps/explorer/lib/explorer/chain/block/reward.ex
  6. 4
      apps/explorer/lib/explorer/etherscan.ex
  7. 7
      apps/explorer/priv/repo/migrations/20181206200140_rename_block_rewards_to_emission_rewards.exs
  8. 12
      apps/explorer/test/explorer/chain_test.exs
  9. 24
      apps/explorer/test/explorer/etherscan_test.exs
  10. 6
      apps/explorer/test/support/factory.ex

@ -2053,7 +2053,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
end end
test "returns all the required fields", %{conn: conn} do test "returns all the required fields", %{conn: conn} do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) block = insert(:block, number: Enum.random(Range.new(range.from, range.to)))
@ -2062,7 +2062,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
|> with_block(block, gas_used: 1) |> with_block(block, gas_used: 1)
expected_reward = expected_reward =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(1)) |> Decimal.add(Decimal.new(1))
|> Wei.from(:wei) |> Wei.from(:wei)
@ -2092,7 +2092,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
end end
test "with a block with one transaction", %{conn: conn} do test "with a block with one transaction", %{conn: conn} do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) block = insert(:block, number: Enum.random(Range.new(range.from, range.to)))
@ -2101,7 +2101,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
|> with_block(block, gas_used: 1) |> with_block(block, gas_used: 1)
expected_reward = expected_reward =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(1)) |> Decimal.add(Decimal.new(1))
|> Wei.from(:wei) |> Wei.from(:wei)
@ -2131,7 +2131,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
end end
test "with pagination options", %{conn: conn} do test "with pagination options", %{conn: conn} do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block_numbers = Range.new(range.from, range.to) block_numbers = Range.new(range.from, range.to)
@ -2147,7 +2147,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
|> with_block(block2, gas_used: 2) |> with_block(block2, gas_used: 2)
expected_reward = expected_reward =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(4)) |> Decimal.add(Decimal.new(4))
|> Wei.from(:wei) |> Wei.from(:wei)

@ -41,7 +41,7 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
end end
test "with a valid block", %{conn: conn} do test "with a valid block", %{conn: conn} do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) block = insert(:block, number: Enum.random(Range.new(range.from, range.to)))
:transaction :transaction
@ -49,7 +49,7 @@ defmodule BlockScoutWeb.API.RPC.BlockControllerTest do
|> with_block(block, gas_used: 1) |> with_block(block, gas_used: 1)
expected_reward = expected_reward =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(1)) |> Decimal.add(Decimal.new(1))
|> Decimal.to_string(:normal) |> Decimal.to_string(:normal)

@ -38,7 +38,7 @@ defmodule Explorer.Chain do
Wei Wei
} }
alias Explorer.Chain.Block.Reward alias Explorer.Chain.Block.EmissionReward
alias Explorer.{PagingOptions, Repo} alias Explorer.{PagingOptions, Repo}
alias Explorer.Counters.{ alias Explorer.Counters.{
@ -366,15 +366,15 @@ defmodule Explorer.Chain do
from( from(
block in Block, block in Block,
left_join: transaction in assoc(block, :transactions), left_join: transaction in assoc(block, :transactions),
inner_join: block_reward in Reward, inner_join: emission_reward in EmissionReward,
on: fragment("? <@ ?", block.number, block_reward.block_range), on: fragment("? <@ ?", block.number, emission_reward.block_range),
where: block.number == ^block_number, where: block.number == ^block_number,
group_by: block_reward.reward, group_by: emission_reward.reward,
select: %{ select: %{
transaction_reward: %Wei{ transaction_reward: %Wei{
value: default_if_empty(sum_of_products(transaction.gas_used, transaction.gas_price), 0) value: default_if_empty(sum_of_products(transaction.gas_used, transaction.gas_price), 0)
}, },
static_reward: block_reward.reward static_reward: emission_reward.reward
} }
) )

@ -0,0 +1,27 @@
defmodule Explorer.Chain.Block.EmissionReward do
@moduledoc """
Represents the static reward given to the miner of a block in a range of block numbers.
"""
use Ecto.Schema
alias Explorer.Chain.Block.{EmissionReward, Range}
alias Explorer.Chain.Wei
@typedoc """
The static reward given to the miner of a block.
* `:block_range` - Range of block numbers
* `:reward` - Reward given in Wei
"""
@type t :: %EmissionReward{
block_range: Range.t(),
reward: Wei.t()
}
@primary_key false
schema "emission_rewards" do
field(:block_range, Range)
field(:reward, Wei)
end
end

@ -1,11 +1,11 @@
defmodule Explorer.Chain.Block.Reward do defmodule Explorer.Chain.Block.EmissionReward do
@moduledoc """ @moduledoc """
Represents the static reward given to the miner of a block in a range of block numbers. Represents the static reward given to the miner of a block in a range of block numbers.
""" """
use Ecto.Schema use Ecto.Schema
alias Explorer.Chain.Block.{Range, Reward} alias Explorer.Chain.Block.{EmissionReward, Range}
alias Explorer.Chain.Wei alias Explorer.Chain.Wei
@typedoc """ @typedoc """
@ -14,13 +14,13 @@ defmodule Explorer.Chain.Block.Reward do
* `:block_range` - Range of block numbers * `:block_range` - Range of block numbers
* `:reward` - Reward given in Wei * `:reward` - Reward given in Wei
""" """
@type t :: %Reward{ @type t :: %EmissionReward{
block_range: Range.t(), block_range: Range.t(),
reward: Wei.t() reward: Wei.t()
} }
@primary_key false @primary_key false
schema "block_rewards" do schema "emission_rewards" do
field(:block_range, Range) field(:block_range, Range)
field(:reward, Wei) field(:reward, Wei)
end end

@ -9,7 +9,7 @@ defmodule Explorer.Etherscan do
alias Explorer.{Chain, Repo} alias Explorer.{Chain, Repo}
alias Explorer.Chain.Address.TokenBalance alias Explorer.Chain.Address.TokenBalance
alias Explorer.Chain.{Block, Hash, InternalTransaction, Transaction, Wei} alias Explorer.Chain.{Block, Hash, InternalTransaction, Transaction, Wei}
alias Explorer.Chain.Block.Reward alias Explorer.Chain.Block.EmissionReward
@default_options %{ @default_options %{
order_by_direction: :asc, order_by_direction: :asc,
@ -186,7 +186,7 @@ defmodule Explorer.Etherscan do
from( from(
b in Block, b in Block,
left_join: t in assoc(b, :transactions), left_join: t in assoc(b, :transactions),
inner_join: r in Reward, inner_join: r in EmissionReward,
on: fragment("? <@ ?", b.number, r.block_range), on: fragment("? <@ ?", b.number, r.block_range),
where: b.miner_hash == ^address_hash, where: b.miner_hash == ^address_hash,
order_by: [desc: b.number], order_by: [desc: b.number],

@ -0,0 +1,7 @@
defmodule Explorer.Repo.Migrations.RenameBlockRewardsToEmissionRewards do
use Ecto.Migration
def change do
rename(table(:block_rewards), to: table(:emission_rewards))
end
end

@ -2159,15 +2159,15 @@ defmodule Explorer.ChainTest do
describe "block_reward/1" do describe "block_reward/1" do
setup do setup do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) block = insert(:block, number: Enum.random(Range.new(range.from, range.to)))
insert(:transaction) insert(:transaction)
{:ok, block: block, block_reward: block_reward} {:ok, block: block, emission_reward: emission_reward}
end end
test "with block containing transactions", %{block: block, block_reward: block_reward} do test "with block containing transactions", %{block: block, emission_reward: emission_reward} do
:transaction :transaction
|> insert(gas_price: 1) |> insert(gas_price: 1)
|> with_block(block, gas_used: 1) |> with_block(block, gas_used: 1)
@ -2177,7 +2177,7 @@ defmodule Explorer.ChainTest do
|> with_block(block, gas_used: 2) |> with_block(block, gas_used: 2)
expected = expected =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(3)) |> Decimal.add(Decimal.new(3))
|> Wei.from(:wei) |> Wei.from(:wei)
@ -2185,8 +2185,8 @@ defmodule Explorer.ChainTest do
assert expected == Chain.block_reward(block) assert expected == Chain.block_reward(block)
end end
test "with block without transactions", %{block: block, block_reward: block_reward} do test "with block without transactions", %{block: block, emission_reward: emission_reward} do
assert block_reward.reward == Chain.block_reward(block) assert emission_reward.reward == Chain.block_reward(block)
end end
end end

@ -1168,7 +1168,7 @@ defmodule Explorer.EtherscanTest do
describe "list_blocks/1" do describe "list_blocks/1" do
test "it returns all required fields" do test "it returns all required fields" do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) block = insert(:block, number: Enum.random(Range.new(range.from, range.to)))
@ -1180,7 +1180,7 @@ defmodule Explorer.EtherscanTest do
|> with_block(block, gas_used: 1) |> with_block(block, gas_used: 1)
expected_reward = expected_reward =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(1)) |> Decimal.add(Decimal.new(1))
|> Wei.from(:wei) |> Wei.from(:wei)
@ -1197,7 +1197,7 @@ defmodule Explorer.EtherscanTest do
end end
test "with block containing multiple transactions" do test "with block containing multiple transactions" do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) block = insert(:block, number: Enum.random(Range.new(range.from, range.to)))
@ -1213,7 +1213,7 @@ defmodule Explorer.EtherscanTest do
|> with_block(block, gas_used: 2) |> with_block(block, gas_used: 2)
expected_reward = expected_reward =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(3)) |> Decimal.add(Decimal.new(3))
|> Wei.from(:wei) |> Wei.from(:wei)
@ -1230,7 +1230,7 @@ defmodule Explorer.EtherscanTest do
end end
test "with block without transactions" do test "with block without transactions" do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block = insert(:block, number: Enum.random(Range.new(range.from, range.to))) block = insert(:block, number: Enum.random(Range.new(range.from, range.to)))
@ -1241,7 +1241,7 @@ defmodule Explorer.EtherscanTest do
%{ %{
number: block.number, number: block.number,
timestamp: block.timestamp, timestamp: block.timestamp,
reward: block_reward.reward reward: emission_reward.reward
} }
] ]
@ -1249,7 +1249,7 @@ defmodule Explorer.EtherscanTest do
end end
test "with multiple blocks" do test "with multiple blocks" do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block_numbers = Range.new(range.from, range.to) block_numbers = Range.new(range.from, range.to)
@ -1280,13 +1280,13 @@ defmodule Explorer.EtherscanTest do
|> with_block(block2, gas_used: 3) |> with_block(block2, gas_used: 3)
expected_reward_block1 = expected_reward_block1 =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(8)) |> Decimal.add(Decimal.new(8))
|> Wei.from(:wei) |> Wei.from(:wei)
expected_reward_block2 = expected_reward_block2 =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(18)) |> Decimal.add(Decimal.new(18))
|> Wei.from(:wei) |> Wei.from(:wei)
@ -1308,7 +1308,7 @@ defmodule Explorer.EtherscanTest do
end end
test "with pagination options" do test "with pagination options" do
%{block_range: range} = block_reward = insert(:block_reward) %{block_range: range} = emission_reward = insert(:emission_reward)
block_numbers = Range.new(range.from, range.to) block_numbers = Range.new(range.from, range.to)
@ -1324,7 +1324,7 @@ defmodule Explorer.EtherscanTest do
|> with_block(block1, gas_used: 2) |> with_block(block1, gas_used: 2)
expected_reward = expected_reward =
block_reward.reward emission_reward.reward
|> Wei.to(:wei) |> Wei.to(:wei)
|> Decimal.add(Decimal.new(4)) |> Decimal.add(Decimal.new(4))
|> Wei.from(:wei) |> Wei.from(:wei)
@ -1333,7 +1333,7 @@ defmodule Explorer.EtherscanTest do
%{ %{
number: block2.number, number: block2.number,
timestamp: block2.timestamp, timestamp: block2.timestamp,
reward: block_reward.reward reward: emission_reward.reward
} }
] ]

@ -9,7 +9,7 @@ defmodule Explorer.Factory do
alias Comeonin.Bcrypt alias Comeonin.Bcrypt
alias Explorer.Accounts.{User, UserContact} alias Explorer.Accounts.{User, UserContact}
alias Explorer.Admin.Administrator alias Explorer.Admin.Administrator
alias Explorer.Chain.Block.{Range, Reward} alias Explorer.Chain.Block.{EmissionReward, Range}
alias Explorer.Chain.{ alias Explorer.Chain.{
Address, Address,
@ -404,7 +404,7 @@ defmodule Explorer.Factory do
} }
end end
def block_reward_factory do def emission_reward_factory do
# Generate ranges like 1 - 10,000; 10,001 - 20,000, 20,001 - 30,000; etc # Generate ranges like 1 - 10,000; 10,001 - 20,000, 20,001 - 30,000; etc
x = sequence("block_range", & &1) x = sequence("block_range", & &1)
lower = x * Kernel.+(10_000, 1) lower = x * Kernel.+(10_000, 1)
@ -419,7 +419,7 @@ defmodule Explorer.Factory do
reward = Decimal.mult(reward_multiplier, wei_per_ether) reward = Decimal.mult(reward_multiplier, wei_per_ether)
%Reward{ %EmissionReward{
block_range: %Range{from: lower, to: upper}, block_range: %Range{from: lower, to: upper},
reward: reward reward: reward
} }

Loading…
Cancel
Save