From 8aa55932f704c003f333cbf333a2c7eeb0d34f77 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 26 Nov 2019 16:42:17 +0300 Subject: [PATCH] fix tests --- .../api/rpc/address_controller_test.exs | 24 ++++- ...saction_token_transfer_controller_test.exs | 11 ++- .../explorer/test/explorer/etherscan_test.exs | 98 ++++++++++++++++--- 3 files changed, 112 insertions(+), 21 deletions(-) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs index ba9725bb1c..2215057a9a 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs @@ -1787,7 +1787,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do insert(:token_transfer, %{ token_contract_address: token_address, token_id: 666, - transaction: transaction + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number }) {:ok, _} = Chain.token_from_address_hash(token_transfer.token_contract_address_hash) @@ -1817,7 +1819,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> insert() |> with_block() - token_transfer = insert(:token_transfer, block: transaction.block, transaction: transaction) + token_transfer = + insert(:token_transfer, block: transaction.block, transaction: transaction, block_number: block.number) + {:ok, token} = Chain.token_from_address_hash(token_transfer.token_contract_address_hash) params = %{ @@ -1894,8 +1898,20 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do |> insert() |> with_block() - insert(:token_transfer, from_address: address, transaction: transaction) - insert(:token_transfer, from_address: address, token_contract_address: contract_address, transaction: transaction) + insert(:token_transfer, + from_address: address, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) + + insert(:token_transfer, + from_address: address, + token_contract_address: contract_address, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) params = %{ "module" => "account", diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs index 72da1bc63d..3c1fb0a8f4 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs @@ -48,9 +48,9 @@ defmodule BlockScoutWeb.TransactionTokenTransferControllerTest do test "includes token transfers for the transaction", %{conn: conn} do transaction = insert(:transaction) |> with_block() - insert(:token_transfer, transaction: transaction, block: transaction.block) + insert(:token_transfer, transaction: transaction, block: transaction.block, block_number: transaction.block_number) - insert(:token_transfer, transaction: transaction, block: transaction.block) + insert(:token_transfer, transaction: transaction, block: transaction.block, block_number: transaction.block_number) path = transaction_token_transfer_path(BlockScoutWeb.Endpoint, :index, transaction.hash) @@ -107,7 +107,8 @@ defmodule BlockScoutWeb.TransactionTokenTransferControllerTest do :token_transfer, transaction: transaction, log_index: log_index, - block: transaction.block + block: transaction.block, + block_number: transaction.block_number ) end) @@ -130,7 +131,9 @@ defmodule BlockScoutWeb.TransactionTokenTransferControllerTest do insert( :token_transfer, transaction: transaction, - log_index: log_index + log_index: log_index, + block_number: transaction.block_number, + block: transaction.block ) end) diff --git a/apps/explorer/test/explorer/etherscan_test.exs b/apps/explorer/test/explorer/etherscan_test.exs index 5d1cf7fcb1..5ba4b8dc8e 100644 --- a/apps/explorer/test/explorer/etherscan_test.exs +++ b/apps/explorer/test/explorer/etherscan_test.exs @@ -828,7 +828,12 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block() - token_transfer = insert(:token_transfer, transaction: transaction) + token_transfer = + insert(:token_transfer, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) [found_token_transfer] = Etherscan.list_token_transfers(token_transfer.from_address_hash, nil) @@ -863,9 +868,26 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block() - insert(:token_transfer, from_address: address1, transaction: transaction) - insert(:token_transfer, from_address: address1, transaction: transaction) - insert(:token_transfer, from_address: address2, transaction: transaction) + insert(:token_transfer, + from_address: address1, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) + + insert(:token_transfer, + from_address: address1, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) + + insert(:token_transfer, + from_address: address2, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) found_token_transfers = Etherscan.list_token_transfers(address1.hash, nil) @@ -884,7 +906,12 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block() - token_transfer = insert(:token_transfer, transaction: transaction) + token_transfer = + insert(:token_transfer, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) insert(:block) @@ -903,7 +930,12 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block() - token_transfer = insert(:token_transfer, transaction: transaction) + token_transfer = + insert(:token_transfer, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) {:ok, token} = Chain.token_from_address_hash(token_transfer.token_contract_address_hash) @@ -1019,11 +1051,29 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block(third_block) - second_block_token_transfers = insert_list(2, :token_transfer, from_address: address, transaction: transaction2) + second_block_token_transfers = + insert_list(2, :token_transfer, + from_address: address, + transaction: transaction2, + block: transaction2.block, + block_number: transaction2.block_number + ) - first_block_token_transfers = insert_list(2, :token_transfer, from_address: address, transaction: transaction3) + first_block_token_transfers = + insert_list(2, :token_transfer, + from_address: address, + transaction: transaction3, + block: transaction3.block, + block_number: transaction3.block_number + ) - third_block_token_transfers = insert_list(2, :token_transfer, from_address: address, transaction: transaction1) + third_block_token_transfers = + insert_list(2, :token_transfer, + from_address: address, + transaction: transaction1, + block: transaction1.block, + block_number: transaction1.block_number + ) options1 = %{page_number: 1, page_size: 2} @@ -1076,7 +1126,12 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block(block) - insert(:token_transfer, from_address: address, transaction: transaction) + insert(:token_transfer, + from_address: address, + transaction: transaction, + block: block, + block_number: block.number + ) end options = %{ @@ -1105,7 +1160,12 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block(block) - insert(:token_transfer, from_address: address, transaction: transaction) + insert(:token_transfer, + from_address: address, + transaction: transaction, + block: block, + block_number: block.number + ) end options = %{start_block: third_block.number} @@ -1131,7 +1191,12 @@ defmodule Explorer.EtherscanTest do |> insert() |> with_block(block) - insert(:token_transfer, from_address: address, transaction: transaction) + insert(:token_transfer, + from_address: address, + transaction: transaction, + block: block, + block_number: block.number + ) end options = %{end_block: second_block.number} @@ -1160,7 +1225,14 @@ defmodule Explorer.EtherscanTest do |> with_block() insert(:token_transfer, from_address: address, transaction: transaction) - insert(:token_transfer, from_address: address, token_contract_address: contract_address, transaction: transaction) + + insert(:token_transfer, + from_address: address, + token_contract_address: contract_address, + transaction: transaction, + block: transaction.block, + block_number: transaction.block_number + ) [found_token_transfer] = Etherscan.list_token_transfers(address.hash, contract_address.hash)