Skip to content

Commit 47ba8cf

Browse files
committed
scripted-diff: rename assert_raises_jsonrpc to assert_raises_rpc error
-BEGIN VERIFY SCRIPT- sed -i 's/assert_raises_jsonrpc/assert_raises_rpc_error/g' test/functional/*py test/functional/test_framework/*py -END VERIFY SCRIPT-
1 parent 677d893 commit 47ba8cf

35 files changed

+117
-117
lines changed

test/functional/bip68-sequence.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_disable_flag(self):
8383
tx2.vout = [CTxOut(int(value-self.relayfee*COIN), CScript([b'a']))]
8484
tx2.rehash()
8585

86-
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2))
86+
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2))
8787

8888
# Setting the version back down to 1 should disable the sequence lock,
8989
# so this should be accepted.
@@ -180,7 +180,7 @@ def test_sequence_lock_confirmed_inputs(self):
180180

181181
if (using_sequence_locks and not should_pass):
182182
# This transaction should be rejected
183-
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, rawtx)
183+
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, rawtx)
184184
else:
185185
# This raw transaction should be accepted
186186
self.nodes[0].sendrawtransaction(rawtx)
@@ -227,7 +227,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
227227

228228
if (orig_tx.hash in node.getrawmempool()):
229229
# sendrawtransaction should fail if the tx is in the mempool
230-
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, node.sendrawtransaction, ToHex(tx))
230+
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, node.sendrawtransaction, ToHex(tx))
231231
else:
232232
# sendrawtransaction should succeed if the tx is not in the mempool
233233
node.sendrawtransaction(ToHex(tx))
@@ -280,7 +280,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
280280
tx5.vout[0].nValue += int(utxos[0]["amount"]*COIN)
281281
raw_tx5 = self.nodes[0].signrawtransaction(ToHex(tx5))["hex"]
282282

283-
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, raw_tx5)
283+
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, raw_tx5)
284284

285285
# Test mempool-BIP68 consistency after reorg
286286
#
@@ -353,7 +353,7 @@ def test_bip68_not_consensus(self):
353353
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))]
354354
tx3.rehash()
355355

356-
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3))
356+
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3))
357357

358358
# make a block that violates bip68; ensure that the tip updates
359359
tip = int(self.nodes[0].getbestblockhash(), 16)

test/functional/blockchain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from test_framework.util import (
2626
assert_equal,
2727
assert_raises,
28-
assert_raises_jsonrpc,
28+
assert_raises_rpc_error,
2929
assert_is_hex_string,
3030
assert_is_hash_string,
3131
)
@@ -101,7 +101,7 @@ def _test_getchaintxstats(self):
101101
assert('window_interval' not in chaintxstats)
102102
assert('txrate' not in chaintxstats)
103103

104-
assert_raises_jsonrpc(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, 201)
104+
assert_raises_rpc_error(-8, "Invalid block count: should be between 0 and the block's height - 1", self.nodes[0].getchaintxstats, 201)
105105

106106
def _test_gettxoutsetinfo(self):
107107
node = self.nodes[0]
@@ -147,7 +147,7 @@ def _test_gettxoutsetinfo(self):
147147
def _test_getblockheader(self):
148148
node = self.nodes[0]
149149

150-
assert_raises_jsonrpc(-5, "Block not found",
150+
assert_raises_rpc_error(-5, "Block not found",
151151
node.getblockheader, "nonsense")
152152

153153
besthash = node.getbestblockhash()

test/functional/bumpfee.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_segwit_bumpfee_succeeds(rbf_node, dest_address):
133133
def test_nonrbf_bumpfee_fails(peer_node, dest_address):
134134
# cannot replace a non RBF transaction (from node which did not enable RBF)
135135
not_rbfid = peer_node.sendtoaddress(dest_address, Decimal("0.00090000"))
136-
assert_raises_jsonrpc(-4, "not BIP 125 replaceable", peer_node.bumpfee, not_rbfid)
136+
assert_raises_rpc_error(-4, "not BIP 125 replaceable", peer_node.bumpfee, not_rbfid)
137137

138138

139139
def test_notmine_bumpfee_fails(rbf_node, peer_node, dest_address):
@@ -153,7 +153,7 @@ def test_notmine_bumpfee_fails(rbf_node, peer_node, dest_address):
153153
signedtx = rbf_node.signrawtransaction(rawtx)
154154
signedtx = peer_node.signrawtransaction(signedtx["hex"])
155155
rbfid = rbf_node.sendrawtransaction(signedtx["hex"])
156-
assert_raises_jsonrpc(-4, "Transaction contains inputs that don't belong to this wallet",
156+
assert_raises_rpc_error(-4, "Transaction contains inputs that don't belong to this wallet",
157157
rbf_node.bumpfee, rbfid)
158158

159159

@@ -164,7 +164,7 @@ def test_bumpfee_with_descendant_fails(rbf_node, rbf_node_address, dest_address)
164164
tx = rbf_node.createrawtransaction([{"txid": parent_id, "vout": 0}], {dest_address: 0.00020000})
165165
tx = rbf_node.signrawtransaction(tx)
166166
rbf_node.sendrawtransaction(tx["hex"])
167-
assert_raises_jsonrpc(-8, "Transaction has descendants in the wallet", rbf_node.bumpfee, parent_id)
167+
assert_raises_rpc_error(-8, "Transaction has descendants in the wallet", rbf_node.bumpfee, parent_id)
168168

169169

170170
def test_small_output_fails(rbf_node, dest_address):
@@ -173,7 +173,7 @@ def test_small_output_fails(rbf_node, dest_address):
173173
rbf_node.bumpfee(rbfid, {"totalFee": 50000})
174174

175175
rbfid = spend_one_input(rbf_node, dest_address)
176-
assert_raises_jsonrpc(-4, "Change output is too small", rbf_node.bumpfee, rbfid, {"totalFee": 50001})
176+
assert_raises_rpc_error(-4, "Change output is too small", rbf_node.bumpfee, rbfid, {"totalFee": 50001})
177177

178178

179179
def test_dust_to_fee(rbf_node, dest_address):
@@ -205,15 +205,15 @@ def test_rebumping(rbf_node, dest_address):
205205
# check that re-bumping the original tx fails, but bumping the bumper succeeds
206206
rbfid = spend_one_input(rbf_node, dest_address)
207207
bumped = rbf_node.bumpfee(rbfid, {"totalFee": 2000})
208-
assert_raises_jsonrpc(-4, "already bumped", rbf_node.bumpfee, rbfid, {"totalFee": 3000})
208+
assert_raises_rpc_error(-4, "already bumped", rbf_node.bumpfee, rbfid, {"totalFee": 3000})
209209
rbf_node.bumpfee(bumped["txid"], {"totalFee": 3000})
210210

211211

212212
def test_rebumping_not_replaceable(rbf_node, dest_address):
213213
# check that re-bumping a non-replaceable bump tx fails
214214
rbfid = spend_one_input(rbf_node, dest_address)
215215
bumped = rbf_node.bumpfee(rbfid, {"totalFee": 10000, "replaceable": False})
216-
assert_raises_jsonrpc(-4, "Transaction is not BIP 125 replaceable", rbf_node.bumpfee, bumped["txid"],
216+
assert_raises_rpc_error(-4, "Transaction is not BIP 125 replaceable", rbf_node.bumpfee, bumped["txid"],
217217
{"totalFee": 20000})
218218

219219

@@ -264,7 +264,7 @@ def test_bumpfee_metadata(rbf_node, dest_address):
264264
def test_locked_wallet_fails(rbf_node, dest_address):
265265
rbfid = spend_one_input(rbf_node, dest_address)
266266
rbf_node.walletlock()
267-
assert_raises_jsonrpc(-13, "Please enter the wallet passphrase with walletpassphrase first.",
267+
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first.",
268268
rbf_node.bumpfee, rbfid)
269269

270270

test/functional/deprecated_rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test deprecation of RPC calls."""
66
from test_framework.test_framework import BitcoinTestFramework
7-
from test_framework.util import assert_raises_jsonrpc
7+
from test_framework.util import assert_raises_rpc_error
88

99
class DeprecatedRpcTest(BitcoinTestFramework):
1010
def set_test_params(self):
@@ -14,7 +14,7 @@ def set_test_params(self):
1414

1515
def run_test(self):
1616
self.log.info("estimatefee: Shows deprecated message")
17-
assert_raises_jsonrpc(-32, 'estimatefee is deprecated', self.nodes[0].estimatefee, 1)
17+
assert_raises_rpc_error(-32, 'estimatefee is deprecated', self.nodes[0].estimatefee, 1)
1818

1919
self.log.info("Using -deprecatedrpc=estimatefee bypasses the error")
2020
self.nodes[1].estimatefee(1)

test/functional/disablewallet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def set_test_params(self):
1919

2020
def run_test (self):
2121
# Make sure wallet is really disabled
22-
assert_raises_jsonrpc(-32601, 'Method not found', self.nodes[0].getwalletinfo)
22+
assert_raises_rpc_error(-32601, 'Method not found', self.nodes[0].getwalletinfo)
2323
x = self.nodes[0].validateaddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
2424
assert(x['isvalid'] == False)
2525
x = self.nodes[0].validateaddress('mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')
@@ -28,7 +28,7 @@ def run_test (self):
2828
# Checking mining to an address without a wallet. Generating to a valid address should succeed
2929
# but generating to an invalid address will fail.
3030
self.nodes[0].generatetoaddress(1, 'mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')
31-
assert_raises_jsonrpc(-5, "Invalid address", self.nodes[0].generatetoaddress, 1, '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
31+
assert_raises_rpc_error(-5, "Invalid address", self.nodes[0].generatetoaddress, 1, '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
3232

3333
if __name__ == '__main__':
3434
DisableWalletTest ().main ()

test/functional/disconnect_ban.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from test_framework.test_framework import BitcoinTestFramework
99
from test_framework.util import (
1010
assert_equal,
11-
assert_raises_jsonrpc,
11+
assert_raises_rpc_error,
1212
connect_nodes_bi,
1313
wait_until,
1414
)
@@ -34,14 +34,14 @@ def run_test(self):
3434

3535
self.log.info("setban: fail to ban an already banned subnet")
3636
assert_equal(len(self.nodes[1].listbanned()), 1)
37-
assert_raises_jsonrpc(-23, "IP/Subnet already banned", self.nodes[1].setban, "127.0.0.1", "add")
37+
assert_raises_rpc_error(-23, "IP/Subnet already banned", self.nodes[1].setban, "127.0.0.1", "add")
3838

3939
self.log.info("setban: fail to ban an invalid subnet")
40-
assert_raises_jsonrpc(-30, "Error: Invalid IP/Subnet", self.nodes[1].setban, "127.0.0.1/42", "add")
40+
assert_raises_rpc_error(-30, "Error: Invalid IP/Subnet", self.nodes[1].setban, "127.0.0.1/42", "add")
4141
assert_equal(len(self.nodes[1].listbanned()), 1) # still only one banned ip because 127.0.0.1 is within the range of 127.0.0.0/24
4242

4343
self.log.info("setban remove: fail to unban a non-banned subnet")
44-
assert_raises_jsonrpc(-30, "Error: Unban failed", self.nodes[1].setban, "127.0.0.1", "remove")
44+
assert_raises_rpc_error(-30, "Error: Unban failed", self.nodes[1].setban, "127.0.0.1", "remove")
4545
assert_equal(len(self.nodes[1].listbanned()), 1)
4646

4747
self.log.info("setban remove: successfully unban subnet")
@@ -81,10 +81,10 @@ def run_test(self):
8181
self.log.info("disconnectnode: fail to disconnect when calling with address and nodeid")
8282
address1 = self.nodes[0].getpeerinfo()[0]['addr']
8383
node1 = self.nodes[0].getpeerinfo()[0]['addr']
84-
assert_raises_jsonrpc(-32602, "Only one of address and nodeid should be provided.", self.nodes[0].disconnectnode, address=address1, nodeid=node1)
84+
assert_raises_rpc_error(-32602, "Only one of address and nodeid should be provided.", self.nodes[0].disconnectnode, address=address1, nodeid=node1)
8585

8686
self.log.info("disconnectnode: fail to disconnect when calling with junk address")
87-
assert_raises_jsonrpc(-29, "Node not found in connected nodes", self.nodes[0].disconnectnode, address="221B Baker Street")
87+
assert_raises_rpc_error(-29, "Node not found in connected nodes", self.nodes[0].disconnectnode, address="221B Baker Street")
8888

8989
self.log.info("disconnectnode: successfully disconnect node by address")
9090
address1 = self.nodes[0].getpeerinfo()[0]['addr']

test/functional/fundrawtransaction.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def run_test(self):
179179
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
180180
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
181181

182-
assert_raises_jsonrpc(-3, "Unexpected key foo", self.nodes[2].fundrawtransaction, rawtx, {'foo':'bar'})
182+
assert_raises_rpc_error(-3, "Unexpected key foo", self.nodes[2].fundrawtransaction, rawtx, {'foo':'bar'})
183183

184184
############################################################
185185
# test a fundrawtransaction with an invalid change address #
@@ -192,7 +192,7 @@ def run_test(self):
192192
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
193193
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
194194

195-
assert_raises_jsonrpc(-5, "changeAddress must be a valid bitcoin address", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':'foobar'})
195+
assert_raises_rpc_error(-5, "changeAddress must be a valid bitcoin address", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':'foobar'})
196196

197197
############################################################
198198
# test a fundrawtransaction with a provided change address #
@@ -206,7 +206,7 @@ def run_test(self):
206206
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
207207

208208
change = self.nodes[2].getnewaddress()
209-
assert_raises_jsonrpc(-8, "changePosition out of bounds", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':change, 'changePosition':2})
209+
assert_raises_rpc_error(-8, "changePosition out of bounds", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':change, 'changePosition':2})
210210
rawtxfund = self.nodes[2].fundrawtransaction(rawtx, {'changeAddress': change, 'changePosition': 0})
211211
dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
212212
out = dec_tx['vout'][0]
@@ -314,7 +314,7 @@ def run_test(self):
314314
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
315315
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
316316

317-
assert_raises_jsonrpc(-4, "Insufficient funds", self.nodes[2].fundrawtransaction, rawtx)
317+
assert_raises_rpc_error(-4, "Insufficient funds", self.nodes[2].fundrawtransaction, rawtx)
318318

319319
############################################################
320320
#compare fee of a standard pubkeyhash transaction
@@ -469,14 +469,14 @@ def run_test(self):
469469
rawtx = self.nodes[1].createrawtransaction(inputs, outputs)
470470
# fund a transaction that requires a new key for the change output
471471
# creating the key must be impossible because the wallet is locked
472-
assert_raises_jsonrpc(-4, "Keypool ran out, please call keypoolrefill first", self.nodes[1].fundrawtransaction, rawtx)
472+
assert_raises_rpc_error(-4, "Keypool ran out, please call keypoolrefill first", self.nodes[1].fundrawtransaction, rawtx)
473473

474474
#refill the keypool
475475
self.nodes[1].walletpassphrase("test", 100)
476476
self.nodes[1].keypoolrefill(8) #need to refill the keypool to get an internal change address
477477
self.nodes[1].walletlock()
478478

479-
assert_raises_jsonrpc(-13, "walletpassphrase", self.nodes[1].sendtoaddress, self.nodes[0].getnewaddress(), 1.2)
479+
assert_raises_rpc_error(-13, "walletpassphrase", self.nodes[1].sendtoaddress, self.nodes[0].getnewaddress(), 1.2)
480480

481481
oldBalance = self.nodes[0].getbalance()
482482

test/functional/import-rescan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121

2222
from test_framework.test_framework import BitcoinTestFramework
23-
from test_framework.util import (assert_raises_jsonrpc, connect_nodes, sync_blocks, assert_equal, set_node_times)
23+
from test_framework.util import (assert_raises_rpc_error, connect_nodes, sync_blocks, assert_equal, set_node_times)
2424

2525
import collections
2626
import enum
@@ -36,7 +36,7 @@ class Variant(collections.namedtuple("Variant", "call data rescan prune")):
3636

3737
def try_rpc(self, func, *args, **kwargs):
3838
if self.expect_disabled:
39-
assert_raises_jsonrpc(-4, "Rescan is disabled in pruned mode", func, *args, **kwargs)
39+
assert_raises_rpc_error(-4, "Rescan is disabled in pruned mode", func, *args, **kwargs)
4040
else:
4141
return func(*args, **kwargs)
4242

test/functional/importmulti.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,11 @@ def run_test (self):
423423

424424
# Bad or missing timestamps
425425
self.log.info("Should throw on invalid or missing timestamp values")
426-
assert_raises_jsonrpc(-3, 'Missing required timestamp field for key',
426+
assert_raises_rpc_error(-3, 'Missing required timestamp field for key',
427427
self.nodes[1].importmulti, [{
428428
"scriptPubKey": address['scriptPubKey'],
429429
}])
430-
assert_raises_jsonrpc(-3, 'Expected number or "now" timestamp value for key. got type string',
430+
assert_raises_rpc_error(-3, 'Expected number or "now" timestamp value for key. got type string',
431431
self.nodes[1].importmulti, [{
432432
"scriptPubKey": address['scriptPubKey'],
433433
"timestamp": "",

test/functional/importprunedfunds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def run_test(self):
6666
self.sync_all()
6767

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

7171
balance1 = self.nodes[1].getbalance("", 0, True)
7272
assert_equal(balance1, Decimal(0))
@@ -97,7 +97,7 @@ def run_test(self):
9797
assert_equal(address_info['ismine'], True)
9898

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

102102
balance1 = self.nodes[1].getbalance("*", 0, True)
103103
assert_equal(balance1, Decimal('0.075'))

0 commit comments

Comments
 (0)