Merge pull request #6013 from blockscout/fix-erc1155-tokens-fetching
Fix ERC-1155 tokens fetchingpull/6045/head
commit
0b1ca31545
@ -0,0 +1,44 @@ |
||||
defmodule BlockScoutWeb.Tokens.Instance.TransferControllerTest do |
||||
use BlockScoutWeb.ConnCase, async: false |
||||
|
||||
describe "GET token-transfers/2" do |
||||
test "works for ERC-721 tokens", %{conn: conn} do |
||||
contract_address = insert(:address) |
||||
|
||||
insert(:token, contract_address: contract_address) |
||||
|
||||
token_id = 10 |
||||
|
||||
%{log_index: log_index} = |
||||
insert(:token_transfer, |
||||
from_address: contract_address, |
||||
token_contract_address: contract_address, |
||||
token_id: token_id |
||||
) |
||||
|
||||
conn = get(conn, "/token/#{contract_address.hash}/instance/#{token_id}/token-transfers") |
||||
|
||||
assert %{assigns: %{token_instance: %{log_index: ^log_index}}} = conn |
||||
end |
||||
|
||||
test "works for ERC-1155 tokens", %{conn: conn} do |
||||
contract_address = insert(:address) |
||||
|
||||
insert(:token, contract_address: contract_address) |
||||
|
||||
token_id = 10 |
||||
|
||||
%{log_index: log_index} = |
||||
insert(:token_transfer, |
||||
from_address: contract_address, |
||||
token_contract_address: contract_address, |
||||
token_id: nil, |
||||
token_ids: [token_id] |
||||
) |
||||
|
||||
conn = get(conn, "/token/#{contract_address.hash}/instance/#{token_id}/token-transfers") |
||||
|
||||
assert %{assigns: %{token_instance: %{log_index: ^log_index}}} = conn |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,13 @@ |
||||
defmodule Explorer.Repo.Migrations.CreateIndexTokenTransfersTokenIds do |
||||
use Ecto.Migration |
||||
|
||||
def up do |
||||
execute(""" |
||||
CREATE INDEX token_transfers_token_ids_index on token_transfers USING GIN ("token_ids") |
||||
""") |
||||
end |
||||
|
||||
def down do |
||||
execute("DROP INDEX token_transfers_token_ids_index") |
||||
end |
||||
end |
@ -0,0 +1,8 @@ |
||||
defmodule Explorer.Repo.Migrations.CreateIndexesTokenInstancesTokenContractAddressHashTokenId do |
||||
use Ecto.Migration |
||||
|
||||
def change do |
||||
create_if_not_exists(index(:token_instances, [:token_contract_address_hash, :token_id])) |
||||
create_if_not_exists(index(:token_instances, [:token_id])) |
||||
end |
||||
end |
Loading…
Reference in new issue