From 18a8a61842643bebceea034cbb2b2dcdf4482629 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 13 Jun 2019 14:27:29 +0300 Subject: [PATCH] add test for average block number without uncles --- .../counters/average_block_time_test.exs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/explorer/test/explorer/counters/average_block_time_test.exs b/apps/explorer/test/explorer/counters/average_block_time_test.exs index a89a899208..0f7c328bb3 100644 --- a/apps/explorer/test/explorer/counters/average_block_time_test.exs +++ b/apps/explorer/test/explorer/counters/average_block_time_test.exs @@ -42,5 +42,21 @@ defmodule Explorer.Counters.AverageBlockTimeTest do assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT3S") end + + test "when there are no uncles sorts by block number" do + block_number = 99_999_999 + + first_timestamp = Timex.now() + + insert(:block, number: block_number, consensus: true, timestamp: Timex.shift(first_timestamp, seconds: 3)) + insert(:block, number: block_number + 2, consensus: true, timestamp: Timex.shift(first_timestamp, seconds: 9)) + insert(:block, number: block_number + 1, consensus: true, timestamp: Timex.shift(first_timestamp, seconds: 6)) + + assert Repo.aggregate(Block, :count, :hash) == 3 + + AverageBlockTime.refresh() + + assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT3S") + end end end