|
|
@ -3522,24 +3522,27 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
|
|
describe "stream_cataloged_token_contract_address_hashes/2" do |
|
|
|
describe "stream_cataloged_token_contract_address_hashes/2" do |
|
|
|
test "reduces with given reducer and accumulator" do |
|
|
|
test "reduces with given reducer and accumulator" do |
|
|
|
%Token{contract_address_hash: catalog_address} = insert(:token, cataloged: true) |
|
|
|
today = DateTime.utc_now() |
|
|
|
|
|
|
|
yesterday = Timex.shift(today, days: -1) |
|
|
|
|
|
|
|
%Token{contract_address_hash: catalog_address} = insert(:token, cataloged: true, updated_at: yesterday) |
|
|
|
insert(:token, cataloged: false) |
|
|
|
insert(:token, cataloged: false) |
|
|
|
assert Chain.stream_cataloged_token_contract_address_hashes([], &[&1 | &2]) == {:ok, [catalog_address]} |
|
|
|
assert Chain.stream_cataloged_token_contract_address_hashes([], &[&1 | &2], 1) == {:ok, [catalog_address]} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "sorts the tokens by updated_at in ascending order" do |
|
|
|
test "sorts the tokens by updated_at in ascending order" do |
|
|
|
today = DateTime.utc_now() |
|
|
|
today = DateTime.utc_now() |
|
|
|
yesterday = Timex.shift(today, days: -1) |
|
|
|
yesterday = Timex.shift(today, days: -1) |
|
|
|
|
|
|
|
two_days_ago = Timex.shift(today, days: -2) |
|
|
|
|
|
|
|
|
|
|
|
token1 = insert(:token, %{cataloged: true, updated_at: today}) |
|
|
|
token1 = insert(:token, %{cataloged: true, updated_at: yesterday}) |
|
|
|
token2 = insert(:token, %{cataloged: true, updated_at: yesterday}) |
|
|
|
token2 = insert(:token, %{cataloged: true, updated_at: two_days_ago}) |
|
|
|
|
|
|
|
|
|
|
|
expected_response = |
|
|
|
expected_response = |
|
|
|
[token1, token2] |
|
|
|
[token1, token2] |
|
|
|
|> Enum.sort(&(Timex.to_unix(&1.updated_at) < Timex.to_unix(&2.updated_at))) |
|
|
|
|> Enum.sort(&(Timex.to_unix(&1.updated_at) < Timex.to_unix(&2.updated_at))) |
|
|
|
|> Enum.map(& &1.contract_address_hash) |
|
|
|
|> Enum.map(& &1.contract_address_hash) |
|
|
|
|
|
|
|
|
|
|
|
assert Chain.stream_cataloged_token_contract_address_hashes([], &(&2 ++ [&1])) == {:ok, expected_response} |
|
|
|
assert Chain.stream_cataloged_token_contract_address_hashes([], &(&2 ++ [&1]), 12) == {:ok, expected_response} |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|