aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_abandonconflict.py
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-09-30 15:09:08 +0200
committerJon Atack <jon@atack.com>2021-10-02 15:27:40 +0200
commit502f50da12694dd0193744427f0f89238e612f54 (patch)
tree901a64952d65d8b77c762a5698f7a1af15c4d5d8 /test/functional/wallet_abandonconflict.py
parent1cf7fb9fd65820b298a0eb28f6e2c4c7409c78d1 (diff)
downloadbitcoin-502f50da12694dd0193744427f0f89238e612f54.tar.xz
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.
Diffstat (limited to 'test/functional/wallet_abandonconflict.py')
-rwxr-xr-xtest/functional/wallet_abandonconflict.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/functional/wallet_abandonconflict.py b/test/functional/wallet_abandonconflict.py
index 6365840041..70ca5a2fe4 100755
--- a/test/functional/wallet_abandonconflict.py
+++ b/test/functional/wallet_abandonconflict.py
@@ -149,6 +149,7 @@ class AbandonConflictTest(BitcoinTestFramework):
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 = []
@@ -163,6 +164,34 @@ class AbandonConflictTest(BitcoinTestFramework):
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"))