Skip to content

Commit

Permalink
feat: handle unknown status tx
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid committed Dec 27, 2023
1 parent 5cf0100 commit 82e83eb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/workers/pool_transaction_check_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 19 additions & 6 deletions test/workers/pool_transaction_check_worker_test.rb
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions vcr_fixtures/vcr_cassettes/get_rejected_transaction.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82e83eb

Please sign in to comment.