mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Fix RPC failure testing (2 of 2)
Commit 9db8eecac1 improved the
assert_raises_jsonrpc() function for better testing of RPC failure
modes. This commit completes the job by removing remaining broken
try-except RPC testing from the individual test cases and replacing it
with calls to assert_raises_jsonrpc().
This commit is contained in:
@@ -90,12 +90,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx2.vout = [CTxOut(int(value-self.relayfee*COIN), CScript([b'a']))]
|
||||
tx2.rehash()
|
||||
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(ToHex(tx2))
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error["message"], NOT_FINAL_ERROR)
|
||||
else:
|
||||
assert(False)
|
||||
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2))
|
||||
|
||||
# Setting the version back down to 1 should disable the sequence lock,
|
||||
# so this should be accepted.
|
||||
@@ -190,14 +185,12 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx.vout.append(CTxOut(int(value-self.relayfee*tx_size*COIN/1000), CScript([b'a'])))
|
||||
rawtx = self.nodes[0].signrawtransaction(ToHex(tx))["hex"]
|
||||
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(rawtx)
|
||||
except JSONRPCException as exp:
|
||||
assert(not should_pass and using_sequence_locks)
|
||||
assert_equal(exp.error["message"], NOT_FINAL_ERROR)
|
||||
if (using_sequence_locks and not should_pass):
|
||||
# This transaction should be rejected
|
||||
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, rawtx)
|
||||
else:
|
||||
assert(should_pass or not using_sequence_locks)
|
||||
# Recalculate utxos if we successfully sent the transaction
|
||||
# This raw transaction should be accepted
|
||||
self.nodes[0].sendrawtransaction(rawtx)
|
||||
utxos = self.nodes[0].listunspent()
|
||||
|
||||
# Test that sequence locks on unconfirmed inputs must have nSequence
|
||||
@@ -239,14 +232,13 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee*COIN), CScript([b'a']))]
|
||||
tx.rehash()
|
||||
|
||||
try:
|
||||
node.sendrawtransaction(ToHex(tx))
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error["message"], NOT_FINAL_ERROR)
|
||||
assert(orig_tx.hash in node.getrawmempool())
|
||||
if (orig_tx.hash in node.getrawmempool()):
|
||||
# sendrawtransaction should fail if the tx is in the mempool
|
||||
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, node.sendrawtransaction, ToHex(tx))
|
||||
else:
|
||||
# orig_tx must not be in mempool
|
||||
assert(orig_tx.hash not in node.getrawmempool())
|
||||
# sendrawtransaction should succeed if the tx is not in the mempool
|
||||
node.sendrawtransaction(ToHex(tx))
|
||||
|
||||
return tx
|
||||
|
||||
test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=True)
|
||||
@@ -295,12 +287,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx5.vout[0].nValue += int(utxos[0]["amount"]*COIN)
|
||||
raw_tx5 = self.nodes[0].signrawtransaction(ToHex(tx5))["hex"]
|
||||
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(raw_tx5)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error["message"], NOT_FINAL_ERROR)
|
||||
else:
|
||||
assert(False)
|
||||
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, raw_tx5)
|
||||
|
||||
# Test mempool-BIP68 consistency after reorg
|
||||
#
|
||||
@@ -373,12 +360,7 @@ class BIP68Test(BitcoinTestFramework):
|
||||
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))]
|
||||
tx3.rehash()
|
||||
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(ToHex(tx3))
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error["message"], NOT_FINAL_ERROR)
|
||||
else:
|
||||
assert(False)
|
||||
assert_raises_jsonrpc(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3))
|
||||
|
||||
# make a block that violates bip68; ensure that the tip updates
|
||||
tip = int(self.nodes[0].getbestblockhash(), 16)
|
||||
|
||||
Reference in New Issue
Block a user