From 9f0acb82ca446909df937a84d90a6157e292546b Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 4 Jun 2019 10:07:06 +0300 Subject: [PATCH] use reverse order --- apps/explorer/lib/explorer/chain/blocks_cache.ex | 1 + apps/explorer/test/explorer/chain/blocks_cache_test.exs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/blocks_cache.ex b/apps/explorer/lib/explorer/chain/blocks_cache.ex index 45152dc262..24fab7f8b7 100644 --- a/apps/explorer/lib/explorer/chain/blocks_cache.ex +++ b/apps/explorer/lib/explorer/chain/blocks_cache.ex @@ -60,6 +60,7 @@ defmodule Explorer.Chain.BlocksCache do numbers |> Enum.sort() + |> Enum.reverse() |> Enum.map(fn number -> ConCache.get(@cache_name, number) end) diff --git a/apps/explorer/test/explorer/chain/blocks_cache_test.exs b/apps/explorer/test/explorer/chain/blocks_cache_test.exs index 5a15a07f37..135aded458 100644 --- a/apps/explorer/test/explorer/chain/blocks_cache_test.exs +++ b/apps/explorer/test/explorer/chain/blocks_cache_test.exs @@ -33,10 +33,11 @@ defmodule Explorer.Chain.BlocksCacheTest do new_block = insert(:block, number: 70) BlocksCache.update(new_block) - new_blocks = blocks |> List.replace_at(0, new_block.number) |> Enum.sort() + new_blocks = blocks |> List.replace_at(0, new_block.number) |> Enum.sort() |> Enum.reverse() assert Enum.map(BlocksCache.blocks(), & &1.number) == new_blocks end + test "adds missing element" do block1 = insert(:block, number: 10) block2 = insert(:block, number: 4) @@ -67,7 +68,7 @@ defmodule Explorer.Chain.BlocksCacheTest do BlocksCache.rewrite_cache(new_blocks) - assert BlocksCache.blocks() == [block1, block2] + assert BlocksCache.blocks() == [block2, block1] end end end