Fix read contract bug (#9300)

* Fix read contract bug

* Changelog
pull/9305/head
nikitosing 9 months ago committed by GitHub
parent 9534acaf22
commit 10520bc026
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 82
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs
  3. 4
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex

@ -10,6 +10,7 @@
- [#9317](https://github.com/blockscout/blockscout/pull/9317) - Include null gas price txs in fee calculations
- [#9315](https://github.com/blockscout/blockscout/pull/9315) - Fix manual uncle reward calculation
- [#9300](https://github.com/blockscout/blockscout/pull/9300) - Fix read contract bug
### Chore

@ -2084,6 +2084,88 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
"result" => %{"names" => ["bool"], "output" => [%{"type" => "bool", "value" => true}]}
} == response
end
test "query read method 1", %{conn: conn} do
abi = [
%{
"inputs" => [
%{
"internalType" => "uint256",
"name" => "amountIn",
"type" => "uint256"
},
%{
"internalType" => "address[]",
"name" => "path",
"type" => "address[]"
}
],
"name" => "getAmountsOut",
"outputs" => [
%{
"internalType" => "uint256[]",
"name" => "amounts",
"type" => "uint256[]"
}
],
"stateMutability" => "view",
"type" => "function"
}
]
expect(
EthereumJSONRPC.Mox,
:json_rpc,
fn [
%{
id: id,
method: "eth_call",
params: [
%{
data:
"0xd06ca61f00000000000000000000000000000000000000000000003635c9adc5dea0000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000909fd75ce23a7e61787fe2763652935f921164610000000000000000000000009801eeb848987c0a8d6443912827bd36c288f8fb"
},
_
]
}
],
_opts ->
{:ok,
[
%{
id: id,
jsonrpc: "2.0",
result:
"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000003635c9adc5dea000000000000000000000000000000000000000000000000000000037240fc3496a65"
}
]}
end
)
target_contract = insert(:smart_contract, abi: abi)
request =
post(conn, "/api/v2/smart-contracts/#{target_contract.address_hash}/query-read-method", %{
"contract_type" => "regular",
"args" => [
"1000000000000000000000",
["0x909Fd75Ce23a7e61787FE2763652935F92116461", "0x9801eeb848987c0a8d6443912827bd36c288f8fb"]
],
"method_id" => "d06ca61f"
})
assert response = json_response(request, 200)
assert %{
"is_error" => false,
"result" => %{
"names" => ["amounts"],
"output" => [
%{"type" => "uint256[]", "value" => [1_000_000_000_000_000_000_000, 15_520_773_838_563_941]}
]
}
} == response
end
end
describe "/smart-contracts/{address_hash}/methods-read-proxy" do

@ -25,6 +25,10 @@ defmodule EthereumJSONRPC.Encoder do
def encode_function_call(function_selector, args), do: encode_function_call(function_selector, [args])
defp parse_args(args, {:array, type}) when is_list(args) do
Enum.map(args, fn arg -> parse_args(arg, type) end)
end
defp parse_args(args, types) when is_list(args) do
args
|> Enum.zip(types)

Loading…
Cancel
Save