@@ -97,12 +97,7 @@ def test_disable_flag(self):
9797 tx2 .vout = [CTxOut (int (value - self .relayfee * COIN ), CScript ([b'a' ]))]
9898 tx2 .rehash ()
9999
100- try :
101- self .nodes [0 ].sendrawtransaction (ToHex (tx2 ))
102- except JSONRPCException as exp :
103- assert_equal (exp .error ["message" ], NOT_FINAL_ERROR )
104- else :
105- assert (False )
100+ assert_raises_jsonrpc (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , ToHex (tx2 ))
106101
107102 # Setting the version back down to 1 should disable the sequence lock,
108103 # so this should be accepted.
@@ -197,14 +192,12 @@ def test_sequence_lock_confirmed_inputs(self):
197192 tx .vout .append (CTxOut (int (value - self .relayfee * tx_size * COIN / 1000 ), CScript ([b'a' ])))
198193 rawtx = self .nodes [0 ].signrawtransaction (ToHex (tx ))["hex" ]
199194
200- try :
201- self .nodes [0 ].sendrawtransaction (rawtx )
202- except JSONRPCException as exp :
203- assert (not should_pass and using_sequence_locks )
204- assert_equal (exp .error ["message" ], NOT_FINAL_ERROR )
195+ if (using_sequence_locks and not should_pass ):
196+ # This transaction should be rejected
197+ assert_raises_jsonrpc (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , rawtx )
205198 else :
206- assert ( should_pass or not using_sequence_locks )
207- # Recalculate utxos if we successfully sent the transaction
199+ # This raw transaction should be accepted
200+ self . nodes [ 0 ]. sendrawtransaction ( rawtx )
208201 utxos = self .nodes [0 ].listunspent ()
209202
210203 # Test that sequence locks on unconfirmed inputs must have nSequence
@@ -246,14 +239,13 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
246239 tx .vout = [CTxOut (int (orig_tx .vout [0 ].nValue - relayfee * COIN ), CScript ([b'a' ]))]
247240 tx .rehash ()
248241
249- try :
250- node .sendrawtransaction (ToHex (tx ))
251- except JSONRPCException as exp :
252- assert_equal (exp .error ["message" ], NOT_FINAL_ERROR )
253- assert (orig_tx .hash in node .getrawmempool ())
242+ if (orig_tx .hash in node .getrawmempool ()):
243+ # sendrawtransaction should fail if the tx is in the mempool
244+ assert_raises_jsonrpc (- 26 , NOT_FINAL_ERROR , node .sendrawtransaction , ToHex (tx ))
254245 else :
255- # orig_tx must not be in mempool
256- assert (orig_tx .hash not in node .getrawmempool ())
246+ # sendrawtransaction should succeed if the tx is not in the mempool
247+ node .sendrawtransaction (ToHex (tx ))
248+
257249 return tx
258250
259251 test_nonzero_locks (tx2 , self .nodes [0 ], self .relayfee , use_height_lock = True )
@@ -302,12 +294,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
302294 tx5 .vout [0 ].nValue += int (utxos [0 ]["amount" ]* COIN )
303295 raw_tx5 = self .nodes [0 ].signrawtransaction (ToHex (tx5 ))["hex" ]
304296
305- try :
306- self .nodes [0 ].sendrawtransaction (raw_tx5 )
307- except JSONRPCException as exp :
308- assert_equal (exp .error ["message" ], NOT_FINAL_ERROR )
309- else :
310- assert (False )
297+ assert_raises_jsonrpc (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , raw_tx5 )
311298
312299 # Test mempool-BIP68 consistency after reorg
313300 #
@@ -380,12 +367,7 @@ def test_bip68_not_consensus(self):
380367 tx3 .vout = [CTxOut (int (tx2 .vout [0 ].nValue - self .relayfee * COIN ), CScript ([b'a' ]))]
381368 tx3 .rehash ()
382369
383- try :
384- self .nodes [0 ].sendrawtransaction (ToHex (tx3 ))
385- except JSONRPCException as exp :
386- assert_equal (exp .error ["message" ], NOT_FINAL_ERROR )
387- else :
388- assert (False )
370+ assert_raises_jsonrpc (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , ToHex (tx3 ))
389371
390372 # make a block that violates bip68; ensure that the tip updates
391373 tip = int (self .nodes [0 ].getbestblockhash (), 16 )
0 commit comments