@ -1419,6 +1419,332 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
end
end
end
end
describe " pendingtxlist " do
test " with missing address hash " , %{ conn : conn } do
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert response [ " message " ] =~ " 'address' is required "
assert response [ " status " ] == " 0 "
assert Map . has_key? ( response , " result " )
refute response [ " result " ]
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " with an invalid address hash " , %{ conn : conn } do
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " badhash "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert response [ " message " ] =~ " Invalid address format "
assert response [ " status " ] == " 0 "
assert Map . has_key? ( response , " result " )
refute response [ " result " ]
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " with an address that doesn't exist " , %{ conn : conn } do
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " 0x8bf38d4764929064f2d4d3a56520a76ab3df415b "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert response [ " result " ] == [ ]
assert response [ " status " ] == " 0 "
assert response [ " message " ] == " No transactions found "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " with a valid address " , %{ conn : conn } do
address = insert ( :address )
transaction =
:transaction
|> insert ( from_address : address )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address . hash } "
}
expected_result = [
%{
" hash " = > " #{ transaction . hash } " ,
" nonce " = > " #{ transaction . nonce } " ,
" from " = > " #{ transaction . from_address_hash } " ,
" to " = > " #{ transaction . to_address_hash } " ,
" value " = > " #{ transaction . value . value } " ,
" gas " = > " #{ transaction . gas } " ,
" gasPrice " = > " #{ transaction . gas_price . value } " ,
" input " = > " #{ transaction . input } " ,
" contractAddress " = > " #{ transaction . created_contract_address_hash } " ,
" cumulativeGasUsed " = > " #{ transaction . cumulative_gas_used } " ,
" gasUsed " = > " #{ transaction . gas_used } "
}
]
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert response [ " result " ] == expected_result
assert response [ " status " ] == " 1 "
assert response [ " message " ] == " OK "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " with address with multiple transactions " , %{ conn : conn } do
address1 = insert ( :address )
address2 = insert ( :address )
transactions =
3
|> insert_list ( :transaction , from_address : address1 )
:transaction
|> insert ( from_address : address2 )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address1 . hash } "
}
expected_transaction_hashes = Enum . map ( transactions , & " #{ &1 . hash } " )
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert length ( response [ " result " ] ) == 3
for returned_transaction <- response [ " result " ] do
assert returned_transaction [ " hash " ] in expected_transaction_hashes
end
assert response [ " status " ] == " 1 "
assert response [ " message " ] == " OK "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " with valid pagination params " , %{ conn : conn } do
address = insert ( :address )
_transactions_1 =
2
|> insert_list ( :transaction , from_address : address )
_transactions_2 =
2
|> insert_list ( :transaction , from_address : address )
transactions_3 =
2
|> insert_list ( :transaction , from_address : address )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address . hash } " ,
# page number
" page " = > " 1 " ,
# page size
" offset " = > " 2 "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
page1_hashes = Enum . map ( response [ " result " ] , & &1 [ " hash " ] )
assert length ( response [ " result " ] ) == 2
for transaction <- transactions_3 do
assert " #{ transaction . hash } " in page1_hashes
end
assert response [ " status " ] == " 1 "
assert response [ " message " ] == " OK "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " ignores pagination params when invalid " , %{ conn : conn } do
address = insert ( :address )
_transactions_1 =
2
|> insert_list ( :transaction , from_address : address )
_transactions_2 =
2
|> insert_list ( :transaction , from_address : address )
_transactions_3 =
2
|> insert_list ( :transaction , from_address : address )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address . hash } " ,
# page number
" page " = > " invalidpage " ,
# page size
" offset " = > " invalidoffset "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert length ( response [ " result " ] ) == 6
assert response [ " status " ] == " 1 "
assert response [ " message " ] == " OK "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " ignores offset param if offset is less than 1 " , %{ conn : conn } do
address = insert ( :address )
6
|> insert_list ( :transaction , from_address : address )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address . hash } " ,
# page number
" page " = > " 1 " ,
# page size
" offset " = > " 0 "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert length ( response [ " result " ] ) == 6
assert response [ " status " ] == " 1 "
assert response [ " message " ] == " OK "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " ignores offset param if offset is over 10,000 " , %{ conn : conn } do
address = insert ( :address )
6
|> insert_list ( :transaction , from_address : address )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address . hash } " ,
# page number
" page " = > " 1 " ,
# page size
" offset " = > " 10_500 "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert length ( response [ " result " ] ) == 6
assert response [ " status " ] == " 1 "
assert response [ " message " ] == " OK "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " with page number with no results " , %{ conn : conn } do
address = insert ( :address )
_transactions_1 =
2
|> insert_list ( :transaction , from_address : address )
_transactions_2 =
2
|> insert_list ( :transaction , from_address : address )
_transactions_3 =
2
|> insert_list ( :transaction , from_address : address )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address . hash } " ,
# page number
" page " = > " 5 " ,
# page size
" offset " = > " 2 "
}
assert response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert response [ " result " ] == [ ]
assert response [ " status " ] == " 0 "
assert response [ " message " ] == " No transactions found "
assert :ok = ExJsonSchema.Validator . validate ( txlist_schema ( ) , response )
end
test " supports GET and POST requests " , %{ conn : conn } do
address = insert ( :address )
:transaction
|> insert ( from_address : address )
params = %{
" module " = > " account " ,
" action " = > " pendingtxlist " ,
" address " = > " #{ address . hash } "
}
assert get_response =
conn
|> get ( " /api " , params )
|> json_response ( 200 )
assert post_response =
conn
|> post ( " /api " , params )
|> json_response ( 200 )
assert get_response == post_response
end
end
describe " txlistinternal " do
describe " txlistinternal " do
test " with missing txhash and address " , %{ conn : conn } do
test " with missing txhash and address " , %{ conn : conn } do
params = %{
params = %{