Update tests

pull/1030/head
jimmay5469 6 years ago
parent 0a80f12985
commit a55c602836
  1. 379
      apps/block_scout_web/assets/__tests__/pages/address.js
  2. 5
      apps/block_scout_web/assets/js/pages/address.js
  3. 1
      apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex
  4. 5
      apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex
  5. 2
      apps/block_scout_web/lib/block_scout_web/templates/internal_transaction/_tile.html.eex
  6. 38
      apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs

@ -1,300 +1,327 @@
import { reducer, initialState } from '../../js/pages/address'
describe('PAGE_LOAD', () => {
test('page 1 without filter', () => {
const state = initialState
describe('RECEIVED_NEW_BLOCK', () => {
test('with new block', () => {
const state = Object.assign({}, initialState, {
validationCount: 30,
validatedBlocks: [{ blockNumber: 1, blockHtml: 'test 1' }]
})
const action = {
type: 'PAGE_LOAD',
addressHash: '1234',
beyondPageOne: false,
pendingTransactionHashes: ['1']
type: 'RECEIVED_NEW_BLOCK',
msg: { blockNumber: 2, blockHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.addressHash).toBe('1234')
expect(output.beyondPageOne).toBe(false)
expect(output.filter).toBe(undefined)
expect(output.pendingTransactionHashes).toEqual(['1'])
expect(output.validationCount).toEqual(31)
expect(output.validatedBlocks).toEqual([
{ blockNumber: 2, blockHtml: 'test 2' },
{ blockNumber: 1, blockHtml: 'test 1' }
])
})
test('page 2 without filter', () => {
const state = initialState
test('when channel has been disconnected', () => {
const state = Object.assign({}, initialState, {
channelDisconnected: true,
validationCount: 30,
validatedBlocks: [{ blockNumber: 1, blockHtml: 'test 1' }]
})
const action = {
type: 'PAGE_LOAD',
addressHash: '1234',
beyondPageOne: true,
pendingTransactionHashes: ['1']
type: 'RECEIVED_NEW_BLOCK',
msg: { blockNumber: 2, blockHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.addressHash).toBe('1234')
expect(output.beyondPageOne).toBe(true)
expect(output.filter).toBe(undefined)
expect(output.pendingTransactionHashes).toEqual(['1'])
expect(output.validationCount).toEqual(30)
expect(output.validatedBlocks).toEqual([
{ blockNumber: 1, blockHtml: 'test 1' }
])
})
test('page 1 with "to" filter', () => {
const state = initialState
test('beyond page one', () => {
const state = Object.assign({}, initialState, {
beyondPageOne: true,
validationCount: 30,
validatedBlocks: [{ blockNumber: 1, blockHtml: 'test 1' }]
})
const action = {
type: 'PAGE_LOAD',
addressHash: '1234',
beyondPageOne: false,
filter: 'to'
type: 'RECEIVED_NEW_BLOCK',
msg: { blockNumber: 2, blockHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.addressHash).toBe('1234')
expect(output.beyondPageOne).toBe(false)
expect(output.filter).toBe('to')
expect(output.validationCount).toEqual(31)
expect(output.validatedBlocks).toEqual([
{ blockNumber: 1, blockHtml: 'test 1' }
])
})
test('page 2 with "to" filter', () => {
const state = initialState
})
describe('RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH', () => {
test('with new internal transaction', () => {
const state = Object.assign({}, initialState, {
internalTransactions: [{ internalTransactionHtml: 'test 1' }]
})
const action = {
type: 'PAGE_LOAD',
addressHash: '1234',
beyondPageOne: true,
filter: 'to'
type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH',
msgs: [{ internalTransactionHtml: 'test 2' }]
}
const output = reducer(state, action)
expect(output.addressHash).toBe('1234')
expect(output.beyondPageOne).toBe(true)
expect(output.filter).toBe('to')
expect(output.internalTransactions).toEqual([
{ internalTransactionHtml: 'test 2' },
{ internalTransactionHtml: 'test 1' }
])
})
})
test('CHANNEL_DISCONNECTED', () => {
const state = initialState
const action = {
type: 'CHANNEL_DISCONNECTED'
}
const output = reducer(state, action)
expect(output.channelDisconnected).toBe(true)
})
test('RECEIVED_UPDATED_BALANCE', () => {
const state = initialState
const action = {
type: 'RECEIVED_UPDATED_BALANCE',
msg: {
balance: 'hello world'
test('with batch of new internal transactions', () => {
const state = Object.assign({}, initialState, {
internalTransactions: [{ internalTransactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH',
msgs: [
{ internalTransactionHtml: 'test 2' },
{ internalTransactionHtml: 'test 3' },
{ internalTransactionHtml: 'test 4' },
{ internalTransactionHtml: 'test 5' },
{ internalTransactionHtml: 'test 6' },
{ internalTransactionHtml: 'test 7' },
{ internalTransactionHtml: 'test 8' },
{ internalTransactionHtml: 'test 9' },
{ internalTransactionHtml: 'test 10' },
{ internalTransactionHtml: 'test 11' },
{ internalTransactionHtml: 'test 12' },
{ internalTransactionHtml: 'test 13' }
]
}
}
const output = reducer(state, action)
expect(output.balance).toBe('hello world')
})
const output = reducer(state, action)
describe('RECEIVED_NEW_PENDING_TRANSACTION', () => {
test('single transaction', () => {
const state = initialState
expect(output.internalTransactions).toEqual([
{ internalTransactionHtml: 'test 1' }
])
expect(output.internalTransactionsBatch).toEqual([
{ internalTransactionHtml: 'test 13' },
{ internalTransactionHtml: 'test 12' },
{ internalTransactionHtml: 'test 11' },
{ internalTransactionHtml: 'test 10' },
{ internalTransactionHtml: 'test 9' },
{ internalTransactionHtml: 'test 8' },
{ internalTransactionHtml: 'test 7' },
{ internalTransactionHtml: 'test 6' },
{ internalTransactionHtml: 'test 5' },
{ internalTransactionHtml: 'test 4' },
{ internalTransactionHtml: 'test 3' },
{ internalTransactionHtml: 'test 2' },
])
})
test('after batch of new internal transactions', () => {
const state = Object.assign({}, initialState, {
internalTransactionsBatch: [{ internalTransactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: {
transactionHash: '0x00',
transactionHtml: 'test'
}
type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH',
msgs: [
{ internalTransactionHtml: 'test 2' }
]
}
const output = reducer(state, action)
expect(output.newPendingTransactions).toEqual(['test'])
expect(output.transactionCount).toEqual(null)
expect(output.internalTransactionsBatch).toEqual([
{ internalTransactionHtml: 'test 2' },
{ internalTransactionHtml: 'test 1' }
])
})
test('single transaction after single transaction', () => {
test('when channel has been disconnected', () => {
const state = Object.assign({}, initialState, {
newPendingTransactions: ['test 1']
channelDisconnected: true,
internalTransactions: [{ internalTransactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: {
transactionHash: '0x02',
transactionHtml: 'test 2'
}
type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH',
msgs: [{ internalTransactionHtml: 'test 2' }]
}
const output = reducer(state, action)
expect(output.newPendingTransactions).toEqual(['test 1', 'test 2'])
expect(output.pendingTransactionHashes.length).toEqual(1)
expect(output.internalTransactions).toEqual([
{ internalTransactionHtml: 'test 1' }
])
})
test('after disconnection', () => {
test('beyond page one', () => {
const state = Object.assign({}, initialState, {
channelDisconnected: true
beyondPageOne: true,
internalTransactions: [{ internalTransactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: {
transactionHash: '0x00',
transactionHtml: 'test'
}
type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH',
msgs: [{ internalTransactionHtml: 'test 2' }]
}
const output = reducer(state, action)
expect(output.newPendingTransactions).toEqual([])
expect(output.pendingTransactionHashes).toEqual([])
expect(output.internalTransactions).toEqual([
{ internalTransactionHtml: 'test 1' }
])
})
test('on page 2', () => {
test('with filtered out internal transaction', () => {
const state = Object.assign({}, initialState, {
beyondPageOne: true
filter: 'to'
})
const action = {
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: {
transactionHash: '0x00',
transactionHtml: 'test'
}
type: 'RECEIVED_NEW_INTERNAL_TRANSACTION_BATCH',
msgs: [{ internalTransactionHtml: 'test 2' }]
}
const output = reducer(state, action)
expect(output.newPendingTransactions).toEqual([])
expect(output.pendingTransactionHashes).toEqual([])
expect(output.internalTransactions).toEqual([])
})
})
describe('RECEIVED_NEW_TRANSACTION', () => {
test('single transaction', () => {
describe('RECEIVED_NEW_PENDING_TRANSACTION', () => {
test('with new pending transaction', () => {
const state = Object.assign({}, initialState, {
addressHash: '0x111'
pendingTransactions: [{ transactionHash: 1, transactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
transactionHtml: 'test'
}
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([{ transactionHtml: 'test' }])
expect(output.transactionCount).toEqual(null)
expect(output.pendingTransactions).toEqual([
{ transactionHash: 2, transactionHtml: 'test 2' },
{ transactionHash: 1, transactionHtml: 'test 1' }
])
})
test('single transaction after single transaction', () => {
test('when channel has been disconnected', () => {
const state = Object.assign({}, initialState, {
newTransactions: [{ transactionHtml: 'test 1' }]
channelDisconnected: true,
pendingTransactions: [{ transactionHash: 1, transactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
transactionHtml: 'test 2'
}
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([
{ transactionHtml: 'test 1' },
{ transactionHtml: 'test 2' }
expect(output.pendingTransactions).toEqual([
{ transactionHash: 1, transactionHtml: 'test 1' }
])
})
test('after disconnection', () => {
test('beyond page one', () => {
const state = Object.assign({}, initialState, {
channelDisconnected: true
beyondPageOne: true,
pendingTransactions: [{ transactionHash: 1, transactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
transactionHtml: 'test'
}
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([])
expect(output.pendingTransactions).toEqual([
{ transactionHash: 1, transactionHtml: 'test 1' }
])
})
test('on page 2', () => {
test('with filtered out pending transaction', () => {
const state = Object.assign({}, initialState, {
beyondPageOne: true,
transactionCount: 1,
addressHash: '0x111'
filter: 'to'
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
transactionHtml: 'test'
}
type: 'RECEIVED_NEW_PENDING_TRANSACTION',
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([])
expect(output.transactionCount).toEqual(1)
expect(output.pendingTransactions).toEqual([])
})
test('transaction from current address with "from" filter', () => {
})
describe('RECEIVED_NEW_TRANSACTION', () => {
test('with new transaction', () => {
const state = Object.assign({}, initialState, {
addressHash: '1234',
filter: 'from'
pendingTransactions: [{ transactionHash: 2, transactionHtml: 'test' }],
transactions: [{ transactionHash: 1, transactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
fromAddressHash: '1234',
transactionHtml: 'test'
}
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([
{ fromAddressHash: '1234', transactionHtml: 'test' }
expect(output.pendingTransactions).toEqual([
{ transactionHash: 2, transactionHtml: 'test 2', validated: true }
])
expect(output.transactions).toEqual([
{ transactionHash: 2, transactionHtml: 'test 2' },
{ transactionHash: 1, transactionHtml: 'test 1' }
])
})
test('transaction from current address with "to" filter', () => {
test('when channel has been disconnected', () => {
const state = Object.assign({}, initialState, {
addressHash: '1234',
filter: 'to'
channelDisconnected: true,
pendingTransactions: [{ transactionHash: 2, transactionHtml: 'test' }],
transactions: [{ transactionHash: 1, transactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
fromAddressHash: '1234',
transactionHtml: 'test'
}
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([])
expect(output.pendingTransactions).toEqual([
{ transactionHash: 2, transactionHtml: 'test' }
])
expect(output.transactions).toEqual([
{ transactionHash: 1, transactionHtml: 'test 1' }
])
})
test('transaction to current address with "to" filter', () => {
test('beyond page one', () => {
const state = Object.assign({}, initialState, {
addressHash: '1234',
filter: 'to'
beyondPageOne: true,
transactions: [{ transactionHash: 1, transactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
toAddressHash: '1234',
transactionHtml: 'test'
}
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([
{ toAddressHash: '1234', transactionHtml: 'test' }
expect(output.pendingTransactions).toEqual([])
expect(output.transactions).toEqual([
{ transactionHash: 1, transactionHtml: 'test 1' }
])
})
test('transaction to current address with "from" filter', () => {
test('with filtered out transaction', () => {
const state = Object.assign({}, initialState, {
addressHash: '1234',
filter: 'from'
filter: 'to'
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
msg: {
toAddressHash: '1234',
transactionHtml: 'test'
}
msg: { transactionHash: 2, transactionHtml: 'test 2' }
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([])
expect(output.transactions).toEqual([])
})
test('single transaction collated from pending', () => {
const state = initialState
})
describe('RECEIVED_NEXT_TRANSACTIONS_PAGE', () => {
test('with new transaction page', () => {
const state = Object.assign({}, initialState, {
loadingNextPage: true,
nextPage: '1',
transactions: [{ transactionHash: 1, transactionHtml: 'test 1' }]
})
const action = {
type: 'RECEIVED_NEW_TRANSACTION',
type: 'RECEIVED_NEXT_TRANSACTIONS_PAGE',
msg: {
transactionHash: '0x00',
transactionHtml: 'test'
nextPage: '2',
transactions: [{ transactionHash: 2, transactionHtml: 'test 2' }]
}
}
const output = reducer(state, action)
expect(output.newTransactions).toEqual([
{ transactionHash: '0x00', transactionHtml: 'test' }
expect(output.loadingNextPage).toEqual(false)
expect(output.nextPage).toEqual('2')
expect(output.transactions).toEqual([
{ transactionHash: 1, transactionHtml: 'test 1' },
{ transactionHash: 2, transactionHtml: 'test 2' }
])
expect(output.transactionCount).toEqual(null)
})
})

@ -103,8 +103,6 @@ export function reducer (state = initialState, action) {
})
}
case 'REMOVE_PENDING_TRANSACTION': {
if (state.channelDisconnected) return state
return Object.assign({}, state, {
pendingTransactions: state.pendingTransactions.filter((transaction) => action.msg.transactionHash !== transaction.transactionHash)
})
@ -247,7 +245,6 @@ const elements = {
load ($el) {
return {
internalTransactions: $el.children().map((index, el) => ({
internalTransactionId: el.dataset.internalTransactionId,
internalTransactionHtml: el.outerHTML
})).toArray()
}
@ -256,7 +253,7 @@ const elements = {
if (oldState.internalTransactions === state.internalTransactions) return
const container = $el[0]
const newElements = _.map(state.internalTransactions, ({ internalTransactionHtml }) => $(internalTransactionHtml)[0])
listMorph(container, newElements, { key: 'dataset.internalTransactionId' })
listMorph(container, newElements, { key: 'dataset.key' })
}
},
'[data-selector="channel-batching-count"]': {

@ -55,7 +55,6 @@ defmodule BlockScoutWeb.AddressChannel do
push(socket, "internal_transaction", %{
to_address_hash: to_string(internal_transaction.to_address_hash),
from_address_hash: to_string(internal_transaction.from_address_hash),
internal_transaction_id: to_string(internal_transaction.id),
internal_transaction_html: rendered_internal_transaction
})

@ -8,10 +8,10 @@ defmodule BlockScoutWeb.AddressTransactionController do
import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1]
import BlockScoutWeb.Chain, only: [current_filter: 1, paging_options: 1, next_page_params: 3, split_list_by_page: 1]
alias BlockScoutWeb.TransactionView
alias Explorer.{Chain, Market}
alias Explorer.ExchangeRates.Token
alias Explorer.Chain.Hash
alias BlockScoutWeb.{InternalTransactionView, AddressView, TransactionView}
alias Explorer.ExchangeRates.Token
alias Phoenix.View
def index(conn, %{"address_id" => address_hash_string, "type" => "JSON"} = params) do
@ -87,6 +87,7 @@ defmodule BlockScoutWeb.AddressTransactionController do
:token_transfers => :optional
}
]
|> Keyword.merge(paging_options(%{}))
|> Keyword.merge(current_filter(params))
full_options = put_in(pending_options, [:necessity_by_association, :block], :required)

@ -1,4 +1,4 @@
<div class="tile tile-type-internal-transaction fade-in" data-test="internal_transaction" data-internal-transaction-transaction-hash="<%= @internal_transaction.transaction_hash %>" data-internal-transaction-index="<%= @internal_transaction.index %>">
<div class="tile tile-type-internal-transaction fade-in" data-test="internal_transaction" data-key="<%= @internal_transaction.transaction_hash %>_<%= @internal_transaction.index %>" data-internal-transaction-transaction-hash="<%= @internal_transaction.transaction_hash %>" data-internal-transaction-index="<%= @internal_transaction.index %>">
<div class="row">
<div class="col-md-2 d-flex flex-row flex-md-column align-items-left justify-content-start justify-content-lg-center mb-1 mb-md-0 pl-md-4">
<%= gettext("Internal Transaction") %>

@ -76,7 +76,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
50
|> insert_list(:transaction, from_address: address)
|> with_block()
|> Enum.map(& &1.hash)
|> Enum.map(&to_string(&1.hash))
%Transaction{block_number: block_number, index: index} =
:transaction
@ -85,47 +85,21 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
conn =
get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{
"type" => "JSON",
"block_number" => Integer.to_string(block_number),
"index" => Integer.to_string(index)
})
{:ok, %{"transactions" => transactions}} = conn.resp_body |> Poison.decode()
actual_hashes =
conn.assigns.transactions
|> Enum.map(& &1.hash)
transactions
|> Enum.map(& &1["transaction_hash"])
|> Enum.reverse()
assert second_page_hashes == actual_hashes
end
test "does not return pending transactions if beyond page one", %{conn: conn} do
address = insert(:address)
50
|> insert_list(:transaction, from_address: address)
|> with_block()
|> Enum.map(& &1.hash)
%Transaction{block_number: block_number, index: index} =
:transaction
|> insert(from_address: address)
|> with_block()
pending = insert(:transaction, from_address: address, to_address: address)
conn =
get(conn, address_transaction_path(BlockScoutWeb.Endpoint, :index, address.hash), %{
"block_number" => Integer.to_string(block_number),
"index" => Integer.to_string(index)
})
actual_pending_hashes =
conn.assigns.pending_transactions
|> Enum.map(& &1.hash)
|> Enum.reverse()
refute Enum.member?(actual_pending_hashes, pending.hash)
end
test "next_page_params exist if not on last page", %{conn: conn} do
address = insert(:address)
block = %Block{number: number} = insert(:block)

Loading…
Cancel
Save