ERC-1155 metadata fetching: add tests

pull/8050/head
Viktor Baranov 4 years ago
parent 50a2612b2e
commit 866baeaa78
  1. 4
      apps/explorer/lib/explorer/token/instance_metadata_retriever.ex
  2. 96
      apps/explorer/test/explorer/token/instance_metadata_retriever_test.exs

@ -75,10 +75,10 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
|> fetch_json()
if res == {:ok, %{error: @vm_execution_error}} do
contract_functions_2 = %{@uri => [token_id]}
contract_functions_uri = %{@uri => [token_id]}
contract_address_hash
|> query_contract(contract_functions_2, @abi_uri)
|> query_contract(contract_functions_uri, @abi_uri)
|> fetch_json()
else
res

@ -9,6 +9,49 @@ defmodule Explorer.Token.InstanceMetadataRetrieverTest do
setup :verify_on_exit!
setup :set_mox_global
@abi [
%{
"type" => "function",
"stateMutability" => "view",
"payable" => false,
"outputs" => [
%{"type" => "string", "name" => ""}
],
"name" => "tokenURI",
"inputs" => [
%{
"type" => "uint256",
"name" => "_tokenId"
}
],
"constant" => true
}
]
@abi_uri [
%{
"type" => "function",
"stateMutability" => "view",
"payable" => false,
"outputs" => [
%{
"type" => "string",
"name" => "",
"internalType" => "string"
}
],
"name" => "uri",
"inputs" => [
%{
"type" => "uint256",
"name" => "_id",
"internalType" => "uint256"
}
],
"constant" => true
}
]
describe "fetch_metadata/2" do
@tag :no_parity
@tag :no_geth
@ -46,9 +89,56 @@ defmodule Explorer.Token.InstanceMetadataRetrieverTest do
assert %{
"c87b56dd" => {:ok, ["https://vault.warriders.com/18290729947667102496.json"]}
} ==
InstanceMetadataRetriever.query_contract("0x5caebd3b32e210e85ce3e9d51638b9c445481567", %{
"c87b56dd" => [18_290_729_947_667_102_496]
})
InstanceMetadataRetriever.query_contract(
"0x5caebd3b32e210e85ce3e9d51638b9c445481567",
%{
"c87b56dd" => [18_290_729_947_667_102_496]
},
@abi
)
end
test "fetches json metadata for ERC-1155 token", %{json_rpc_named_arguments: json_rpc_named_arguments} do
if json_rpc_named_arguments[:transport] == EthereumJSONRPC.Mox do
EthereumJSONRPC.Mox
|> expect(:json_rpc, fn [
%{
id: 0,
jsonrpc: "2.0",
method: "eth_call",
params: [
%{
data:
"0x0e89341c000000000000000000000000000000000000000000000000fdd5b9fa9d4bfb20",
to: "0x5caebd3b32e210e85ce3e9d51638b9c445481567"
},
"latest"
]
}
],
_options ->
{:ok,
[
%{
id: 0,
jsonrpc: "2.0",
result:
"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003568747470733a2f2f7661756c742e7761727269646572732e636f6d2f31383239303732393934373636373130323439362e6a736f6e0000000000000000000000"
}
]}
end)
end
assert %{
"0e89341c" => {:ok, ["https://vault.warriders.com/18290729947667102496.json"]}
} ==
InstanceMetadataRetriever.query_contract(
"0x5caebd3b32e210e85ce3e9d51638b9c445481567",
%{
"0e89341c" => [18_290_729_947_667_102_496]
},
@abi_uri
)
end
end

Loading…
Cancel
Save