|
|
@ -3,7 +3,9 @@ defmodule Explorer.Counters.AverageBlockTimeTest do |
|
|
|
|
|
|
|
|
|
|
|
doctest Explorer.Counters.AverageBlockTimeDurationFormat |
|
|
|
doctest Explorer.Counters.AverageBlockTimeDurationFormat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.Chain.Block |
|
|
|
alias Explorer.Counters.AverageBlockTime |
|
|
|
alias Explorer.Counters.AverageBlockTime |
|
|
|
|
|
|
|
alias Explorer.Repo |
|
|
|
|
|
|
|
|
|
|
|
setup do |
|
|
|
setup do |
|
|
|
start_supervised!(AverageBlockTime) |
|
|
|
start_supervised!(AverageBlockTime) |
|
|
@ -24,5 +26,37 @@ defmodule Explorer.Counters.AverageBlockTimeTest do |
|
|
|
test "without blocks duration is 0" do |
|
|
|
test "without blocks duration is 0" do |
|
|
|
assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT0S") |
|
|
|
assert AverageBlockTime.average_block_time() == Timex.Duration.parse!("PT0S") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "considers both uncles and consensus blocks" 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, consensus: false, timestamp: Timex.shift(first_timestamp, seconds: 9)) |
|
|
|
|
|
|
|
insert(:block, number: block_number, consensus: false, 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
end |
|
|
|
end |
|
|
|