Skip to content

Commit 502f50d

Browse files
committed
Test transactions conflicted by double spend in listtransactions
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.
1 parent 1cf7fb9 commit 502f50d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/functional/wallet_abandonconflict.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def run_test(self):
149149
assert_equal(newbalance, balance - Decimal("24.9996"))
150150
balance = newbalance
151151

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

167+
tx_list = self.nodes[0].listtransactions()
168+
169+
conflicted = [tx for tx in tx_list if tx["confirmations"] < 0]
170+
assert_equal(4, len(conflicted))
171+
172+
wallet_conflicts = [tx for tx in conflicted if tx["walletconflicts"]]
173+
assert_equal(2, len(wallet_conflicts))
174+
175+
double_spends = [tx for tx in tx_list if tx["walletconflicts"] and tx["confirmations"] > 0]
176+
assert_equal(1, len(double_spends))
177+
double_spend = double_spends[0]
178+
179+
# Test the properties of the conflicted transactions, i.e. with confirmations < 0.
180+
for tx in conflicted:
181+
assert_equal(tx["abandoned"], False)
182+
assert_equal(tx["confirmations"], -1)
183+
assert_equal(tx["trusted"], False)
184+
185+
# Test the properties of the double-spend transaction, i.e. having wallet conflicts and confirmations > 0.
186+
assert_equal(double_spend["abandoned"], False)
187+
assert_equal(double_spend["confirmations"], 1)
188+
assert "trusted" not in double_spend.keys() # "trusted" only returned if tx has 0 or negative confirmations.
189+
190+
# Test the walletconflicts field of each.
191+
for tx in wallet_conflicts:
192+
assert_equal(double_spend["walletconflicts"], [tx["txid"]])
193+
assert_equal(tx["walletconflicts"], [double_spend["txid"]])
194+
166195
# Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted
167196
newbalance = self.nodes[0].getbalance()
168197
assert_equal(newbalance, balance + Decimal("20"))

0 commit comments

Comments
 (0)