fix: Fix failed tests (#11000)

production-scroll
nikitosing 1 month ago committed by GitHub
parent eafe7c8b3b
commit fc0c5b5315
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 268
      apps/explorer/test/explorer/migrator/sanitize_duplicated_log_index_logs_test.exs

@ -7,138 +7,142 @@ defmodule Explorer.Migrator.SanitizeDuplicatedLogIndexLogsTest do
alias Explorer.Chain.Token.Instance alias Explorer.Chain.Token.Instance
alias Explorer.Migrator.{SanitizeDuplicatedLogIndexLogs, MigrationStatus} alias Explorer.Migrator.{SanitizeDuplicatedLogIndexLogs, MigrationStatus}
describe "Sanitize duplicated log index logs" do if Application.compile_env(:explorer, :chain_type) != :celo do
test "correctly identifies and updates duplicated log index logs" do describe "Sanitize duplicated log index logs" do
block = insert(:block) test "correctly identifies and updates duplicated log index logs" do
block = insert(:block)
tx1 = :transaction |> insert() |> with_block(block, index: 0)
tx2 = :transaction |> insert() |> with_block(block, index: 1) tx1 = :transaction |> insert() |> with_block(block, index: 0)
tx2 = :transaction |> insert() |> with_block(block, index: 1)
_log1 = insert(:log, transaction: tx1, index: 3, data: "0x01", block: block, block_number: block.number)
_log2 = insert(:log, transaction: tx1, index: 0, data: "0x02", block: block, block_number: block.number) _log1 = insert(:log, transaction: tx1, index: 3, data: "0x01", block: block, block_number: block.number)
_log3 = insert(:log, transaction: tx2, index: 3, data: "0x03", block: block, block_number: block.number) _log2 = insert(:log, transaction: tx1, index: 0, data: "0x02", block: block, block_number: block.number)
_log3 = insert(:log, transaction: tx2, index: 3, data: "0x03", block: block, block_number: block.number)
log4 = insert(:log)
log4 = insert(:log)
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == nil
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == nil
SanitizeDuplicatedLogIndexLogs.start_link([])
Process.sleep(300) SanitizeDuplicatedLogIndexLogs.start_link([])
Process.sleep(300)
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == "completed"
assert BackgroundMigrations.get_sanitize_duplicated_log_index_logs_finished() == true assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == "completed"
assert BackgroundMigrations.get_sanitize_duplicated_log_index_logs_finished() == true
updated_logs = Repo.all(Log |> where([log], log.block_number == ^block.number) |> order_by([log], asc: log.index))
updated_logs =
assert match?( Repo.all(Log |> where([log], log.block_number == ^block.number) |> order_by([log], asc: log.index))
[
%{index: 0, data: %Explorer.Chain.Data{bytes: <<2>>}}, assert match?(
%{index: 1, data: %Explorer.Chain.Data{bytes: <<1>>}}, [
%{index: 2, data: %Explorer.Chain.Data{bytes: <<3>>}} %{index: 0, data: %Explorer.Chain.Data{bytes: <<2>>}},
], %{index: 1, data: %Explorer.Chain.Data{bytes: <<1>>}},
updated_logs %{index: 2, data: %Explorer.Chain.Data{bytes: <<3>>}}
) ],
updated_logs
assert %Log{log4 | address: nil, block: nil, transaction: nil} == %Log{ )
Repo.one(Log |> where([log], log.block_number != ^block.number))
| address: nil, assert %Log{log4 | address: nil, block: nil, transaction: nil} == %Log{
block: nil, Repo.one(Log |> where([log], log.block_number != ^block.number))
transaction: nil | address: nil,
} block: nil,
end transaction: nil
}
test "correctly identifies and updates duplicated log index logs & updates corresponding token transfers and token instances" do end
block = insert(:block)
token_address = insert(:contract_address) test "correctly identifies and updates duplicated log index logs & updates corresponding token transfers and token instances" do
insert(:token, contract_address: token_address, type: "ERC-721") block = insert(:block)
token_address = insert(:contract_address)
instance = insert(:token_instance, token_contract_address_hash: token_address.hash) insert(:token, contract_address: token_address, type: "ERC-721")
tx1 = :transaction |> insert() |> with_block(block, index: 0) instance = insert(:token_instance, token_contract_address_hash: token_address.hash)
tx2 = :transaction |> insert() |> with_block(block, index: 1)
tx1 = :transaction |> insert() |> with_block(block, index: 0)
log1 = insert(:log, transaction: tx1, index: 3, data: "0x01", block: block, block_number: block.number) tx2 = :transaction |> insert() |> with_block(block, index: 1)
log2 = insert(:log, transaction: tx1, index: 0, data: "0x02", block: block, block_number: block.number)
log3 = insert(:log, transaction: tx2, index: 3, data: "0x03", block: block, block_number: block.number) log1 = insert(:log, transaction: tx1, index: 3, data: "0x01", block: block, block_number: block.number)
log2 = insert(:log, transaction: tx1, index: 0, data: "0x02", block: block, block_number: block.number)
log4 = insert(:log) log3 = insert(:log, transaction: tx2, index: 3, data: "0x03", block: block, block_number: block.number)
_tt1 = log4 = insert(:log)
insert(:token_transfer,
token_type: "ERC-721", _tt1 =
block: block, insert(:token_transfer,
block_number: block.number, token_type: "ERC-721",
log_index: log1.index, block: block,
token_ids: [instance.token_id], block_number: block.number,
token_contract_address: token_address, log_index: log1.index,
token_contract_address_hash: token_address.hash, token_ids: [instance.token_id],
transaction: tx1, token_contract_address: token_address,
transaction_hash: tx1.hash, token_contract_address_hash: token_address.hash,
block_hash: block.hash transaction: tx1,
) transaction_hash: tx1.hash,
block_hash: block.hash
_tt2 = )
insert(:token_transfer,
block: block, _tt2 =
block_number: block.number, insert(:token_transfer,
log_index: log2.index, block: block,
transaction: tx1, block_number: block.number,
transaction_hash: tx1.hash log_index: log2.index,
) transaction: tx1,
transaction_hash: tx1.hash
_tt3 = )
insert(:token_transfer,
block: block, _tt3 =
block_number: block.number, insert(:token_transfer,
log_index: log3.index, block: block,
transaction: tx2, block_number: block.number,
transaction_hash: tx2.hash log_index: log3.index,
) transaction: tx2,
transaction_hash: tx2.hash
Instance.changeset(instance, %{owner_updated_at_block: block.number, owner_updated_at_log_index: log1.index}) )
|> Repo.update!()
Instance.changeset(instance, %{owner_updated_at_block: block.number, owner_updated_at_log_index: log1.index})
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == nil |> Repo.update!()
SanitizeDuplicatedLogIndexLogs.start_link([]) assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == nil
Process.sleep(300)
SanitizeDuplicatedLogIndexLogs.start_link([])
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == "completed" Process.sleep(300)
assert BackgroundMigrations.get_sanitize_duplicated_log_index_logs_finished() == true
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == "completed"
updated_logs = Repo.all(Log |> where([log], log.block_number == ^block.number) |> order_by([log], asc: log.index)) assert BackgroundMigrations.get_sanitize_duplicated_log_index_logs_finished() == true
assert match?( updated_logs =
[ Repo.all(Log |> where([log], log.block_number == ^block.number) |> order_by([log], asc: log.index))
%{index: 0, data: %Explorer.Chain.Data{bytes: <<2>>}},
%{index: 1, data: %Explorer.Chain.Data{bytes: <<1>>}}, assert match?(
%{index: 2, data: %Explorer.Chain.Data{bytes: <<3>>}} [
], %{index: 0, data: %Explorer.Chain.Data{bytes: <<2>>}},
updated_logs %{index: 1, data: %Explorer.Chain.Data{bytes: <<1>>}},
) %{index: 2, data: %Explorer.Chain.Data{bytes: <<3>>}}
],
block_number = block.number updated_logs
assert [%{owner_updated_at_block: ^block_number, owner_updated_at_log_index: 1}] = Repo.all(Instance) )
assert [%{log_index: 1, block_number: ^block_number}] = block_number = block.number
Repo.all(TokenTransfer |> where([tt], tt.token_type == "ERC-721")) assert [%{owner_updated_at_block: ^block_number, owner_updated_at_log_index: 1}] = Repo.all(Instance)
assert %Log{log4 | address: nil, block: nil, transaction: nil} == %Log{ assert [%{log_index: 1, block_number: ^block_number}] =
Repo.one(Log |> where([log], log.block_number != ^block.number)) Repo.all(TokenTransfer |> where([tt], tt.token_type == "ERC-721"))
| address: nil,
block: nil, assert %Log{log4 | address: nil, block: nil, transaction: nil} == %Log{
transaction: nil Repo.one(Log |> where([log], log.block_number != ^block.number))
} | address: nil,
end block: nil,
transaction: nil
test "correctly handles cases where there are no duplicated log index logs" do }
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == nil end
SanitizeDuplicatedLogIndexLogs.start_link([]) test "correctly handles cases where there are no duplicated log index logs" do
Process.sleep(100) assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == nil
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == "completed" SanitizeDuplicatedLogIndexLogs.start_link([])
assert BackgroundMigrations.get_sanitize_duplicated_log_index_logs_finished() == true Process.sleep(100)
assert MigrationStatus.get_status("sanitize_duplicated_log_index_logs") == "completed"
assert BackgroundMigrations.get_sanitize_duplicated_log_index_logs_finished() == true
end
end end
end end
end end

Loading…
Cancel
Save