staking pools delegators importer test

pull/2036/head
saneery 6 years ago
parent 93bd9f0a00
commit 083f5e6f5d
  1. 2
      apps/explorer/lib/explorer/chain/staking_pool.ex
  2. 33
      apps/explorer/test/explorer/chain/import/runner/staking_pools_delegators_test.exs

@ -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, StakingPoolsDelegator)
has_many(:delegators, StakingPoolsDelegator, foreign_key: :pool_address_hash)
belongs_to(
:staking_address,

@ -0,0 +1,33 @@
defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegatorsTest do
use Explorer.DataCase
import Explorer.Factory
alias Ecto.Multi
alias Explorer.Chain.Import.Runner.StakingPoolsDelegators
alias Explorer.Chain.StakingPoolsDelegator
describe "run/1" do
test "insert new pools list" do
delegators =
[delegator1, delegator2] =
[params_for(:staking_pools_delegator), params_for(:staking_pools_delegator)]
|> Enum.map(fn param ->
changeset = StakingPoolsDelegator.changeset(%StakingPoolsDelegator{}, param)
changeset.changes
end)
assert {:ok, %{insert_staking_pools_delegators: list}} = run_changes(delegators)
assert Enum.count(list) == Enum.count(delegators)
end
end
defp run_changes(changes) do
Multi.new()
|> StakingPoolsDelegators.run(changes, %{
timeout: :infinity,
timestamps: %{inserted_at: DateTime.utc_now(), updated_at: DateTime.utc_now()}
})
|> Repo.transaction()
end
end
Loading…
Cancel
Save