Skip to content

Commit a533834

Browse files
committed
[tests] Fix flake8 warnings in several wallet functional tests
This commit fixes flake8 warnings in the following functional tests: - wallet_listreceivedby.py - wallet_basic.py - wallet_txn_clone.py - wallet_listsinceblock.py - wallet_import_rescan.py - wallet_listtransactions.py - wallet_importprunedfunds.py - wallet_txn_doublspend.py
1 parent 3186ad4 commit a533834

8 files changed

+231
-211
lines changed

test/functional/wallet_basic.py

Lines changed: 88 additions & 77 deletions
Large diffs are not rendered by default.

test/functional/wallet_import_rescan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def do_import(self, timestamp):
4646
if self.call == Call.single:
4747
if self.data == Data.address:
4848
response = self.try_rpc(self.node.importaddress, self.address["address"], self.label,
49-
self.rescan == Rescan.yes)
49+
self.rescan == Rescan.yes)
5050
elif self.data == Data.pub:
5151
response = self.try_rpc(self.node.importpubkey, self.address["pubkey"], self.label,
52-
self.rescan == Rescan.yes)
52+
self.rescan == Rescan.yes)
5353
elif self.data == Data.priv:
5454
response = self.try_rpc(self.node.importprivkey, self.key, self.label, self.rescan == Rescan.yes)
5555
assert_equal(response, None)

test/functional/wallet_importprunedfunds.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
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 importprunedfunds and removeprunedfunds RPCs."""
6+
from decimal import Decimal
7+
68
from test_framework.test_framework import BitcoinTestFramework
7-
from test_framework.util import *
9+
from test_framework.util import (
10+
assert_equal,
11+
assert_raises_rpc_error,
12+
)
813

914
class ImportPrunedFundsTest(BitcoinTestFramework):
1015
def set_test_params(self):
@@ -24,18 +29,18 @@ def run_test(self):
2429
address2 = self.nodes[0].getnewaddress()
2530
# privkey
2631
address3 = self.nodes[0].getnewaddress()
27-
address3_privkey = self.nodes[0].dumpprivkey(address3) # Using privkey
32+
address3_privkey = self.nodes[0].dumpprivkey(address3) # Using privkey
2833

29-
#Check only one address
34+
# Check only one address
3035
address_info = self.nodes[0].getaddressinfo(address1)
3136
assert_equal(address_info['ismine'], True)
3237

3338
self.sync_all()
3439

35-
#Node 1 sync test
36-
assert_equal(self.nodes[1].getblockcount(),101)
40+
# Node 1 sync test
41+
assert_equal(self.nodes[1].getblockcount(), 101)
3742

38-
#Address Test - before import
43+
# Address Test - before import
3944
address_info = self.nodes[1].getaddressinfo(address1)
4045
assert_equal(address_info['iswatchonly'], False)
4146
assert_equal(address_info['ismine'], False)
@@ -48,7 +53,7 @@ def run_test(self):
4853
assert_equal(address_info['iswatchonly'], False)
4954
assert_equal(address_info['ismine'], False)
5055

51-
#Send funds to self
56+
# Send funds to self
5257
txnid1 = self.nodes[0].sendtoaddress(address1, 0.1)
5358
self.nodes[0].generate(1)
5459
rawtxn1 = self.nodes[0].gettransaction(txnid1)['hex']
@@ -66,27 +71,27 @@ def run_test(self):
6671

6772
self.sync_all()
6873

69-
#Import with no affiliated address
74+
# Import with no affiliated address
7075
assert_raises_rpc_error(-5, "No addresses", self.nodes[1].importprunedfunds, rawtxn1, proof1)
7176

7277
balance1 = self.nodes[1].getbalance("", 0, True)
7378
assert_equal(balance1, Decimal(0))
7479

75-
#Import with affiliated address with no rescan
80+
# Import with affiliated address with no rescan
7681
self.nodes[1].importaddress(address2, "add2", False)
7782
self.nodes[1].importprunedfunds(rawtxn2, proof2)
7883
balance2 = self.nodes[1].getbalance("add2", 0, True)
7984
assert_equal(balance2, Decimal('0.05'))
8085

81-
#Import with private key with no rescan
86+
# Import with private key with no rescan
8287
self.nodes[1].importprivkey(privkey=address3_privkey, label="add3", rescan=False)
8388
self.nodes[1].importprunedfunds(rawtxn3, proof3)
8489
balance3 = self.nodes[1].getbalance("add3", 0, False)
8590
assert_equal(balance3, Decimal('0.025'))
8691
balance3 = self.nodes[1].getbalance("*", 0, True)
8792
assert_equal(balance3, Decimal('0.075'))
8893

89-
#Addresses Test - after import
94+
# Addresses Test - after import
9095
address_info = self.nodes[1].getaddressinfo(address1)
9196
assert_equal(address_info['iswatchonly'], False)
9297
assert_equal(address_info['ismine'], False)
@@ -97,7 +102,7 @@ def run_test(self):
97102
assert_equal(address_info['iswatchonly'], False)
98103
assert_equal(address_info['ismine'], True)
99104

100-
#Remove transactions
105+
# Remove transactions
101106
assert_raises_rpc_error(-8, "Transaction does not exist in wallet.", self.nodes[1].removeprunedfunds, txnid1)
102107

103108
balance1 = self.nodes[1].getbalance("*", 0, True)

test/functional/wallet_listreceivedby.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,37 @@ def run_test(self):
5151
{"address": empty_addr},
5252
{"address": empty_addr, "label": "", "amount": 0, "confirmations": 0, "txids": []})
5353

54-
#Test Address filtering
55-
#Only on addr
56-
expected = {"address":addr, "label":"", "amount":Decimal("0.1"), "confirmations":10, "txids":[txid,]}
54+
# Test Address filtering
55+
# Only on addr
56+
expected = {"address": addr, "label": "", "amount": Decimal("0.1"), "confirmations": 10, "txids": [txid, ]}
5757
res = self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True, address_filter=addr)
58-
assert_array_result(res, {"address":addr}, expected)
58+
assert_array_result(res, {"address": addr}, expected)
5959
assert_equal(len(res), 1)
60-
#Error on invalid address
60+
# Error on invalid address
6161
assert_raises_rpc_error(-4, "address_filter parameter was invalid", self.nodes[1].listreceivedbyaddress, minconf=0, include_empty=True, include_watchonly=True, address_filter="bamboozling")
62-
#Another address receive money
62+
# Another address receive money
6363
res = self.nodes[1].listreceivedbyaddress(0, True, True)
64-
assert_equal(len(res), 2) #Right now 2 entries
64+
assert_equal(len(res), 2) # Right now 2 entries
6565
other_addr = self.nodes[1].getnewaddress()
6666
txid2 = self.nodes[0].sendtoaddress(other_addr, 0.1)
6767
self.nodes[0].generate(1)
6868
self.sync_all()
69-
#Same test as above should still pass
70-
expected = {"address":addr, "label":"", "amount":Decimal("0.1"), "confirmations":11, "txids":[txid,]}
69+
# Same test as above should still pass
70+
expected = {"address": addr, "label": "", "amount": Decimal("0.1"), "confirmations": 11, "txids": [txid, ]}
7171
res = self.nodes[1].listreceivedbyaddress(0, True, True, addr)
72-
assert_array_result(res, {"address":addr}, expected)
72+
assert_array_result(res, {"address": addr}, expected)
7373
assert_equal(len(res), 1)
74-
#Same test as above but with other_addr should still pass
75-
expected = {"address":other_addr, "label":"", "amount":Decimal("0.1"), "confirmations":1, "txids":[txid2,]}
74+
# Same test as above but with other_addr should still pass
75+
expected = {"address": other_addr, "label": "", "amount": Decimal("0.1"), "confirmations": 1, "txids": [txid2, ]}
7676
res = self.nodes[1].listreceivedbyaddress(0, True, True, other_addr)
77-
assert_array_result(res, {"address":other_addr}, expected)
77+
assert_array_result(res, {"address": other_addr}, expected)
7878
assert_equal(len(res), 1)
79-
#Should be two entries though without filter
79+
# Should be two entries though without filter
8080
res = self.nodes[1].listreceivedbyaddress(0, True, True)
81-
assert_equal(len(res), 3) #Became 3 entries
81+
assert_equal(len(res), 3) # Became 3 entries
8282

83-
#Not on random addr
84-
other_addr = self.nodes[0].getnewaddress() # note on node[0]! just a random addr
83+
# Not on random addr
84+
other_addr = self.nodes[0].getnewaddress() # note on node[0]! just a random addr
8585
res = self.nodes[1].listreceivedbyaddress(0, True, True, other_addr)
8686
assert_equal(len(res), 0)
8787

@@ -112,8 +112,8 @@ def run_test(self):
112112
self.log.info("listreceivedbylabel + getreceivedbylabel Test")
113113

114114
# set pre-state
115-
addrArr = self.nodes[1].getnewaddress()
116-
label = self.nodes[1].getaccount(addrArr)
115+
address = self.nodes[1].getnewaddress()
116+
label = self.nodes[1].getaccount(address)
117117
received_by_label_json = [r for r in self.nodes[1].listreceivedbylabel() if r["label"] == label][0]
118118
balance_by_label = self.nodes[1].getreceivedbylabel(label)
119119

test/functional/wallet_listsinceblock.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,26 @@ def test_double_spend(self):
150150

151151
# send from nodes[1] using utxo to nodes[0]
152152
change = '%.8f' % (float(utxo['amount']) - 1.0003)
153-
recipientDict = {
153+
recipient_dict = {
154154
self.nodes[0].getnewaddress(): 1,
155155
self.nodes[1].getnewaddress(): change,
156156
}
157-
utxoDicts = [{
157+
utxo_dicts = [{
158158
'txid': utxo['txid'],
159159
'vout': utxo['vout'],
160160
}]
161161
txid1 = self.nodes[1].sendrawtransaction(
162162
self.nodes[1].signrawtransactionwithwallet(
163-
self.nodes[1].createrawtransaction(utxoDicts, recipientDict))['hex'])
163+
self.nodes[1].createrawtransaction(utxo_dicts, recipient_dict))['hex'])
164164

165165
# send from nodes[2] using utxo to nodes[3]
166-
recipientDict2 = {
166+
recipient_dict2 = {
167167
self.nodes[3].getnewaddress(): 1,
168168
self.nodes[2].getnewaddress(): change,
169169
}
170170
self.nodes[2].sendrawtransaction(
171171
self.nodes[2].signrawtransactionwithwallet(
172-
self.nodes[2].createrawtransaction(utxoDicts, recipientDict2))['hex'])
172+
self.nodes[2].createrawtransaction(utxo_dicts, recipient_dict2))['hex'])
173173

174174
# generate on both sides
175175
lastblockhash = self.nodes[1].generate(3)[2]
@@ -225,16 +225,16 @@ def test_double_send(self):
225225
utxos = self.nodes[2].listunspent()
226226
utxo = utxos[0]
227227
change = '%.8f' % (float(utxo['amount']) - 1.0003)
228-
recipientDict = {
228+
recipient_dict = {
229229
self.nodes[0].getnewaddress(): 1,
230230
self.nodes[2].getnewaddress(): change,
231231
}
232-
utxoDicts = [{
232+
utxo_dicts = [{
233233
'txid': utxo['txid'],
234234
'vout': utxo['vout'],
235235
}]
236236
signedtxres = self.nodes[2].signrawtransactionwithwallet(
237-
self.nodes[2].createrawtransaction(utxoDicts, recipientDict))
237+
self.nodes[2].createrawtransaction(utxo_dicts, recipient_dict))
238238
assert signedtxres['complete']
239239

240240
signedtx = signedtxres['hex']

0 commit comments

Comments
 (0)