Merge branch 'master' into master

pull/2626/head
Ethan van Ballegooyen 5 years ago committed by GitHub
commit e230420035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 116
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc/rolling_window_test.exs
  3. 7
      apps/explorer/lib/explorer/chain.ex
  4. 26
      apps/explorer/test/explorer/chain_test.exs

@ -7,6 +7,8 @@
- [#2497](https://github.com/poanetwork/blockscout/pull/2497) - Add generic Ordered Cache behaviour and implementation
### Fixes
- [#2623](https://github.com/poanetwork/blockscout/pull/2623) - fix a blinking test
- [#2616](https://github.com/poanetwork/blockscout/pull/2616) - deduplicate coin history records by delta
- [#2613](https://github.com/poanetwork/blockscout/pull/2613) - fix getminedblocks rpc endpoint
- [#2592](https://github.com/poanetwork/blockscout/pull/2592) - process new metadata format for whisper
- [#2572](https://github.com/poanetwork/blockscout/pull/2572) - Ease non-critical css

@ -1,27 +1,8 @@
defmodule EthereumJSONRPC.RollingWindowTest do
use ExUnit.Case,
# The same named process is used for all tests and they use the same key in the table, so they would interfere
async: false
use ExUnit.Case, async: true
alias EthereumJSONRPC.RollingWindow
@table :table
setup do
# We set `window_length` to a large time frame so that we can sweep manually to simulate
# time passing
{:ok, pid} =
RollingWindow.start_link([table: @table, duration: :timer.minutes(120), window_count: 3], name: RollingWindow)
on_exit(fn -> Process.exit(pid, :normal) end)
:ok
end
defp sweep do
GenServer.call(RollingWindow, :sweep)
end
test "start_link/2" do
assert {:ok, _} = RollingWindow.start_link(table: :test_table, duration: 5, window_count: 1)
end
@ -29,7 +10,7 @@ defmodule EthereumJSONRPC.RollingWindowTest do
describe "init/1" do
test "raises when duration isn't evenly divisble by window_count" do
assert_raise ArgumentError, ~r"evenly divisible", fn ->
RollingWindow.init(table: @table, duration: :timer.seconds(2), window_count: 3)
RollingWindow.init(table: :init_test_table, duration: :timer.seconds(2), window_count: 3)
end
end
@ -40,61 +21,85 @@ defmodule EthereumJSONRPC.RollingWindowTest do
end
test "when no increments have happened, inspect returns an empty list" do
assert RollingWindow.inspect(@table, :foobar) == []
table = :no_increments_have_happened
start_rolling_window(table)
assert RollingWindow.inspect(table, :foobar) == []
end
test "when no increments have happened, count returns 0" do
assert RollingWindow.count(@table, :foobar) == 0
table = :no_increments_have_happened_empty_list
start_rolling_window(table)
assert RollingWindow.count(table, :foobar) == 0
end
test "when an increment has happened, inspect returns the count for that window" do
RollingWindow.inc(@table, :foobar)
table = :no_increments_have_happened_count
start_rolling_window(table)
assert RollingWindow.inspect(@table, :foobar) == [1]
RollingWindow.inc(table, :foobar)
assert RollingWindow.inspect(table, :foobar) == [1]
end
test "when an increment has happened, count returns the count for that window" do
RollingWindow.inc(@table, :foobar)
table = :no_increments_have_happened_count1
start_rolling_window(table)
RollingWindow.inc(table, :foobar)
assert RollingWindow.count(@table, :foobar) == 1
assert RollingWindow.count(table, :foobar) == 1
end
test "when an increment has happened in multiple windows, inspect returns the count for both windows" do
RollingWindow.inc(@table, :foobar)
sweep()
RollingWindow.inc(@table, :foobar)
table = :no_increments_have_happened_multiple_windows
start_rolling_window(table)
assert RollingWindow.inspect(@table, :foobar) == [1, 1]
RollingWindow.inc(table, :foobar)
sweep(table)
RollingWindow.inc(table, :foobar)
assert RollingWindow.inspect(table, :foobar) == [1, 1]
end
test "when an increment has happened in multiple windows, count returns the sum of both windows" do
RollingWindow.inc(@table, :foobar)
sweep()
RollingWindow.inc(@table, :foobar)
table = :no_increments_have_happened_multiple_windows1
start_rolling_window(table)
RollingWindow.inc(table, :foobar)
sweep(table)
RollingWindow.inc(table, :foobar)
assert RollingWindow.count(@table, :foobar) == 2
assert RollingWindow.count(table, :foobar) == 2
end
test "when an increment has happened, but has been swept <window_count> times, it no longer appears in inspect" do
RollingWindow.inc(@table, :foobar)
sweep()
sweep()
RollingWindow.inc(@table, :foobar)
sweep()
RollingWindow.inc(@table, :foobar)
assert RollingWindow.inspect(@table, :foobar) == [1, 1, 0]
table = :no_increments_have_happened_multiple_windows3
start_rolling_window(table)
RollingWindow.inc(table, :foobar)
sweep(table)
sweep(table)
RollingWindow.inc(table, :foobar)
sweep(table)
RollingWindow.inc(table, :foobar)
assert RollingWindow.inspect(table, :foobar) == [1, 1, 0]
end
test "when an increment has happened, but has been swept <window_count> times, it no longer is included in count" do
RollingWindow.inc(@table, :foobar)
sweep()
sweep()
RollingWindow.inc(@table, :foobar)
sweep()
RollingWindow.inc(@table, :foobar)
assert RollingWindow.count(@table, :foobar) == 2
table = :no_increments_have_happened_multiple_windows4
start_rolling_window(table)
RollingWindow.inc(table, :foobar)
sweep(table)
sweep(table)
RollingWindow.inc(table, :foobar)
sweep(table)
RollingWindow.inc(table, :foobar)
assert RollingWindow.count(table, :foobar) == 2
end
test "sweeping schedules another sweep" do
@ -102,4 +107,13 @@ defmodule EthereumJSONRPC.RollingWindowTest do
RollingWindow.handle_info(:sweep, state)
assert_receive(:sweep)
end
defp start_rolling_window(table_name) do
{:ok, _pid} =
RollingWindow.start_link([table: table_name, duration: :timer.minutes(120), window_count: 3], name: table_name)
end
defp sweep(name) do
GenServer.call(name, :sweep)
end
end

@ -2967,6 +2967,13 @@ defmodule Explorer.Chain do
|> CoinBalance.fetch_coin_balances(paging_options)
|> page_coin_balances(paging_options)
|> Repo.all()
|> Enum.dedup_by(fn record ->
if record.delta == Decimal.new(0) do
:dup
else
System.unique_integer()
end
end)
end
def get_coin_balance(address_hash, block_number) do

@ -4159,4 +4159,30 @@ defmodule Explorer.ChainTest do
assert Chain.staking_pools_count(:inactive) == 1
end
end
describe "address_to_coin_balances/2" do
test "deduplicates records by zero delta" do
address = insert(:address)
1..5
|> Enum.each(fn block_number ->
insert(:block, number: block_number)
insert(:fetched_balance, value: 1, block_number: block_number, address_hash: address.hash)
end)
insert(:block, number: 6)
insert(:fetched_balance, value: 2, block_number: 6, address_hash: address.hash)
assert [first, second, third] = Chain.address_to_coin_balances(address.hash, [])
assert first.block_number == 6
assert first.delta == Decimal.new(1)
assert second.block_number == 5
assert second.delta == Decimal.new(0)
assert third.block_number == 1
assert third.delta == Decimal.new(1)
end
end
end

Loading…
Cancel
Save