Merge pull request #4801 from blockscout/np-fix-stake-dapp-bug

Added clauses and tests for `get_total_staked_and_ordered/1`
pull/4815/head
Victor Baranov 3 years ago committed by GitHub
commit 88ec3e3777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 6
      apps/explorer/lib/explorer/chain.ex
  3. 12
      apps/explorer/test/explorer/chain_test.exs

@ -25,6 +25,7 @@
### Fixes ### Fixes
- [#4812](https://github.com/blockscout/blockscout/pull/4812) - Check if exists custom_cap property of extended token object before access it - [#4812](https://github.com/blockscout/blockscout/pull/4812) - Check if exists custom_cap property of extended token object before access it
- [#4810](https://github.com/blockscout/blockscout/pull/4810) - Show `nil` block.size as `N/A bytes` - [#4810](https://github.com/blockscout/blockscout/pull/4810) - Show `nil` block.size as `N/A bytes`
- [#4801](https://github.com/blockscout/blockscout/pull/4801) - Added clauses and tests for get_total_staked_and_ordered/1
- [#4798](https://github.com/blockscout/blockscout/pull/4798) - Token instance View contract icon Safari fix - [#4798](https://github.com/blockscout/blockscout/pull/4798) - Token instance View contract icon Safari fix
- [#4796](https://github.com/blockscout/blockscout/pull/4796) - Fix nil.timestamp issue - [#4796](https://github.com/blockscout/blockscout/pull/4796) - Fix nil.timestamp issue
- [#4764](https://github.com/blockscout/blockscout/pull/4764) - Add cleaning of substrings of `require` messages from parsed constructor arguments - [#4764](https://github.com/blockscout/blockscout/pull/4764) - Add cleaning of substrings of `require` messages from parsed constructor arguments

@ -6319,7 +6319,9 @@ defmodule Explorer.Chain do
) )
end end
def get_total_staked_and_ordered(address_hash) do def get_total_staked_and_ordered(""), do: nil
def get_total_staked_and_ordered(address_hash) when is_binary(address_hash) do
StakingPoolsDelegator StakingPoolsDelegator
|> where([delegator], delegator.address_hash == ^address_hash and not delegator.is_deleted) |> where([delegator], delegator.address_hash == ^address_hash and not delegator.is_deleted)
|> select([delegator], %{ |> select([delegator], %{
@ -6329,6 +6331,8 @@ defmodule Explorer.Chain do
|> Repo.one() |> Repo.one()
end end
def get_total_staked_and_ordered(_), do: nil
defp with_decompiled_code_flag(query, _hash, false), do: query defp with_decompiled_code_flag(query, _hash, false), do: query
defp with_decompiled_code_flag(query, hash, true) do defp with_decompiled_code_flag(query, hash, true) do

@ -5745,5 +5745,17 @@ defmodule Explorer.ChainTest do
assert implementation_abi == @implementation_abi assert implementation_abi == @implementation_abi
end end
test "get_total_staked_and_ordered should return just nil in case of invalid input and some response otherwise" do
assert Chain.get_total_staked_and_ordered(nil) == nil
assert Chain.get_total_staked_and_ordered(%{}) == nil
assert Chain.get_total_staked_and_ordered("") == nil
assert Chain.get_total_staked_and_ordered([]) == nil
assert Chain.get_total_staked_and_ordered("0x3f7c51ef174ee8a62e3fcfb0947aa90c97bd2784") == %{
stake_amount: Decimal.new(0),
ordered_withdraw: Decimal.new(0)
}
end
end end
end end

Loading…
Cancel
Save