Skip to content

Commit

Permalink
chore: adjust tests (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz authored Apr 9, 2024
1 parent 0568529 commit aa25446
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
9 changes: 5 additions & 4 deletions app/controllers/api/v1/address_dao_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ def show
address = Address.find_address!(params[:id])
raise Api::V1::Exceptions::AddressNotFoundError if address.is_a?(NullAddress)

ckb_dao_transactions = address.ckb_dao_transactions.select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at).recent.page(@page).per(@page_size).fast_page
ckb_dao_transactions = address.ckb_dao_transactions.select(:id, :tx_hash, :block_id, :block_number, :tags, :block_timestamp, :is_cellbase, :updated_at, :created_at).
recent.page(@page).per(@page_size).fast_page
json =
Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do
records_counter = RecordCounters::AddressDaoTransactions.new(address)
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_dao_transactions, page: @page, page_size: @page_size, records_counter: records_counter).call
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_dao_transactions, page: @page, page_size: @page_size, records_counter:).call
CkbTransactionsSerializer.new(ckb_dao_transactions, options.merge(params: { previews: true })).serialized_json
end

render json: json
render json:
end

private
Expand All @@ -28,7 +29,7 @@ def validate_query_params
errors = validator.error_object[:errors]
status = validator.error_object[:status]

render json: errors, status: status
render json: errors, status:
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def show
raise Api::V1::Exceptions::UdtNotFoundError if udt.blank?

ckb_dao_transactions = address.ckb_udt_transactions(udt.id).
select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at).
select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at, :tags).
recent.page(@page).per(@page_size).fast_page
json =
Rails.cache.realize(ckb_dao_transactions.cache_key, version: ckb_dao_transactions.cache_version) do
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/api/v1/block_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BlockTransactionsController < ApplicationController
def show
block = Block.find_by!(block_hash: params[:id])
ckb_transactions = block.ckb_transactions.
select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at).
select(:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at, :tags).
order(is_cellbase: :desc, id: :asc)

if params[:tx_hash].present?
Expand All @@ -24,16 +24,16 @@ def show
records_counter = RecordCounters::BlockTransactions.new(ckb_transactions)
ckb_transactions = ckb_transactions.page(@page).per(@page_size).fast_page
options = FastJsonapi::PaginationMetaGenerator.new(
request: request,
request:,
records: ckb_transactions,
page: @page,
page_size: @page_size,
records_counter: records_counter
records_counter:,
).call
json = CkbTransactionsSerializer.new(ckb_transactions,
options.merge(params: { previews: true })).serialized_json

render json: json
render json:
end
rescue ActiveRecord::RecordNotFound
raise Api::V1::Exceptions::BlockTransactionsNotFoundError
Expand All @@ -48,7 +48,7 @@ def validate_query_params
errors = validator.error_object[:errors]
status = validator.error_object[:status]

render json: errors, status: status
render json: errors, status:
end
end

Expand Down
12 changes: 6 additions & 6 deletions app/controllers/api/v1/ckb_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module Api
module V1
class CkbTransactionsController < ApplicationController
before_action :validate_query_params, only: %i[show]
before_action :find_transaction,only: %i[show]
before_action :find_transaction, only: %i[show]
before_action :validate_pagination_params, :pagination_params, only: %i[index]

def index
if from_home_page?
ckb_transactions = CkbTransaction.tx_committed.recent.normal.select(
:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at, :created_at
:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at, :created_at, :tags
).limit((Settings.homepage_transactions_records_count || 15).to_i)
json =
Rails.cache.realize(ckb_transactions.cache_key,
Expand All @@ -18,7 +18,7 @@ def index
render json:
else
ckb_transactions = CkbTransaction.tx_committed.normal.select(
:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at, :created_at
:id, :tx_hash, :block_number, :block_timestamp, :live_cell_changes, :capacity_involved, :updated_at, :created_at, :tags
)

params[:sort] ||= "id.desc"
Expand Down Expand Up @@ -83,7 +83,7 @@ def query
records_counter = RecordCounters::Transactions.new
CkbTransaction.recent.normal.page(@page).per(@page_size).fast_page
end
ckb_transactions = ckb_transactions.select(:id, :tx_hash, :block_id,
ckb_transactions = ckb_transactions.select(:id, :tx_hash, :block_id, :tags,
:block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at)
json =
Rails.cache.realize(ckb_transactions.cache_key,
Expand All @@ -107,8 +107,8 @@ def show
expires_in 10.seconds, public: true, must_revalidate: true

render json: CkbTransactionSerializer.new(@ckb_transaction, {
params: { display_cells: params.fetch(:display_cells, true)
}})
params: { display_cells: params.fetch(:display_cells, true) },
})
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/v1/contract_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def show
expires_in 10.seconds, public: true, must_revalidate: true, stale_while_revalidate: 5.seconds

ckb_transactions = dao_contract.ckb_transactions.includes(:cell_inputs, :cell_outputs).tx_committed.select(
:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at
:id, :tx_hash, :block_id, :block_number, :block_timestamp, :is_cellbase, :updated_at, :created_at, :tags
).order("ckb_transactions.block_timestamp desc nulls last, ckb_transactions.id desc")

if params[:tx_hash].present?
Expand All @@ -28,12 +28,12 @@ def show
end

ckb_transactions = ckb_transactions.page(@page).per(@page_size).fast_page
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions,
options = FastJsonapi::PaginationMetaGenerator.new(request:, records: ckb_transactions,
page: @page, page_size: @page_size).call
json = CkbTransactionsSerializer.new(ckb_transactions,
options.merge(params: { previews: true })).serialized_json

render json: json
render json:
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/interactions/addresses/pending_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def transactions_ordering
end

def select_fields
%i[id tx_hash block_id block_number block_timestamp
%i[id tx_hash block_id block_number block_timestamp tags
is_cellbase updated_at capacity_involved created_at]
end

Expand Down
2 changes: 1 addition & 1 deletion app/interactions/udts/ckb_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def validate_tx_hash!

def select_fields
%i[id tx_hash block_id block_number block_timestamp
is_cellbase updated_at created_at]
is_cellbase updated_at created_at tags]
end
end
end

0 comments on commit aa25446

Please sign in to comment.