13
13
from decimal import Decimal
14
14
15
15
from test_framework .test_framework import BitcoinTestFramework
16
- from test_framework .util import assert_equal , assert_raises_rpc_error , connect_nodes , disconnect_nodes , sync_blocks , sync_mempools
16
+ from test_framework .util import (
17
+ assert_equal ,
18
+ assert_raises_rpc_error ,
19
+ connect_nodes ,
20
+ disconnect_nodes ,
21
+ sync_blocks ,
22
+ sync_mempools ,
23
+ )
24
+
17
25
18
26
class AbandonConflictTest (BitcoinTestFramework ):
19
27
def set_test_params (self ):
@@ -40,7 +48,7 @@ def run_test(self):
40
48
41
49
sync_blocks (self .nodes )
42
50
newbalance = self .nodes [0 ].getbalance ()
43
- assert ( balance - newbalance < Decimal ("0.001" )) #no more than fees lost
51
+ assert balance - newbalance < Decimal ("0.001" ) #no more than fees lost
44
52
balance = newbalance
45
53
46
54
# Disconnect nodes so node0's transactions don't get into node1's mempool
@@ -51,10 +59,10 @@ def run_test(self):
51
59
nB = next (i for i , vout in enumerate (self .nodes [0 ].getrawtransaction (txB , 1 )["vout" ]) if vout ["value" ] == Decimal ("10" ))
52
60
nC = next (i for i , vout in enumerate (self .nodes [0 ].getrawtransaction (txC , 1 )["vout" ]) if vout ["value" ] == Decimal ("10" ))
53
61
54
- inputs = []
62
+ inputs = []
55
63
# spend 10btc outputs from txA and txB
56
- inputs .append ({"txid" :txA , "vout" :nA })
57
- inputs .append ({"txid" :txB , "vout" :nB })
64
+ inputs .append ({"txid" : txA , "vout" : nA })
65
+ inputs .append ({"txid" : txB , "vout" : nB })
58
66
outputs = {}
59
67
60
68
outputs [self .nodes [0 ].getnewaddress ()] = Decimal ("14.99998" )
@@ -67,17 +75,17 @@ def run_test(self):
67
75
68
76
#Create a child tx spending AB1 and C
69
77
inputs = []
70
- inputs .append ({"txid" :txAB1 , "vout" :nAB })
71
- inputs .append ({"txid" :txC , "vout" :nC })
78
+ inputs .append ({"txid" : txAB1 , "vout" : nAB })
79
+ inputs .append ({"txid" : txC , "vout" : nC })
72
80
outputs = {}
73
81
outputs [self .nodes [0 ].getnewaddress ()] = Decimal ("24.9996" )
74
82
signed2 = self .nodes [0 ].signrawtransactionwithwallet (self .nodes [0 ].createrawtransaction (inputs , outputs ))
75
83
txABC2 = self .nodes [0 ].sendrawtransaction (signed2 ["hex" ])
76
84
77
85
# Create a child tx spending ABC2
78
86
signed3_change = Decimal ("24.999" )
79
- inputs = [ {"txid" :txABC2 , "vout" :0 } ]
80
- outputs = { self .nodes [0 ].getnewaddress (): signed3_change }
87
+ inputs = [{"txid" : txABC2 , "vout" : 0 } ]
88
+ outputs = {self .nodes [0 ].getnewaddress (): signed3_change }
81
89
signed3 = self .nodes [0 ].signrawtransactionwithwallet (self .nodes [0 ].createrawtransaction (inputs , outputs ))
82
90
# note tx is never directly referenced, only abandoned as a child of the above
83
91
self .nodes [0 ].sendrawtransaction (signed3 ["hex" ])
@@ -105,7 +113,7 @@ def run_test(self):
105
113
unconfbalance = self .nodes [0 ].getunconfirmedbalance () + self .nodes [0 ].getbalance ()
106
114
assert_equal (unconfbalance , newbalance )
107
115
# Also shouldn't show up in listunspent
108
- assert ( not txABC2 in [utxo ["txid" ] for utxo in self .nodes [0 ].listunspent (0 )])
116
+ assert not txABC2 in [utxo ["txid" ] for utxo in self .nodes [0 ].listunspent (0 )]
109
117
balance = newbalance
110
118
111
119
# Abandon original transaction and verify inputs are available again
@@ -145,8 +153,8 @@ def run_test(self):
145
153
146
154
# Create a double spend of AB1 by spending again from only A's 10 output
147
155
# Mine double spend from node 1
148
- inputs = []
149
- inputs .append ({"txid" :txA , "vout" :nA })
156
+ inputs = []
157
+ inputs .append ({"txid" : txA , "vout" : nA })
150
158
outputs = {}
151
159
outputs [self .nodes [1 ].getnewaddress ()] = Decimal ("9.9999" )
152
160
tx = self .nodes [0 ].createrawtransaction (inputs , outputs )
@@ -172,5 +180,6 @@ def run_test(self):
172
180
self .log .info ("conflicted has not resumed causing its inputs to be seen as spent. See Issue #7315" )
173
181
self .log .info (str (balance ) + " -> " + str (newbalance ) + " ?" )
174
182
183
+
175
184
if __name__ == '__main__' :
176
185
AbandonConflictTest ().main ()
0 commit comments