Fix using of startblock/endblock in API v1 list endpoints: txlist, txlistinternal, tokentx (#9364)

* Fix using of startblock/endblock in API v1 list endpoints: txlist, txlistinternal, tokentx

* Add CHANGELOG entry
pull/9360/head
Victor Baranov 9 months ago committed by GitHub
parent 61df0a9b07
commit cef2819e10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 4
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/address_controller.ex
  3. 12
      apps/block_scout_web/lib/block_scout_web/etherscan.ex
  4. 40
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs
  5. 28
      apps/explorer/lib/explorer/etherscan.ex
  6. 28
      apps/explorer/test/explorer/etherscan_test.exs

@ -5,6 +5,7 @@
### Features
- [#9379](https://github.com/blockscout/blockscout/pull/9379) - Filter non-traceable transactions for zetachain
- [#9364](https://github.com/blockscout/blockscout/pull/9364) - Fix using of startblock/endblock in API v1 list endpoints: txlist, txlistinternal, tokentx
- [#9351](https://github.com/blockscout/blockscout/pull/9351) - Noves.fi: add proxy endpoint for describeTxs endpoint
- [#9282](https://github.com/blockscout/blockscout/pull/9282) - Add `license_type` to smart contracts
- [#9202](https://github.com/blockscout/blockscout/pull/9202) - Add base and priority fee to gas oracle response

@ -281,8 +281,8 @@ defmodule BlockScoutWeb.API.RPC.AddressController do
%{}
|> put_order_by_direction(params)
|> Helper.put_pagination_options(params)
|> put_block(params, "start_block")
|> put_block(params, "end_block")
|> put_block(params, "startblock")
|> put_block(params, "endblock")
|> put_filter_by(params)
|> put_timestamp(params, "start_timestamp")
|> put_timestamp(params, "end_timestamp")

@ -1420,12 +1420,12 @@ defmodule BlockScoutWeb.Etherscan do
"A string representing the order by block number direction. Defaults to descending order. Available values: asc, desc"
},
%{
key: "start_block",
key: "startblock",
type: "integer",
description: "A nonnegative integer that represents the starting block number."
},
%{
key: "end_block",
key: "endblock",
type: "integer",
description: "A nonnegative integer that represents the ending block number."
},
@ -1513,13 +1513,13 @@ defmodule BlockScoutWeb.Etherscan do
"A string representing the order by block number direction. Defaults to ascending order. Available values: asc, desc. WARNING: Only available if 'address' is provided."
},
%{
key: "start_block",
key: "startblock",
type: "integer",
description:
"A nonnegative integer that represents the starting block number. WARNING: Only available if 'address' is provided."
},
%{
key: "end_block",
key: "endblock",
type: "integer",
description:
"A nonnegative integer that represents the ending block number. WARNING: Only available if 'address' is provided."
@ -1588,12 +1588,12 @@ defmodule BlockScoutWeb.Etherscan do
"A string representing the order by block number direction. Defaults to ascending order. Available values: asc, desc"
},
%{
key: "start_block",
key: "startblock",
type: "integer",
description: "A nonnegative integer that represents the starting block number."
},
%{
key: "end_block",
key: "endblock",
type: "integer",
description: "A nonnegative integer that represents the ending block number."
},

@ -1090,7 +1090,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response)
end
test "with start_block and end_block params", %{conn: conn} do
test "with startblock and endblock params", %{conn: conn} do
blocks = [_, second_block, third_block, _] = insert_list(4, :block)
address = insert(:address)
@ -1104,8 +1104,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"module" => "account",
"action" => "txlist",
"address" => "#{address.hash}",
"start_block" => "#{second_block.number}",
"end_block" => "#{third_block.number}"
"startblock" => "#{second_block.number}",
"endblock" => "#{third_block.number}"
}
expected_block_numbers = [
@ -1129,7 +1129,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response)
end
test "with start_block but without end_block", %{conn: conn} do
test "with startblock but without endblock", %{conn: conn} do
blocks = [_, _, third_block, fourth_block] = insert_list(4, :block)
address = insert(:address)
@ -1143,7 +1143,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"module" => "account",
"action" => "txlist",
"address" => "#{address.hash}",
"start_block" => "#{third_block.number}"
"startblock" => "#{third_block.number}"
}
expected_block_numbers = [
@ -1167,7 +1167,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response)
end
test "with end_block but without start_block", %{conn: conn} do
test "with endblock but without startblock", %{conn: conn} do
blocks = [first_block, second_block, _, _] = insert_list(4, :block)
address = insert(:address)
@ -1181,7 +1181,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"module" => "account",
"action" => "txlist",
"address" => "#{address.hash}",
"end_block" => "#{second_block.number}"
"endblock" => "#{second_block.number}"
}
expected_block_numbers = [
@ -1205,7 +1205,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
assert :ok = ExJsonSchema.Validator.validate(txlist_schema(), response)
end
test "ignores invalid start_block and end_block", %{conn: conn} do
test "ignores invalid startblock and endblock", %{conn: conn} do
blocks = [_, _, _, _] = insert_list(4, :block)
address = insert(:address)
@ -1219,8 +1219,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"module" => "account",
"action" => "txlist",
"address" => "#{address.hash}",
"start_block" => "invalidstart",
"end_block" => "invalidend"
"startblock" => "invalidstart",
"endblock" => "invalidend"
}
assert response =
@ -3108,8 +3108,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
describe "optional_params/1" do
test "includes valid optional params in the required format" do
params = %{
"start_block" => "100",
"end_block" => "120",
"startblock" => "100",
"endblock" => "120",
"sort" => "asc",
# page number
"page" => "1",
@ -3128,8 +3128,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
assert optional_params.page_number == 1
assert optional_params.page_size == 2
assert optional_params.order_by_direction == :asc
assert optional_params.start_block == 100
assert optional_params.end_block == 120
assert optional_params.startblock == 100
assert optional_params.endblock == 120
assert optional_params.filter_by == "to"
assert optional_params.start_timestamp == expected_timestamp
assert optional_params.end_timestamp == expected_timestamp
@ -3177,8 +3177,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
test "ignores invalid optional params, keeps valid ones" do
params1 = %{
"start_block" => "invalid",
"end_block" => "invalid",
"startblock" => "invalid",
"endblock" => "invalid",
"sort" => "invalid",
"page" => "invalid",
"offset" => "invalid",
@ -3189,8 +3189,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
assert AddressController.optional_params(params1) == %{}
params2 = %{
"start_block" => "4",
"end_block" => "10",
"startblock" => "4",
"endblock" => "10",
"sort" => "invalid",
"page" => "invalid",
"offset" => "invalid",
@ -3200,8 +3200,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
optional_params = AddressController.optional_params(params2)
assert optional_params.start_block == 4
assert optional_params.end_block == 10
assert optional_params.startblock == 4
assert optional_params.endblock == 10
end
test "ignores 'page' if less than 1" do

@ -18,8 +18,8 @@ defmodule Explorer.Etherscan do
order_by_direction: :desc,
page_number: 1,
page_size: 10_000,
start_block: nil,
end_block: nil,
startblock: nil,
endblock: nil,
start_timestamp: nil,
end_timestamp: nil
}
@ -640,21 +640,21 @@ defmodule Explorer.Etherscan do
|> Repo.replica().all()
end
defp where_start_block_match(query, %{start_block: nil}), do: query
defp where_start_block_match(query, %{startblock: nil}), do: query
defp where_start_block_match(query, %{start_block: start_block}) do
defp where_start_block_match(query, %{startblock: start_block}) do
where(query, [..., block], block.number >= ^start_block)
end
defp where_end_block_match(query, %{end_block: nil}), do: query
defp where_end_block_match(query, %{endblock: nil}), do: query
defp where_end_block_match(query, %{end_block: end_block}) do
defp where_end_block_match(query, %{endblock: end_block}) do
where(query, [..., block], block.number <= ^end_block)
end
defp where_start_transaction_block_match(query, %{start_block: nil}), do: query
defp where_start_transaction_block_match(query, %{startblock: nil}), do: query
defp where_start_transaction_block_match(query, %{start_block: start_block} = params) do
defp where_start_transaction_block_match(query, %{startblock: start_block} = params) do
if DenormalizationHelper.denormalization_finished?() do
where(query, [transaction], transaction.block_number >= ^start_block)
else
@ -662,9 +662,9 @@ defmodule Explorer.Etherscan do
end
end
defp where_end_transaction_block_match(query, %{end_block: nil}), do: query
defp where_end_transaction_block_match(query, %{endblock: nil}), do: query
defp where_end_transaction_block_match(query, %{end_block: end_block} = params) do
defp where_end_transaction_block_match(query, %{endblock: end_block} = params) do
if DenormalizationHelper.denormalization_finished?() do
where(query, [transaction], transaction.block_number <= ^end_block)
else
@ -672,15 +672,15 @@ defmodule Explorer.Etherscan do
end
end
defp where_start_block_match_tt(query, %{start_block: nil}), do: query
defp where_start_block_match_tt(query, %{startblock: nil}), do: query
defp where_start_block_match_tt(query, %{start_block: start_block}) do
defp where_start_block_match_tt(query, %{startblock: start_block}) do
where(query, [tt], tt.block_number >= ^start_block)
end
defp where_end_block_match_tt(query, %{end_block: nil}), do: query
defp where_end_block_match_tt(query, %{endblock: nil}), do: query
defp where_end_block_match_tt(query, %{end_block: end_block}) do
defp where_end_block_match_tt(query, %{endblock: end_block}) do
where(query, [tt], tt.block_number <= ^end_block)
end

@ -294,8 +294,8 @@ defmodule Explorer.EtherscanTest do
end
options = %{
start_block: second_block.number,
end_block: third_block.number
startblock: second_block.number,
endblock: third_block.number
}
found_transactions = Etherscan.list_transactions(address.hash, options)
@ -309,7 +309,7 @@ defmodule Explorer.EtherscanTest do
end
end
test "with start_block but no end_block option" do
test "with startblock but no endblock option" do
blocks = [_, _, third_block, fourth_block] = insert_list(4, :block)
address = insert(:address)
@ -320,7 +320,7 @@ defmodule Explorer.EtherscanTest do
end
options = %{
start_block: third_block.number
startblock: third_block.number
}
found_transactions = Etherscan.list_transactions(address.hash, options)
@ -334,7 +334,7 @@ defmodule Explorer.EtherscanTest do
end
end
test "with end_block but no start_block option" do
test "with endblock but no startblock option" do
blocks = [first_block, second_block, _, _] = insert_list(4, :block)
address = insert(:address)
@ -345,7 +345,7 @@ defmodule Explorer.EtherscanTest do
end
options = %{
end_block: second_block.number
endblock: second_block.number
}
found_transactions = Etherscan.list_transactions(address.hash, options)
@ -973,8 +973,8 @@ defmodule Explorer.EtherscanTest do
end
options = %{
start_block: second_block.number,
end_block: third_block.number
startblock: second_block.number,
endblock: third_block.number
}
found_internal_transactions = Etherscan.list_internal_transactions(address.hash, options)
@ -1365,8 +1365,8 @@ defmodule Explorer.EtherscanTest do
end
options = %{
start_block: second_block.number,
end_block: third_block.number
startblock: second_block.number,
endblock: third_block.number
}
found_token_transfers = Etherscan.list_token_transfers(address.hash, nil, options)
@ -1380,7 +1380,7 @@ defmodule Explorer.EtherscanTest do
end
end
test "with start_block but no end_block option" do
test "with startblock but no endblock option" do
blocks = [_, _, third_block, fourth_block] = insert_list(4, :block)
address = insert(:address)
@ -1398,7 +1398,7 @@ defmodule Explorer.EtherscanTest do
)
end
options = %{start_block: third_block.number}
options = %{startblock: third_block.number}
found_token_transfers = Etherscan.list_token_transfers(address.hash, nil, options)
@ -1411,7 +1411,7 @@ defmodule Explorer.EtherscanTest do
end
end
test "with end_block but no start_block option" do
test "with endblock but no startblock option" do
blocks = [first_block, second_block, _, _] = insert_list(4, :block)
address = insert(:address)
@ -1429,7 +1429,7 @@ defmodule Explorer.EtherscanTest do
)
end
options = %{end_block: second_block.number}
options = %{endblock: second_block.number}
found_token_transfers = Etherscan.list_token_transfers(address.hash, nil, options)

Loading…
Cancel
Save