Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#23146: Test transactions conflicted by double s…
Browse files Browse the repository at this point in the history
…pend in listtransactions

502f50d Test transactions conflicted by double spend in listtransactions (Jon Atack)

Pull request description:

  Test the properties of transactions conflicted by a double spend as returned by RPC listtransactions in the abandoned, confirmations, trusted and walletconflicts fields. These fields are also returned by RPCs listsinceblock and gettransactions.

ACKs for top commit:
  brunoerg:
    tACK 502f50d
  rajarshimaitra:
    Concept + tACK bitcoin/bitcoin@502f50d

Tree-SHA512: 28968f4a5f1960ea45b2e6f5b20fe25c1b51f66944062dcddea52ea970ad21c74d583793d091b84e8a5e506d6aecc1f0435c5b918213975b22c38e02bba19aa1
  • Loading branch information
MarcoFalke committed Oct 7, 2021
2 parents b4437d7 + 502f50d commit c0b6c96
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/functional/wallet_abandonconflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def run_test(self):
assert_equal(newbalance, balance - Decimal("24.9996"))
balance = newbalance

self.log.info("Test transactions conflicted by a double spend")
# Create a double spend of AB1 by spending again from only A's 10 output
# Mine double spend from node 1
inputs = []
Expand All @@ -163,6 +164,34 @@ def run_test(self):
self.connect_nodes(0, 1)
self.sync_blocks()

tx_list = self.nodes[0].listtransactions()

conflicted = [tx for tx in tx_list if tx["confirmations"] < 0]
assert_equal(4, len(conflicted))

wallet_conflicts = [tx for tx in conflicted if tx["walletconflicts"]]
assert_equal(2, len(wallet_conflicts))

double_spends = [tx for tx in tx_list if tx["walletconflicts"] and tx["confirmations"] > 0]
assert_equal(1, len(double_spends))
double_spend = double_spends[0]

# Test the properties of the conflicted transactions, i.e. with confirmations < 0.
for tx in conflicted:
assert_equal(tx["abandoned"], False)
assert_equal(tx["confirmations"], -1)
assert_equal(tx["trusted"], False)

# Test the properties of the double-spend transaction, i.e. having wallet conflicts and confirmations > 0.
assert_equal(double_spend["abandoned"], False)
assert_equal(double_spend["confirmations"], 1)
assert "trusted" not in double_spend.keys() # "trusted" only returned if tx has 0 or negative confirmations.

# Test the walletconflicts field of each.
for tx in wallet_conflicts:
assert_equal(double_spend["walletconflicts"], [tx["txid"]])
assert_equal(tx["walletconflicts"], [double_spend["txid"]])

# Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted
newbalance = self.nodes[0].getbalance()
assert_equal(newbalance, balance + Decimal("20"))
Expand Down

0 comments on commit c0b6c96

Please sign in to comment.