11#!/usr/bin/env python3
2- # Copyright (c) 2014-2018 The Bitcoin Core developers
2+ # Copyright (c) 2014-2019 The Bitcoin Core developers
33# Distributed under the MIT software license, see the accompanying
44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55"""Test the wallet."""
1919 wait_until ,
2020)
2121
22+
2223class WalletTest (BitcoinTestFramework ):
2324 def set_test_params (self ):
2425 self .num_nodes = 4
@@ -196,7 +197,7 @@ def run_test(self):
196197 txid = self .nodes [2 ].sendtoaddress (address , 10 , "" , "" , False )
197198 self .nodes [2 ].generate (1 )
198199 self .sync_all ([self .nodes [0 :3 ]])
199- node_2_bal = self .check_fee_amount (self .nodes [2 ].getbalance (), Decimal ('84' ), fee_per_byte , self .get_vsize (self .nodes [2 ].getrawtransaction (txid )))
200+ node_2_bal = self .check_fee_amount (self .nodes [2 ].getbalance (), Decimal ('84' ), fee_per_byte , self .get_vsize (self .nodes [2 ].gettransaction (txid )[ 'hex' ] ))
200201 assert_equal (self .nodes [0 ].getbalance (), Decimal ('10' ))
201202
202203 # Send 10 BTC with subtract fee from amount
@@ -205,14 +206,14 @@ def run_test(self):
205206 self .sync_all ([self .nodes [0 :3 ]])
206207 node_2_bal -= Decimal ('10' )
207208 assert_equal (self .nodes [2 ].getbalance (), node_2_bal )
208- node_0_bal = self .check_fee_amount (self .nodes [0 ].getbalance (), Decimal ('20' ), fee_per_byte , self .get_vsize (self .nodes [2 ].getrawtransaction (txid )))
209+ node_0_bal = self .check_fee_amount (self .nodes [0 ].getbalance (), Decimal ('20' ), fee_per_byte , self .get_vsize (self .nodes [2 ].gettransaction (txid )[ 'hex' ] ))
209210
210211 # Sendmany 10 BTC
211212 txid = self .nodes [2 ].sendmany ('' , {address : 10 }, 0 , "" , [])
212213 self .nodes [2 ].generate (1 )
213214 self .sync_all ([self .nodes [0 :3 ]])
214215 node_0_bal += Decimal ('10' )
215- node_2_bal = self .check_fee_amount (self .nodes [2 ].getbalance (), node_2_bal - Decimal ('10' ), fee_per_byte , self .get_vsize (self .nodes [2 ].getrawtransaction (txid )))
216+ node_2_bal = self .check_fee_amount (self .nodes [2 ].getbalance (), node_2_bal - Decimal ('10' ), fee_per_byte , self .get_vsize (self .nodes [2 ].gettransaction (txid )[ 'hex' ] ))
216217 assert_equal (self .nodes [0 ].getbalance (), node_0_bal )
217218
218219 # Sendmany 10 BTC with subtract fee from amount
@@ -221,7 +222,7 @@ def run_test(self):
221222 self .sync_all ([self .nodes [0 :3 ]])
222223 node_2_bal -= Decimal ('10' )
223224 assert_equal (self .nodes [2 ].getbalance (), node_2_bal )
224- node_0_bal = self .check_fee_amount (self .nodes [0 ].getbalance (), node_0_bal + Decimal ('10' ), fee_per_byte , self .get_vsize (self .nodes [2 ].getrawtransaction (txid )))
225+ node_0_bal = self .check_fee_amount (self .nodes [0 ].getbalance (), node_0_bal + Decimal ('10' ), fee_per_byte , self .get_vsize (self .nodes [2 ].gettransaction (txid )[ 'hex' ] ))
225226
226227 # Test ResendWalletTransactions:
227228 # Create a couple of transactions, then start up a fourth
@@ -239,7 +240,7 @@ def run_test(self):
239240 assert_equal (set (relayed ), {txid1 , txid2 })
240241 sync_mempools (self .nodes )
241242
242- assert ( txid1 in self .nodes [3 ].getrawmempool () )
243+ assert txid1 in self .nodes [3 ].getrawmempool ()
243244
244245 # check if we can list zero value tx as available coins
245246 # 1. create raw_tx
@@ -266,7 +267,7 @@ def run_test(self):
266267 if uTx ['txid' ] == zero_value_txid :
267268 found = True
268269 assert_equal (uTx ['amount' ], Decimal ('0' ))
269- assert ( found )
270+ assert found
270271
271272 # do some -walletbroadcast tests
272273 self .stop_nodes ()
@@ -343,7 +344,7 @@ def run_test(self):
343344 self .nodes [1 ].importaddress (address_to_import )
344345
345346 # 3. Validate that the imported address is watch-only on node1
346- assert ( self .nodes [1 ].getaddressinfo (address_to_import )["iswatchonly" ])
347+ assert self .nodes [1 ].getaddressinfo (address_to_import )["iswatchonly" ]
347348
348349 # 4. Check that the unspents after import are not spendable
349350 assert_array_result (self .nodes [1 ].listunspent (),
@@ -385,7 +386,7 @@ def run_test(self):
385386 addr = self .nodes [0 ].getnewaddress ()
386387 self .nodes [0 ].setlabel (addr , label )
387388 assert_equal (self .nodes [0 ].getaddressinfo (addr )['label' ], label )
388- assert ( label in self .nodes [0 ].listlabels () )
389+ assert label in self .nodes [0 ].listlabels ()
389390 self .nodes [0 ].rpc .ensure_ascii = True # restore to default
390391
391392 # maintenance tests
@@ -444,8 +445,8 @@ def run_test(self):
444445 # Without walletrejectlongchains, we will still generate a txid
445446 # The tx will be stored in the wallet but not accepted to the mempool
446447 extra_txid = self .nodes [0 ].sendtoaddress (sending_addr , Decimal ('0.0001' ))
447- assert ( extra_txid not in self .nodes [0 ].getrawmempool () )
448- assert ( extra_txid in [tx ["txid" ] for tx in self .nodes [0 ].listtransactions ()])
448+ assert extra_txid not in self .nodes [0 ].getrawmempool ()
449+ assert extra_txid in [tx ["txid" ] for tx in self .nodes [0 ].listtransactions ()]
449450 self .nodes [0 ].abandontransaction (extra_txid )
450451 total_txs = len (self .nodes [0 ].listtransactions ("*" , 99999 ))
451452
@@ -482,7 +483,7 @@ def run_test(self):
482483 self .nodes [0 ].generate (1 )
483484 destination = self .nodes [1 ].getnewaddress ()
484485 txid = self .nodes [0 ].sendtoaddress (destination , 0.123 )
485- tx = self .nodes [0 ].decoderawtransaction (self .nodes [0 ].getrawtransaction (txid ))
486+ tx = self .nodes [0 ].decoderawtransaction (self .nodes [0 ].gettransaction (txid )[ 'hex' ] )
486487 output_addresses = [vout ['scriptPubKey' ]['addresses' ][0 ] for vout in tx ["vout" ]]
487488 assert len (output_addresses ) > 1
488489 for address in output_addresses :
@@ -493,5 +494,6 @@ def run_test(self):
493494 self .nodes [0 ].setlabel (change , 'foobar' )
494495 assert_equal (self .nodes [0 ].getaddressinfo (change )['ischange' ], False )
495496
497+
496498if __name__ == '__main__' :
497499 WalletTest ().main ()
0 commit comments