|
|
|
@ -7,6 +7,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
Address, |
|
|
|
|
Address.CoinBalance, |
|
|
|
|
Block, |
|
|
|
|
Data, |
|
|
|
|
InternalTransaction, |
|
|
|
|
Log, |
|
|
|
|
Token, |
|
|
|
@ -36,7 +37,6 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
correct_reponse = %{ |
|
|
|
|
"hash" => Address.checksum(address.hash), |
|
|
|
|
"implementation_name" => nil, |
|
|
|
|
"is_contract" => false, |
|
|
|
|
"is_verified" => false, |
|
|
|
|
"name" => nil, |
|
|
|
@ -340,7 +340,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "/addresses/{address_hash}/token-transfers" do |
|
|
|
|
test "get empty list on non existing address", %{conn: conn} do |
|
|
|
|
test "get 404 on non existing address", %{conn: conn} do |
|
|
|
|
address = build(:address) |
|
|
|
|
|
|
|
|
|
request = get(conn, "/api/v2/addresses/#{address.hash}/token-transfers") |
|
|
|
@ -354,10 +354,69 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
assert %{"message" => "Invalid parameter(s)"} = json_response(request, 422) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "get 404 on non existing address of token", %{conn: conn} do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
token = build(:address) |
|
|
|
|
|
|
|
|
|
request = get(conn, "/api/v2/addresses/#{address.hash}/token-transfers", %{"token" => to_string(token.hash)}) |
|
|
|
|
|
|
|
|
|
assert %{"message" => "Not found"} = json_response(request, 404) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "get 422 on invalid token address hash", %{conn: conn} do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
request = get(conn, "/api/v2/addresses/#{address.hash}/token-transfers", %{"token" => "0x"}) |
|
|
|
|
|
|
|
|
|
assert %{"message" => "Invalid parameter(s)"} = json_response(request, 422) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "get relevant token transfer", %{conn: conn} do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number) |
|
|
|
|
|
|
|
|
|
token_transfer = |
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
|
|
|
|
|
request = get(conn, "/api/v2/addresses/#{address.hash}/token-transfers") |
|
|
|
|
|
|
|
|
|
assert response = json_response(request, 200) |
|
|
|
|
assert Enum.count(response["items"]) == 1 |
|
|
|
|
assert response["next_page_params"] == nil |
|
|
|
|
compare_item(token_transfer, Enum.at(response["items"], 0)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "method in token transer could be decoded", %{conn: conn} do |
|
|
|
|
insert(:contract_method, |
|
|
|
|
identifier: Base.decode16!("731133e9", case: :lower), |
|
|
|
|
abi: %{ |
|
|
|
|
"constant" => false, |
|
|
|
|
"inputs" => [ |
|
|
|
|
%{"name" => "account", "type" => "address"}, |
|
|
|
|
%{"name" => "id", "type" => "uint256"}, |
|
|
|
|
%{"name" => "amount", "type" => "uint256"}, |
|
|
|
|
%{"name" => "data", "type" => "bytes"} |
|
|
|
|
], |
|
|
|
|
"name" => "mint", |
|
|
|
|
"outputs" => [], |
|
|
|
|
"payable" => false, |
|
|
|
|
"stateMutability" => "nonpayable", |
|
|
|
|
"type" => "function" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
tx = |
|
|
|
|
insert(:transaction, |
|
|
|
|
input: |
|
|
|
|
"0x731133e9000000000000000000000000bb36c792b9b45aaf8b848a1392b0d6559202729e000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000" |
|
|
|
|
) |
|
|
|
|
|> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number) |
|
|
|
|
|
|
|
|
@ -370,12 +429,76 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
assert Enum.count(response["items"]) == 1 |
|
|
|
|
assert response["next_page_params"] == nil |
|
|
|
|
compare_item(token_transfer, Enum.at(response["items"], 0)) |
|
|
|
|
assert Enum.at(response["items"], 0)["method"] == "mint" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "get relevant token transfer filtered by token", %{conn: conn} do |
|
|
|
|
token = insert(:token) |
|
|
|
|
|
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number) |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
|
|
|
|
|
token_transfer = |
|
|
|
|
insert(:token_transfer, |
|
|
|
|
transaction: tx, |
|
|
|
|
block: tx.block, |
|
|
|
|
block_number: tx.block_number, |
|
|
|
|
from_address: address, |
|
|
|
|
token_contract_address: token.contract_address |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
request = |
|
|
|
|
get(conn, "/api/v2/addresses/#{address.hash}/token-transfers", %{ |
|
|
|
|
"token" => to_string(token.contract_address) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
assert response = json_response(request, 200) |
|
|
|
|
assert Enum.count(response["items"]) == 1 |
|
|
|
|
assert response["next_page_params"] == nil |
|
|
|
|
compare_item(token_transfer, Enum.at(response["items"], 0)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "token transfers by token can paginate", %{conn: conn} do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
token = insert(:token) |
|
|
|
|
|
|
|
|
|
token_tranfers = |
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, |
|
|
|
|
transaction: tx, |
|
|
|
|
block: tx.block, |
|
|
|
|
block_number: tx.block_number, |
|
|
|
|
from_address: address, |
|
|
|
|
token_contract_address: token.contract_address |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
params = %{"token" => to_string(token.contract_address)} |
|
|
|
|
request = get(conn, "/api/v2/addresses/#{address.hash}/token-transfers", params) |
|
|
|
|
assert response = json_response(request, 200) |
|
|
|
|
|
|
|
|
|
request_2nd_page = |
|
|
|
|
get(conn, "/api/v2/addresses/#{address.hash}/token-transfers", Map.merge(params, response["next_page_params"])) |
|
|
|
|
|
|
|
|
|
assert response_2nd_page = json_response(request_2nd_page, 200) |
|
|
|
|
|
|
|
|
|
check_paginated_response(response, response_2nd_page, token_tranfers) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "get only :to token transfer", %{conn: conn} do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
|
|
|
|
@ -393,7 +516,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
test "get only :from token transfer", %{conn: conn} do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
token_transfer = |
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
@ -412,7 +535,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
token_tranfers = |
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
end |
|
|
|
@ -430,13 +553,13 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
address = insert(:address) |
|
|
|
|
|
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
token_tranfers = |
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, to_address: address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -457,13 +580,13 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
token_tranfers = |
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, to_address: address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -484,14 +607,14 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
tt_from = |
|
|
|
|
for _ <- 0..49 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, from_address: address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
tt_to = |
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
insert(:token_transfer, transaction: tx, block: tx.block, block_number: tx.block_number, to_address: address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -525,7 +648,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
erc_20_tt = |
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, |
|
|
|
|
transaction: tx, |
|
|
|
@ -540,7 +663,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
erc_721_tt = |
|
|
|
|
for x <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, |
|
|
|
|
transaction: tx, |
|
|
|
@ -556,7 +679,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
erc_1155_tt = |
|
|
|
|
for x <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, |
|
|
|
|
transaction: tx, |
|
|
|
@ -650,7 +773,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
erc_20_tt = |
|
|
|
|
for _ <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, |
|
|
|
|
transaction: tx, |
|
|
|
@ -665,7 +788,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
|
|
|
|
|
erc_721_tt = |
|
|
|
|
for x <- 0..50 do |
|
|
|
|
tx = insert(:transaction) |> with_block() |
|
|
|
|
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block() |
|
|
|
|
|
|
|
|
|
insert(:token_transfer, |
|
|
|
|
transaction: tx, |
|
|
|
@ -1235,6 +1358,9 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
assert response_2nd_page = json_response(request_2nd_page, 200) |
|
|
|
|
|
|
|
|
|
check_paginated_response(response, response_2nd_page, addresses) |
|
|
|
|
|
|
|
|
|
assert Enum.at(response["items"], 0)["coin_balance"] == |
|
|
|
|
to_string(Enum.at(addresses, 50).fetched_coin_balance.value) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "check nil", %{conn: conn} do |
|
|
|
@ -1265,6 +1391,10 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
assert Address.checksum(token_transfer.from_address_hash) == json["from"]["hash"] |
|
|
|
|
assert Address.checksum(token_transfer.to_address_hash) == json["to"]["hash"] |
|
|
|
|
assert to_string(token_transfer.transaction_hash) == json["tx_hash"] |
|
|
|
|
assert json["timestamp"] != nil |
|
|
|
|
assert json["method"] != nil |
|
|
|
|
assert to_string(token_transfer.block_hash) == json["block_hash"] |
|
|
|
|
assert to_string(token_transfer.log_index) == json["log_index"] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp compare_item(%InternalTransaction{} = internal_tx, json) do |
|
|
|
@ -1309,6 +1439,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do |
|
|
|
|
assert log.index == json["index"] |
|
|
|
|
assert to_string(log.data) == json["data"] |
|
|
|
|
assert Address.checksum(log.address_hash) == json["address"]["hash"] |
|
|
|
|
assert to_string(log.transaction_hash) == json["tx_hash"] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp check_paginated_response(first_page_resp, second_page_resp, list) do |
|
|
|
|