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:
@@ -125,12 +125,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx1b.vout = [CTxOut(1*COIN, CScript([b'b']))]
|
||||
tx1b_hex = txToHex(tx1b)
|
||||
|
||||
try:
|
||||
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26) # insufficient fee
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception due to insufficient fee
|
||||
assert_raises_jsonrpc(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, True)
|
||||
|
||||
# Extra 0.1 BTC fee
|
||||
tx1b = CTransaction()
|
||||
@@ -172,12 +168,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
dbl_tx.vout = [CTxOut(initial_nValue - 30*COIN, CScript([1]))]
|
||||
dbl_tx_hex = txToHex(dbl_tx)
|
||||
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26) # insufficient fee
|
||||
else:
|
||||
assert(False) # transaction mistakenly accepted!
|
||||
# This will raise an exception due to insufficient fee
|
||||
assert_raises_jsonrpc(-26, "insufficient fee", self.nodes[0].sendrawtransaction, dbl_tx_hex, True)
|
||||
|
||||
# Accepted with sufficient fee
|
||||
dbl_tx = CTransaction()
|
||||
@@ -237,12 +229,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||
dbl_tx.vout = [CTxOut(initial_nValue - fee*n, CScript([1]))]
|
||||
dbl_tx_hex = txToHex(dbl_tx)
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26) # insufficient fee
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception due to insufficient fee
|
||||
assert_raises_jsonrpc(-26, "insufficient fee", self.nodes[0].sendrawtransaction, dbl_tx_hex, True)
|
||||
|
||||
# 1 BTC fee is enough
|
||||
dbl_tx = CTransaction()
|
||||
@@ -269,13 +257,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
|
||||
dbl_tx.vout = [CTxOut(initial_nValue - 2*fee*n, CScript([1]))]
|
||||
dbl_tx_hex = txToHex(dbl_tx)
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
assert_equal("too many potential replacements" in exp.error['message'], True)
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception
|
||||
assert_raises_jsonrpc(-26, "too many potential replacements", self.nodes[0].sendrawtransaction, dbl_tx_hex, True)
|
||||
|
||||
for tx in tree_txs:
|
||||
tx.rehash()
|
||||
@@ -298,12 +281,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*999000]))]
|
||||
tx1b_hex = txToHex(tx1b)
|
||||
|
||||
try:
|
||||
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26) # insufficient fee
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception due to insufficient fee
|
||||
assert_raises_jsonrpc(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, True)
|
||||
|
||||
def test_spends_of_conflicting_outputs(self):
|
||||
"""Replacements that spend conflicting tx outputs are rejected"""
|
||||
@@ -325,12 +304,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx2.vout = tx1a.vout
|
||||
tx2_hex = txToHex(tx2)
|
||||
|
||||
try:
|
||||
tx2_txid = self.nodes[0].sendrawtransaction(tx2_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception
|
||||
assert_raises_jsonrpc(-26, "bad-txns-spends-conflicting-tx", self.nodes[0].sendrawtransaction, tx2_hex, True)
|
||||
|
||||
# Spend tx1a's output to test the indirect case.
|
||||
tx1b = CTransaction()
|
||||
@@ -346,12 +321,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx2.vout = tx1a.vout
|
||||
tx2_hex = txToHex(tx2)
|
||||
|
||||
try:
|
||||
tx2_txid = self.nodes[0].sendrawtransaction(tx2_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception
|
||||
assert_raises_jsonrpc(-26, "bad-txns-spends-conflicting-tx", self.nodes[0].sendrawtransaction, tx2_hex, True)
|
||||
|
||||
def test_new_unconfirmed_inputs(self):
|
||||
"""Replacements that add new unconfirmed inputs are rejected"""
|
||||
@@ -369,12 +340,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx2.vout = tx1.vout
|
||||
tx2_hex = txToHex(tx2)
|
||||
|
||||
try:
|
||||
tx2_txid = self.nodes[0].sendrawtransaction(tx2_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception
|
||||
assert_raises_jsonrpc(-26, "replacement-adds-unconfirmed", self.nodes[0].sendrawtransaction, tx2_hex, True)
|
||||
|
||||
def test_too_many_replacements(self):
|
||||
"""Replacements that evict too many transactions are rejected"""
|
||||
@@ -419,13 +386,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
double_tx.vout = [CTxOut(double_spend_value, CScript([b'a']))]
|
||||
double_tx_hex = txToHex(double_tx)
|
||||
|
||||
try:
|
||||
self.nodes[0].sendrawtransaction(double_tx_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
assert_equal("too many potential replacements" in exp.error['message'], True)
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception
|
||||
assert_raises_jsonrpc(-26, "too many potential replacements", self.nodes[0].sendrawtransaction, double_tx_hex, True)
|
||||
|
||||
# If we remove an input, it should pass
|
||||
double_tx = CTransaction()
|
||||
@@ -451,13 +413,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
|
||||
tx1b_hex = txToHex(tx1b)
|
||||
|
||||
try:
|
||||
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
else:
|
||||
self.log.info(tx1b_txid)
|
||||
assert(False)
|
||||
# This will raise an exception
|
||||
assert_raises_jsonrpc(-26, "txn-mempool-conflict", self.nodes[0].sendrawtransaction, tx1b_hex, True)
|
||||
|
||||
tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
|
||||
|
||||
@@ -474,12 +431,8 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx2b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
|
||||
tx2b_hex = txToHex(tx2b)
|
||||
|
||||
try:
|
||||
tx2b_txid = self.nodes[0].sendrawtransaction(tx2b_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
else:
|
||||
assert(False)
|
||||
# This will raise an exception
|
||||
assert_raises_jsonrpc(-26, "txn-mempool-conflict", self.nodes[0].sendrawtransaction, tx2b_hex, True)
|
||||
|
||||
# Now create a new transaction that spends from tx1a and tx2a
|
||||
# opt-in on one of the inputs
|
||||
@@ -531,12 +484,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx1b_hex = txToHex(tx1b)
|
||||
|
||||
# Verify tx1b cannot replace tx1a.
|
||||
try:
|
||||
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
else:
|
||||
assert(False)
|
||||
assert_raises_jsonrpc(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, True)
|
||||
|
||||
# Use prioritisetransaction to set tx1a's fee to 0.
|
||||
self.nodes[0].prioritisetransaction(tx1a_txid, int(-0.1*COIN))
|
||||
@@ -563,12 +511,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
tx2b_hex = txToHex(tx2b)
|
||||
|
||||
# Verify tx2b cannot replace tx2a.
|
||||
try:
|
||||
tx2b_txid = self.nodes[0].sendrawtransaction(tx2b_hex, True)
|
||||
except JSONRPCException as exp:
|
||||
assert_equal(exp.error['code'], -26)
|
||||
else:
|
||||
assert(False)
|
||||
assert_raises_jsonrpc(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx2b_hex, True)
|
||||
|
||||
# Now prioritise tx2b to have a higher modified fee
|
||||
self.nodes[0].prioritisetransaction(tx2b.hash, int(0.1*COIN))
|
||||
|
||||
Reference in New Issue
Block a user