Skip to content

Commit c3f2033

Browse files
committed
test: use common assert_signing_completed_successfully helper
1 parent 647d95a commit c3f2033

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

test/functional/rpc_signrawtransactionwithkey.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def send_to_address(self, addr, amount):
5656
txid = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransactionwithkey(rawtx, [self.nodes[0].get_deterministic_priv_key().key])["hex"], 0)
5757
return txid
5858

59+
def assert_signing_completed_successfully(self, signed_tx):
60+
assert 'errors' not in signed_tx
61+
assert 'complete' in signed_tx
62+
assert_equal(signed_tx['complete'], True)
63+
5964
def successful_signing_test(self):
6065
"""Create and sign a valid raw transaction with one input.
6166
@@ -68,11 +73,7 @@ def successful_signing_test(self):
6873
rawTx = self.nodes[0].createrawtransaction(INPUTS, OUTPUTS)
6974
rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, INPUTS)
7075

71-
# 1) The transaction has a complete set of signatures
72-
assert rawTxSigned['complete']
73-
74-
# 2) No script verification error occurred
75-
assert 'errors' not in rawTxSigned
76+
self.assert_signing_completed_successfully(rawTxSigned)
7677

7778
def witness_script_test(self):
7879
self.log.info("Test signing transaction to P2SH-P2WSH addresses without wallet")
@@ -93,9 +94,7 @@ def witness_script_test(self):
9394
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
9495
spending_tx = self.nodes[0].createrawtransaction([unspent_output], {getnewdestination()[2]: Decimal("49.998")})
9596
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [unspent_output])
96-
# Check the signing completed successfully
97-
assert 'complete' in spending_tx_signed
98-
assert_equal(spending_tx_signed['complete'], True)
97+
self.assert_signing_completed_successfully(spending_tx_signed)
9998

10099
# Now test with P2PKH and P2PK scripts as the witnessScript
101100
for tx_type in ['P2PKH', 'P2PK']: # these tests are order-independent
@@ -118,9 +117,7 @@ def verify_txn_with_witness_script(self, tx_type):
118117
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
119118
spending_tx = self.nodes[0].createrawtransaction([{'txid': txid, 'vout': vout}], {getnewdestination()[2]: Decimal("9.999")})
120119
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [{'txid': txid, 'vout': vout, 'scriptPubKey': script_pub_key, 'redeemScript': redeem_script, 'witnessScript': witness_script, 'amount': 10}])
121-
# Check the signing completed successfully
122-
assert 'complete' in spending_tx_signed
123-
assert_equal(spending_tx_signed['complete'], True)
120+
self.assert_signing_completed_successfully(spending_tx_signed)
124121
self.nodes[0].sendrawtransaction(spending_tx_signed['hex'])
125122

126123
def invalid_sighashtype_test(self):

0 commit comments

Comments
 (0)