rename delegators module

pull/2036/head
saneery 6 years ago
parent 2a25481663
commit 93bd9f0a00
  1. 14
      apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex
  2. 4
      apps/explorer/lib/explorer/chain/staking_pool.ex
  3. 6
      apps/explorer/lib/explorer/chain/staking_pools_delegator.ex
  4. 2
      apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs
  5. 18
      apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs
  6. 18
      apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs
  7. 6
      apps/explorer/test/support/factory.ex

@ -1,12 +1,12 @@
defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do
@moduledoc """ @moduledoc """
Bulk imports staking pools to StakingPoolsDelegators tabe. Bulk imports staking pools to StakingPoolsDelegator tabe.
""" """
require Ecto.Query require Ecto.Query
alias Ecto.{Changeset, Multi, Repo} alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, StakingPoolsDelegators} alias Explorer.Chain.{Import, StakingPoolsDelegator}
import Ecto.Query, only: [from: 2] import Ecto.Query, only: [from: 2]
@ -15,10 +15,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do
# milliseconds # milliseconds
@timeout 60_000 @timeout 60_000
@type imported :: [StakingPoolsDelegators.t()] @type imported :: [StakingPoolsDelegator.t()]
@impl Import.Runner @impl Import.Runner
def ecto_schema_module, do: StakingPoolsDelegators def ecto_schema_module, do: StakingPoolsDelegator
@impl Import.Runner @impl Import.Runner
def option_key, do: :staking_pools_delegators def option_key, do: :staking_pools_delegators
@ -54,7 +54,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do
required(:timeout) => timeout, required(:timeout) => timeout,
required(:timestamps) => Import.timestamps() required(:timestamps) => Import.timestamps()
}) :: }) ::
{:ok, [StakingPoolsDelegators.t()]} {:ok, [StakingPoolsDelegator.t()]}
| {:error, [Changeset.t()]} | {:error, [Changeset.t()]}
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0) on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)
@ -65,7 +65,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do
changes_list, changes_list,
conflict_target: [:pool_address_hash, :delegator_address_hash], conflict_target: [:pool_address_hash, :delegator_address_hash],
on_conflict: on_conflict, on_conflict: on_conflict,
for: StakingPoolsDelegators, for: StakingPoolsDelegator,
returning: [:pool_address_hash, :delegator_address_hash], returning: [:pool_address_hash, :delegator_address_hash],
timeout: timeout, timeout: timeout,
timestamps: timestamps timestamps: timestamps
@ -74,7 +74,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do
defp default_on_conflict do defp default_on_conflict do
from( from(
name in StakingPoolsDelegators, name in StakingPoolsDelegator,
update: [ update: [
set: [ set: [
stake_amount: fragment("EXCLUDED.stake_amount"), stake_amount: fragment("EXCLUDED.stake_amount"),

@ -9,7 +9,7 @@ defmodule Explorer.Chain.StakingPool do
alias Explorer.Chain.{ alias Explorer.Chain.{
Address, Address,
Hash, Hash,
StakingPoolsDelegators, StakingPoolsDelegator,
Wei Wei
} }
@ -54,7 +54,7 @@ defmodule Explorer.Chain.StakingPool do
field(:was_banned_count, :integer) field(:was_banned_count, :integer)
field(:was_validator_count, :integer) field(:was_validator_count, :integer)
field(:is_deleted, :boolean, default: false) field(:is_deleted, :boolean, default: false)
has_many(:delegators, StakingPoolsDelegators) has_many(:delegators, StakingPoolsDelegator)
belongs_to( belongs_to(
:staking_address, :staking_address,

@ -1,4 +1,4 @@
defmodule Explorer.Chain.StakingPoolsDelegators do defmodule Explorer.Chain.StakingPoolsDelegator do
@moduledoc """ @moduledoc """
The representation of delegators from POSDAO network. The representation of delegators from POSDAO network.
Delegators make stakes on staking pools and withdraw from them. Delegators make stakes on staking pools and withdraw from them.
@ -55,8 +55,8 @@ defmodule Explorer.Chain.StakingPoolsDelegators do
end end
@doc false @doc false
def changeset(staking_pools_delegators, attrs) do def changeset(staking_pools_delegator, attrs) do
staking_pools_delegators staking_pools_delegator
|> cast(attrs, @attrs) |> cast(attrs, @attrs)
|> validate_required(@attrs) |> validate_required(@attrs)
|> unique_constraint(:pool_address_hash, name: :pools_delegator_index) |> unique_constraint(:pool_address_hash, name: :pools_delegator_index)

@ -1,4 +1,4 @@
defmodule Explorer.Repo.Migrations.CreateStakingPoolsDelegators do defmodule Explorer.Repo.Migrations.CreateStakingPoolsDelegator do
use Ecto.Migration use Ecto.Migration
def change do def change do

@ -0,0 +1,18 @@
defmodule Explorer.Chain.StakingPoolsDelegatorTest do
use Explorer.DataCase
alias Explorer.Chain.StakingPoolsDelegator
describe "changeset/2" do
test "with valid attributes" do
params = params_for(:staking_pools_delegator)
changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, params)
assert changeset.valid?
end
test "with invalid attributes" do
changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, %{pool_address_hash: 0})
refute changeset.valid?
end
end
end

@ -1,18 +0,0 @@
defmodule Explorer.Chain.StakingPoolsDelegatorsTest do
use Explorer.DataCase
alias Explorer.Chain.StakingPoolsDelegators
describe "changeset/2" do
test "with valid attributes" do
params = params_for(:staking_pools_delegators)
changeset = StakingPoolsDelegators.changeset(%StakingPoolsDelegators{}, params)
assert changeset.valid?
end
test "with invalid attributes" do
changeset = StakingPoolsDelegators.changeset(%StakingPoolsDelegators{}, %{pool_address_hash: 0})
refute changeset.valid?
end
end
end

@ -28,7 +28,7 @@ defmodule Explorer.Factory do
TokenTransfer, TokenTransfer,
Transaction, Transaction,
StakingPool, StakingPool,
StakingPoolsDelegators StakingPoolsDelegator
} }
alias Explorer.Market.MarketHistory alias Explorer.Market.MarketHistory
@ -630,10 +630,10 @@ defmodule Explorer.Factory do
} }
end end
def staking_pools_delegators_factory do def staking_pools_delegator_factory do
wei_per_ether = 1_000_000_000_000_000_000 wei_per_ether = 1_000_000_000_000_000_000
%StakingPoolsDelegators{ %StakingPoolsDelegator{
pool_address_hash: address_hash(), pool_address_hash: address_hash(),
delegator_address_hash: address_hash(), delegator_address_hash: address_hash(),
max_ordered_withdraw_allowed: wei_per_ether * 100, max_ordered_withdraw_allowed: wei_per_ether * 100,

Loading…
Cancel
Save