diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex index 5d44d68a92..22d62592c3 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex @@ -1,12 +1,12 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do @moduledoc """ - Bulk imports staking pools to StakingPoolsDelegators tabe. + Bulk imports staking pools to StakingPoolsDelegator tabe. """ require Ecto.Query alias Ecto.{Changeset, Multi, Repo} - alias Explorer.Chain.{Import, StakingPoolsDelegators} + alias Explorer.Chain.{Import, StakingPoolsDelegator} import Ecto.Query, only: [from: 2] @@ -15,10 +15,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do # milliseconds @timeout 60_000 - @type imported :: [StakingPoolsDelegators.t()] + @type imported :: [StakingPoolsDelegator.t()] @impl Import.Runner - def ecto_schema_module, do: StakingPoolsDelegators + def ecto_schema_module, do: StakingPoolsDelegator @impl Import.Runner def option_key, do: :staking_pools_delegators @@ -54,7 +54,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do required(:timeout) => timeout, required(:timestamps) => Import.timestamps() }) :: - {:ok, [StakingPoolsDelegators.t()]} + {:ok, [StakingPoolsDelegator.t()]} | {:error, [Changeset.t()]} 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) @@ -65,7 +65,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do changes_list, conflict_target: [:pool_address_hash, :delegator_address_hash], on_conflict: on_conflict, - for: StakingPoolsDelegators, + for: StakingPoolsDelegator, returning: [:pool_address_hash, :delegator_address_hash], timeout: timeout, timestamps: timestamps @@ -74,7 +74,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do defp default_on_conflict do from( - name in StakingPoolsDelegators, + name in StakingPoolsDelegator, update: [ set: [ stake_amount: fragment("EXCLUDED.stake_amount"), diff --git a/apps/explorer/lib/explorer/chain/staking_pool.ex b/apps/explorer/lib/explorer/chain/staking_pool.ex index 31c5b1cc26..bb5635702d 100644 --- a/apps/explorer/lib/explorer/chain/staking_pool.ex +++ b/apps/explorer/lib/explorer/chain/staking_pool.ex @@ -9,7 +9,7 @@ defmodule Explorer.Chain.StakingPool do alias Explorer.Chain.{ Address, Hash, - StakingPoolsDelegators, + StakingPoolsDelegator, Wei } @@ -54,7 +54,7 @@ defmodule Explorer.Chain.StakingPool do field(:was_banned_count, :integer) field(:was_validator_count, :integer) field(:is_deleted, :boolean, default: false) - has_many(:delegators, StakingPoolsDelegators) + has_many(:delegators, StakingPoolsDelegator) belongs_to( :staking_address, diff --git a/apps/explorer/lib/explorer/chain/staking_pools_delegators.ex b/apps/explorer/lib/explorer/chain/staking_pools_delegator.ex similarity index 92% rename from apps/explorer/lib/explorer/chain/staking_pools_delegators.ex rename to apps/explorer/lib/explorer/chain/staking_pools_delegator.ex index d40edfaad8..8fabc6c447 100644 --- a/apps/explorer/lib/explorer/chain/staking_pools_delegators.ex +++ b/apps/explorer/lib/explorer/chain/staking_pools_delegator.ex @@ -1,4 +1,4 @@ -defmodule Explorer.Chain.StakingPoolsDelegators do +defmodule Explorer.Chain.StakingPoolsDelegator do @moduledoc """ The representation of delegators from POSDAO network. Delegators make stakes on staking pools and withdraw from them. @@ -55,8 +55,8 @@ defmodule Explorer.Chain.StakingPoolsDelegators do end @doc false - def changeset(staking_pools_delegators, attrs) do - staking_pools_delegators + def changeset(staking_pools_delegator, attrs) do + staking_pools_delegator |> cast(attrs, @attrs) |> validate_required(@attrs) |> unique_constraint(:pool_address_hash, name: :pools_delegator_index) diff --git a/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs b/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs index 1f243771fb..ccf9c8c372 100644 --- a/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs +++ b/apps/explorer/priv/repo/migrations/20190523112839_create_staking_pools_delegators.exs @@ -1,4 +1,4 @@ -defmodule Explorer.Repo.Migrations.CreateStakingPoolsDelegators do +defmodule Explorer.Repo.Migrations.CreateStakingPoolsDelegator do use Ecto.Migration def change do diff --git a/apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs b/apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs new file mode 100644 index 0000000000..222658e92e --- /dev/null +++ b/apps/explorer/test/explorer/chain/staking_pools_delegator_test.exs @@ -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 diff --git a/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs b/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs deleted file mode 100644 index a27dada2eb..0000000000 --- a/apps/explorer/test/explorer/chain/staking_pools_delegators_test.exs +++ /dev/null @@ -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 diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 58a16c97b9..9d0a2e9997 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -28,7 +28,7 @@ defmodule Explorer.Factory do TokenTransfer, Transaction, StakingPool, - StakingPoolsDelegators + StakingPoolsDelegator } alias Explorer.Market.MarketHistory @@ -630,10 +630,10 @@ defmodule Explorer.Factory do } end - def staking_pools_delegators_factory do + def staking_pools_delegator_factory do wei_per_ether = 1_000_000_000_000_000_000 - %StakingPoolsDelegators{ + %StakingPoolsDelegator{ pool_address_hash: address_hash(), delegator_address_hash: address_hash(), max_ordered_withdraw_allowed: wei_per_ether * 100,