diff --git a/app/workers/pool_transaction_check_worker.rb b/app/workers/pool_transaction_check_worker.rb index 523054079a..885c171639 100644 --- a/app/workers/pool_transaction_check_worker.rb +++ b/app/workers/pool_transaction_check_worker.rb @@ -16,6 +16,13 @@ def perform tx.create_reject_reason!(message: reason["reason"]) end end + + if reason["status"] == "unknown" + ApplicationRecord.transaction do + tx.update! tx_status: "rejected" + tx.create_reject_reason!(message: "unknown") + end + end end end end diff --git a/test/workers/pool_transaction_check_worker_test.rb b/test/workers/pool_transaction_check_worker_test.rb index 843627edab..b6babae46f 100644 --- a/test/workers/pool_transaction_check_worker_test.rb +++ b/test/workers/pool_transaction_check_worker_test.rb @@ -1,18 +1,31 @@ require "test_helper" class PoolTransactionCheckWorkerTest < ActiveSupport::TestCase - setup do + test "should marked tx to rejected when rpc returns rejected" do + CkbSync::Api.any_instance.stubs(:generate_json_rpc_id).returns(1) rejected_tx_id = "0xed2049c21ffccfcd26281d60f8f77ff117adb9df9d3f8cbe5fe86e893c66d359" - @pending_tx = create(:pending_transaction, - tx_hash: rejected_tx_id, created_at: 10.minutes.ago) + pending_tx = create(:pending_transaction, + tx_hash: rejected_tx_id, created_at: 10.minutes.ago) + + Sidekiq::Testing.inline! + VCR.use_cassette("get_rejected_transaction") do + PoolTransactionCheckWorker.perform_async + assert_equal "rejected", pending_tx.reload.tx_status + assert pending_tx.detailed_message.include?("Resolve failed Dead") + end end - test "should detect and mark failed tx from pending tx, for inputs" do + test "should marked tx to rejected when rpc returns unknown" do + CkbSync::Api.any_instance.stubs(:generate_json_rpc_id).returns(2) + unknown_tx_id = "0x1cebe4b6ddae45264790835200fe3a4efdc58e3474e552aff2246eb42b79ed2c" + pending_tx = create(:pending_transaction, + tx_hash: unknown_tx_id, created_at: 10.minutes.ago) + Sidekiq::Testing.inline! VCR.use_cassette("get_rejected_transaction") do PoolTransactionCheckWorker.perform_async - assert_equal "rejected", @pending_tx.reload.tx_status - assert @pending_tx.detailed_message.include?("Resolve failed Dead") + assert_equal "rejected", pending_tx.reload.tx_status + assert pending_tx.detailed_message.include?("unknown") end end end diff --git a/vcr_fixtures/vcr_cassettes/get_rejected_transaction.yml b/vcr_fixtures/vcr_cassettes/get_rejected_transaction.yml index 3c4088409b..c65b8d34a3 100644 --- a/vcr_fixtures/vcr_cassettes/get_rejected_transaction.yml +++ b/vcr_fixtures/vcr_cassettes/get_rejected_transaction.yml @@ -36,4 +36,37 @@ http_interactions: ' recorded_at: Tue, 25 Oct 2022 02:20:50 GMT +- request: + method: post + uri: http://localhost:8114/ + body: + encoding: UTF-8 + string: '{"id":2,"jsonrpc":"2.0","method":"get_transaction","params":["0x1cebe4b6ddae45264790835200fe3a4efdc58e3474e552aff2246eb42b79ed2c"]}' + headers: + Connection: + - close + Content-Type: + - application/json; charset=UTF-8 + Host: + - localhost:8114 + User-Agent: + - http.rb/5.0.4 + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json; charset=utf-8 + Connection: + - close + Content-Length: + - '267' + Date: + - Tue, 25 Oct 2022 02:20:50 GMT + body: + encoding: UTF-8 + string: '{"jsonrpc":"2.0","result":{"cycles":null,"fee":null,"min_replace_fee":null,"time_added_to_pool":null,"transaction":null,"tx_status":{"block_hash":null,"reason":null,"status":"unknown"}},"id":2}' + recorded_at: Tue, 25 Oct 2022 02:20:50 GMT + recorded_with: VCR 6.0.0