3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
- #
7
- # Exercise the wallet. Ported from wallet.sh.
8
- # Does the following:
9
- # a) creates 3 nodes, with an empty chain (no blocks).
10
- # b) node0 mines a block
11
- # c) node1 mines 101 blocks, so now nodes 0 and 1 have 50btc, node2 has none.
12
- # d) node0 sends 21 btc to node2, in two transactions (11 btc, then 10 btc).
13
- # e) node0 mines a block, collects the fee on the second transaction
14
- # f) node1 mines 100 blocks, to mature node0's just-mined block
15
- # g) check that node0 has 100-21, node2 has 21
16
- # h) node0 should now have 2 unspent outputs; send these to node2 via raw tx broadcast by node1
17
- # i) have node1 mine a block
18
- # j) check balances - node0 should have 0, node2 should have 100
19
- # k) test ResendWalletTransactions - create transactions, startup fourth node, make sure it syncs
20
- #
21
6
22
7
from test_framework .test_framework import BitcoinTestFramework
23
8
from test_framework .util import *
@@ -190,7 +175,7 @@ def run_test (self):
190
175
for uTx in unspentTxs :
191
176
if uTx ['txid' ] == zeroValueTxid :
192
177
found = True
193
- assert_equal (uTx ['amount' ], Decimal ('0.00000000 ' ));
178
+ assert_equal (uTx ['amount' ], Decimal ('0' ))
194
179
assert (found )
195
180
196
181
#do some -walletbroadcast tests
@@ -202,21 +187,21 @@ def run_test (self):
202
187
connect_nodes_bi (self .nodes ,0 ,2 )
203
188
self .sync_all ()
204
189
205
- txIdNotBroadcasted = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 2 );
190
+ txIdNotBroadcasted = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 2 )
206
191
txObjNotBroadcasted = self .nodes [0 ].gettransaction (txIdNotBroadcasted )
207
192
self .nodes [1 ].generate (1 ) #mine a block, tx should not be in there
208
193
self .sync_all ()
209
- assert_equal (self .nodes [2 ].getbalance (), node_2_bal ); #should not be changed because tx was not broadcasted
194
+ assert_equal (self .nodes [2 ].getbalance (), node_2_bal ) #should not be changed because tx was not broadcasted
210
195
211
196
#now broadcast from another node, mine a block, sync, and check the balance
212
197
self .nodes [1 ].sendrawtransaction (txObjNotBroadcasted ['hex' ])
213
198
self .nodes [1 ].generate (1 )
214
199
self .sync_all ()
215
200
txObjNotBroadcasted = self .nodes [0 ].gettransaction (txIdNotBroadcasted )
216
- assert_equal (self .nodes [2 ].getbalance (), node_2_bal + Decimal ('2' )); #should not be
201
+ assert_equal (self .nodes [2 ].getbalance (), node_2_bal + Decimal ('2' )) #should not be
217
202
218
203
#create another tx
219
- txIdNotBroadcasted = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 2 );
204
+ txIdNotBroadcasted = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 2 )
220
205
221
206
#restart the nodes with -walletbroadcast=1
222
207
stop_nodes (self .nodes )
@@ -231,21 +216,21 @@ def run_test (self):
231
216
sync_blocks (self .nodes )
232
217
233
218
#tx should be added to balance because after restarting the nodes tx should be broadcastet
234
- assert_equal (self .nodes [2 ].getbalance (), node_2_bal + Decimal ('4' )); #should not be
219
+ assert_equal (self .nodes [2 ].getbalance (), node_2_bal + Decimal ('4' )) #should not be
235
220
236
221
#send a tx with value in a string (PR#6380 +)
237
222
txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), "2" )
238
223
txObj = self .nodes [0 ].gettransaction (txId )
239
- assert_equal (txObj ['amount' ], Decimal ('-2.00000000 ' ))
224
+ assert_equal (txObj ['amount' ], Decimal ('-2' ))
240
225
241
226
txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), "0.0001" )
242
227
txObj = self .nodes [0 ].gettransaction (txId )
243
- assert_equal (txObj ['amount' ], Decimal ('-0.00010000 ' ))
228
+ assert_equal (txObj ['amount' ], Decimal ('-0.0001 ' ))
244
229
245
230
#check if JSON parser can handle scientific notation in strings
246
231
txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), "1e-4" )
247
232
txObj = self .nodes [0 ].gettransaction (txId )
248
- assert_equal (txObj ['amount' ], Decimal ('-0.00010000 ' ))
233
+ assert_equal (txObj ['amount' ], Decimal ('-0.0001 ' ))
249
234
250
235
#this should fail
251
236
errorString = ""
@@ -254,15 +239,15 @@ def run_test (self):
254
239
except JSONRPCException ,e :
255
240
errorString = e .error ['message' ]
256
241
257
- assert_equal ("Invalid amount" in errorString , True );
242
+ assert_equal ("Invalid amount" in errorString , True )
258
243
259
244
errorString = ""
260
245
try :
261
246
self .nodes [0 ].generate ("2" ) #use a string to as block amount parameter must fail because it's not interpreted as amount
262
247
except JSONRPCException ,e :
263
248
errorString = e .error ['message' ]
264
249
265
- assert_equal ("not an integer" in errorString , True );
250
+ assert_equal ("not an integer" in errorString , True )
266
251
267
252
268
253
if __name__ == '__main__' :
0 commit comments