Skip to content

Commit

Permalink
fix: blockchain info statistic (#1469)
Browse files Browse the repository at this point in the history
* fix: blockchain info statistic

* chore: adjust tests
  • Loading branch information
rabbitz authored Oct 12, 2023
1 parent 755a05c commit e0a7d21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/models/statistic_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def self.hash_rate(block_number)
end

define_logic :blockchain_info do
message_need_to_be_fitlered_out = "CKB v0.105.* have bugs. Please upgrade to the latest version."
message_need_to_be_filtered_out = "CKB v0.105.* have bugs. Please upgrade to the latest version."
result = CkbSync::Api.instance.get_blockchain_info
result.alerts.delete_if { |alert| alert.message == message_need_to_be_fitlered_out }
result
result.alerts.delete_if { |alert| alert.message == message_need_to_be_filtered_out }
JSON.generate(result.as_json)
end

define_logic :transaction_fee_rates do
Expand Down
4 changes: 3 additions & 1 deletion app/serializers/statistic_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class StatisticSerializer

attribute :blockchain_info, if: Proc.new { |_record, params|
params && params[:info_name] == "blockchain_info"
}
} do |object|
JSON.parse(object.blockchain_info)
end

attribute :flush_cache_info, if: Proc.new { |_record, params|
params && params[:info_name] == "flush_cache_info"
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/api/v1/statistics_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ class StatisticsControllerTest < ActionDispatch::IntegrationTest
chain: "ckb_testnet",
alerts: []
)
StatisticInfo.any_instance.stubs(:blockchain_info).returns(blockchain_info)
CkbSync::Api.any_instance.stubs(:get_blockchain_info).returns(blockchain_info)
statistic_info = StatisticInfo.default
statistic_info.reset! :blockchain_info
valid_get api_v1_statistic_url("blockchain_info")

assert_equal StatisticSerializer.new(statistic_info, { params: { info_name: "blockchain_info" } }).serialized_json,
response.body
assert_equal blockchain_info.as_json, json.dig("data", "attributes", "blockchain_info")
end

test "should return top 50 addresses balance list when param is address balance ranking" do
Expand Down

0 comments on commit e0a7d21

Please sign in to comment.