|
|
@ -1,7 +1,8 @@ |
|
|
|
defmodule BlockScoutWeb.AddressTokenTransferControllerTest do |
|
|
|
defmodule BlockScoutWeb.AddressTokenTransferControllerTest do |
|
|
|
use BlockScoutWeb.ConnCase |
|
|
|
use BlockScoutWeb.ConnCase |
|
|
|
|
|
|
|
|
|
|
|
import BlockScoutWeb.Router.Helpers, only: [address_token_transfers_path: 4] |
|
|
|
import BlockScoutWeb.Router.Helpers, |
|
|
|
|
|
|
|
only: [address_token_transfers_path: 4, address_token_transfers_path: 5] |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.Chain.{Address, Token} |
|
|
|
alias Explorer.Chain.{Address, Token} |
|
|
|
|
|
|
|
|
|
|
@ -15,6 +16,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do |
|
|
|
|
|
|
|
|
|
|
|
test "with invalid token hash", %{conn: conn} do |
|
|
|
test "with invalid token hash", %{conn: conn} do |
|
|
|
address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b" |
|
|
|
address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b" |
|
|
|
|
|
|
|
|
|
|
|
conn = get(conn, address_token_transfers_path(conn, :index, address_hash, "invalid_address")) |
|
|
|
conn = get(conn, address_token_transfers_path(conn, :index, address_hash, "invalid_address")) |
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 422) |
|
|
|
assert html_response(conn, 422) |
|
|
@ -35,25 +37,80 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do |
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 404) |
|
|
|
assert html_response(conn, 404) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "GET index/2 JSON" do |
|
|
|
test "without token transfers for a token", %{conn: conn} do |
|
|
|
test "without token transfers for a token", %{conn: conn} do |
|
|
|
%Address{hash: address_hash} = insert(:address) |
|
|
|
%Address{hash: address_hash} = insert(:address) |
|
|
|
%Token{contract_address_hash: token_hash} = insert(:token) |
|
|
|
%Token{contract_address_hash: token_hash} = insert(:token) |
|
|
|
|
|
|
|
|
|
|
|
conn = get(conn, address_token_transfers_path(conn, :index, address_hash, token_hash)) |
|
|
|
conn = |
|
|
|
|
|
|
|
get(conn, address_token_transfers_path(conn, :index, address_hash, token_hash), %{ |
|
|
|
|
|
|
|
type: "JSON" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{"items" => [], "next_page_path" => nil} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "returns the correct number of transactions", %{conn: conn} do |
|
|
|
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
token = insert(:token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inserted_transactions = |
|
|
|
|
|
|
|
Enum.map(1..5, fn index -> |
|
|
|
|
|
|
|
block = insert(:block, number: 1000 - index) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert() |
|
|
|
|
|
|
|
|> with_block(block) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insert( |
|
|
|
|
|
|
|
:token_transfer, |
|
|
|
|
|
|
|
to_address: address, |
|
|
|
|
|
|
|
transaction: transaction, |
|
|
|
|
|
|
|
token_contract_address: token.contract_address |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transaction |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 200) |
|
|
|
conn = |
|
|
|
assert conn.assigns.transactions == [] |
|
|
|
get( |
|
|
|
|
|
|
|
conn, |
|
|
|
|
|
|
|
address_token_transfers_path(conn, :index, address.hash, token.contract_address_hash), |
|
|
|
|
|
|
|
%{type: "JSON"} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response_items = |
|
|
|
|
|
|
|
conn |
|
|
|
|
|
|
|
|> json_response(200) |
|
|
|
|
|
|
|
|> Map.get("items") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
items_length = length(response_items) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert items_length == 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert Enum.all?(inserted_transactions, fn transaction -> |
|
|
|
|
|
|
|
Enum.any?(response_items, fn item -> |
|
|
|
|
|
|
|
String.contains?( |
|
|
|
|
|
|
|
item, |
|
|
|
|
|
|
|
"data-transaction-hash=\"#{to_string(transaction.hash)}\"" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
end) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "returns the transactions that have token transfers for the given address and token", %{conn: conn} do |
|
|
|
test "returns next_page_path as null when there are no more pages", %{conn: conn} do |
|
|
|
address = insert(:address) |
|
|
|
address = insert(:address) |
|
|
|
token = insert(:token) |
|
|
|
token = insert(:token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block = insert(:block, number: 1000) |
|
|
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
transaction = |
|
|
|
:transaction |
|
|
|
:transaction |
|
|
|
|> insert() |
|
|
|
|> insert() |
|
|
|
|> with_block() |
|
|
|
|> with_block(block) |
|
|
|
|
|
|
|
|
|
|
|
insert( |
|
|
|
insert( |
|
|
|
:token_transfer, |
|
|
|
:token_transfer, |
|
|
@ -62,19 +119,21 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do |
|
|
|
token_contract_address: token.contract_address |
|
|
|
token_contract_address: token.contract_address |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
conn = get(conn, address_token_transfers_path(conn, :index, address.hash, token.contract_address_hash)) |
|
|
|
conn = |
|
|
|
|
|
|
|
get( |
|
|
|
transaction_hashes = Enum.map(conn.assigns.transactions, & &1.hash) |
|
|
|
conn, |
|
|
|
|
|
|
|
address_token_transfers_path(conn, :index, address.hash, token.contract_address_hash), |
|
|
|
|
|
|
|
%{type: "JSON"} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 200) |
|
|
|
assert Map.get(json_response(conn, 200), "next_page_path") == nil |
|
|
|
assert transaction_hashes == [transaction.hash] |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "returns next page of results based on last seen transactions", %{conn: conn} do |
|
|
|
test "returns next_page_path when there are more items", %{conn: conn} do |
|
|
|
address = insert(:address) |
|
|
|
address = insert(:address) |
|
|
|
token = insert(:token) |
|
|
|
token = insert(:token) |
|
|
|
|
|
|
|
|
|
|
|
second_page_transactions = |
|
|
|
page_last_transfer = |
|
|
|
1..50 |
|
|
|
1..50 |
|
|
|
|> Enum.map(fn index -> |
|
|
|
|> Enum.map(fn index -> |
|
|
|
block = insert(:block, number: 1000 - index) |
|
|
|
block = insert(:block, number: 1000 - index) |
|
|
@ -93,22 +152,84 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do |
|
|
|
|
|
|
|
|
|
|
|
transaction |
|
|
|
transaction |
|
|
|
end) |
|
|
|
end) |
|
|
|
|> Enum.map(& &1.hash) |
|
|
|
|> List.last() |
|
|
|
|
|
|
|
|
|
|
|
transaction = |
|
|
|
Enum.each(51..60, fn index -> |
|
|
|
:transaction |
|
|
|
block = insert(:block, number: 1000 - index) |
|
|
|
|> insert() |
|
|
|
|
|
|
|
|> with_block(insert(:block, number: 1002)) |
|
|
|
transaction = |
|
|
|
|
|
|
|
:transaction |
|
|
|
|
|
|
|
|> insert() |
|
|
|
|
|
|
|
|> with_block(block) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insert( |
|
|
|
|
|
|
|
:token_transfer, |
|
|
|
|
|
|
|
to_address: address, |
|
|
|
|
|
|
|
transaction: transaction, |
|
|
|
|
|
|
|
token_contract_address: token.contract_address |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
conn = |
|
|
|
conn = |
|
|
|
get(conn, address_token_transfers_path(conn, :index, address.hash, token.contract_address_hash), %{ |
|
|
|
get( |
|
|
|
"block_number" => Integer.to_string(transaction.block_number), |
|
|
|
conn, |
|
|
|
"index" => Integer.to_string(transaction.index) |
|
|
|
address_token_transfers_path(conn, :index, address.hash, token.contract_address_hash), |
|
|
|
|
|
|
|
%{type: "JSON"} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expected_path = |
|
|
|
|
|
|
|
address_token_transfers_path(conn, :index, address.hash, token.contract_address_hash, %{ |
|
|
|
|
|
|
|
block_number: page_last_transfer.block_number, |
|
|
|
|
|
|
|
index: page_last_transfer.index |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
actual_transactions = Enum.map(conn.assigns.transactions, & &1.hash) |
|
|
|
assert Map.get(json_response(conn, 200), "next_page_path") == expected_path |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "with invalid address hash", %{conn: conn} do |
|
|
|
|
|
|
|
token_hash = "0xc8982771dd50285389c352c175ada74d074427c7" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn = |
|
|
|
|
|
|
|
get(conn, address_token_transfers_path(conn, :index, "invalid_address", token_hash), %{ |
|
|
|
|
|
|
|
type: "JSON" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 422) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "with invalid token hash", %{conn: conn} do |
|
|
|
|
|
|
|
address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn = |
|
|
|
|
|
|
|
get(conn, address_token_transfers_path(conn, :index, address_hash, "invalid_address"), %{ |
|
|
|
|
|
|
|
type: "JSON" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 422) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "with an address that doesn't exist in our database", %{conn: conn} do |
|
|
|
|
|
|
|
address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b" |
|
|
|
|
|
|
|
%Token{contract_address_hash: token_hash} = insert(:token) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn = |
|
|
|
|
|
|
|
get(conn, address_token_transfers_path(conn, :index, address_hash, token_hash), %{ |
|
|
|
|
|
|
|
type: "JSON" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 404) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "with a token that doesn't exist in our database", %{conn: conn} do |
|
|
|
|
|
|
|
%Address{hash: address_hash} = insert(:address) |
|
|
|
|
|
|
|
token_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b" |
|
|
|
|
|
|
|
|
|
|
|
assert second_page_transactions == actual_transactions |
|
|
|
conn = |
|
|
|
|
|
|
|
get(conn, address_token_transfers_path(conn, :index, address_hash, token_hash), %{ |
|
|
|
|
|
|
|
type: "JSON" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert html_response(conn, 404) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|