Fix queries.

Update chain queries and created tests for mentioned queries.
pull/738/head
Lokraan 6 years ago
parent 92f99cac22
commit d4aedd08f4
  1. 3
      apps/explorer/lib/explorer/chain.ex
  2. 76
      apps/explorer/test/explorer/chain_test.exs

@ -826,6 +826,7 @@ defmodule Explorer.Chain do
end
@doc """
<<<<<<< HEAD
Lists the top 250 `t:Explorer.Chain.Address.t/0`'s' in descending order based on coin balance.
"""
@ -839,6 +840,8 @@ defmodule Explorer.Chain do
end
@doc """
=======
>>>>>>> Fix queries.
Finds all Blocks validated by the address given.
## Options

@ -1033,6 +1033,82 @@ defmodule Explorer.ChainTest do
end
end
describe "get_blocks_validated_by_address/2" do
test "without blocks" do
address = insert(:address)
assert [] = Chain.get_blocks_validated_by_address([], address)
end
test "with blocks" do
address = insert(:address)
address2 = insert(:address)
%Block{hash: hash, miner_hash: miner_hash} =
insert(:block, miner: address, miner_hash: adress.hash)
%Block{hash: hash, miner_hash: miner_hash} =
insert(:block, miner: address2, miner_hash: adress2.hash)
assert [%Block{hash: ^hash, miner: ^address, miner_hash: ^address.hash}] ==
Chain.get_blocks_validated_by_address([], address)
assert [%Block{hash: ^hash, miner: ^address, miner_hash: ^address.hash}] ==
Chain.get_blocks_validated_by_address([], address2)
end
test "with blocks can be paginated" do
address = insert(:address)
address2 = insert(:address)
second_page_hashes =
50
|> insert_list(:block, miner: address, miner_hash: adress.hash)
|> Enum.map(& &1.hash)
second_page_hashes2 =
50
|> insert_list(:block, miner: address2, miner_hash: adress.hash2)
|> Enum.map(& &1.hash)
assert second_page_hashes ==
[paging_options: %PagingOptions{key: {inserted_at, hash}, page_size: 50}]
|> Chain.get_blocks_validated_by_address([], address)
|> Enum.map(& &1.hash)
|> Enum.reverse()
assert second_page_hashes2 ==
[paging_options: %PagingOptions{key: {inserted_at, hash}, page_size: 50}]
|> Chain.get_blocks_validated_by_address([], address2)
|> Enum.map(& &1.hash)
|> Enum.reverse()
end
end
describe "address_to_validation_count/1" do
test "without blocks" do
address = insert(:address)
assert 0 = Chain.address_to_validation_count(address)
end
test "with blocks" do
address = insert(:address)
address2 = insert(:address)
%Block{hash: hash, miner_hash: miner_hash} =
insert(:block, miner: address, miner_hash: adress.hash)
%Block{hash: hash, miner_hash: miner_hash} =
insert(:block, miner: address2, miner_hash: adress2.hash)
%Block{hash: hash, miner_hash: miner_hash} =
insert(:block, miner: address2, miner_hash: adress2.hash)
assert 1 = Chain.address_to_validation_count(address)
assert 2 = Chain.address_to_validation_count(address)
end
end
describe "number_to_block/1" do
test "without block" do
assert {:error, :not_found} = Chain.number_to_block(-1)

Loading…
Cancel
Save