Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_signrawtransaction.py
Show All 9 Lines | |||||
RPC_WALLET_NOT_SPECIFIED = "Wallet file not specified (must request wallet " + \ | RPC_WALLET_NOT_SPECIFIED = "Wallet file not specified (must request wallet " + \ | ||||
"RPC through /wallet/<filename> uri-path)." | "RPC through /wallet/<filename> uri-path)." | ||||
class SignRawTransactionsTest(BitcoinTestFramework): | class SignRawTransactionsTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-deprecatedrpc=signrawtransaction"], | self.extra_args = [[], ["-wallet=w1", "-wallet=w2"]] | ||||
["-deprecatedrpc=signrawtransaction", "-wallet=w1", | |||||
"-wallet=w2"]] | |||||
def successful_signing_test(self): | def successful_signing_test(self): | ||||
"""Creates and signs a valid raw transaction with one input. | """Creates and signs a valid raw transaction with one input. | ||||
Expected results: | Expected results: | ||||
1) The transaction has a complete set of signatures | 1) The transaction has a complete set of signatures | ||||
2) No script verification error occurred""" | 2) No script verification error occurred""" | ||||
Show All 17 Lines | def successful_signing_test(self): | ||||
rawTx, privKeys, inputs) | rawTx, privKeys, inputs) | ||||
# 1) The transaction has a complete set of signatures | # 1) The transaction has a complete set of signatures | ||||
assert rawTxSigned['complete'] | assert rawTxSigned['complete'] | ||||
# 2) No script verification error occurred | # 2) No script verification error occurred | ||||
assert 'errors' not in rawTxSigned | assert 'errors' not in rawTxSigned | ||||
# Perform the same test on signrawtransaction | |||||
rawTxSigned2 = self.nodes[0].signrawtransaction( | |||||
rawTx, inputs, privKeys) | |||||
assert_equal(rawTxSigned, rawTxSigned2) | |||||
def script_verification_error_test(self): | def script_verification_error_test(self): | ||||
"""Creates and signs a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script. | """Creates and signs a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script. | ||||
Expected results: | Expected results: | ||||
3) The transaction has no complete set of signatures | 3) The transaction has no complete set of signatures | ||||
4) Two script verification errors occurred | 4) Two script verification errors occurred | ||||
5) Script verification errors have certain properties ("txid", "vout", "scriptSig", "sequence", "error") | 5) Script verification errors have certain properties ("txid", "vout", "scriptSig", "sequence", "error") | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | def script_verification_error_test(self): | ||||
# 6) The verification errors refer to the invalid (vin 1) and missing | # 6) The verification errors refer to the invalid (vin 1) and missing | ||||
# input (vin 2) | # input (vin 2) | ||||
assert_equal(rawTxSigned['errors'][0]['txid'], inputs[1]['txid']) | assert_equal(rawTxSigned['errors'][0]['txid'], inputs[1]['txid']) | ||||
assert_equal(rawTxSigned['errors'][0]['vout'], inputs[1]['vout']) | assert_equal(rawTxSigned['errors'][0]['vout'], inputs[1]['vout']) | ||||
assert_equal(rawTxSigned['errors'][1]['txid'], inputs[2]['txid']) | assert_equal(rawTxSigned['errors'][1]['txid'], inputs[2]['txid']) | ||||
assert_equal(rawTxSigned['errors'][1]['vout'], inputs[2]['vout']) | assert_equal(rawTxSigned['errors'][1]['vout'], inputs[2]['vout']) | ||||
# Perform same test with signrawtransaction | |||||
rawTxSigned2 = self.nodes[0].signrawtransaction( | |||||
rawTx, scripts, privKeys) | |||||
assert_equal(rawTxSigned, rawTxSigned2) | |||||
def test_sighashes(self): | def test_sighashes(self): | ||||
"""Creates and signs a raw transaction with various sighashes. | """Creates and signs a raw transaction with various sighashes. | ||||
Expected result: | Expected result: | ||||
1) The transaction is complete if the sighash is valid and has FORKID. | 1) The transaction is complete if the sighash is valid and has FORKID. | ||||
2) The RPC throws an error if the sighash does not contain FORKID. | 2) The RPC throws an error if the sighash does not contain FORKID. | ||||
3) The RPC throws an error if the sighash is invalid.""" | 3) The RPC throws an error if the sighash is invalid.""" | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | def multiwallet_signing_test(self): | ||||
}] | }] | ||||
rawTx_w1 = w1.createrawtransaction(inputs, outputs) | rawTx_w1 = w1.createrawtransaction(inputs, outputs) | ||||
rawTxSigned_w1 = w1.signrawtransactionwithwallet(rawTx_w1) | rawTxSigned_w1 = w1.signrawtransactionwithwallet(rawTx_w1) | ||||
assert rawTxSigned_w1['complete'] | assert rawTxSigned_w1['complete'] | ||||
assert 'errors' not in rawTxSigned_w1 | assert 'errors' not in rawTxSigned_w1 | ||||
# Perform the same test on signrawtransaction | |||||
rawTxSigned_w1 = w1.signrawtransaction(rawTx_w1) | |||||
assert rawTxSigned_w1['complete'] | |||||
assert 'errors' not in rawTxSigned_w1 | |||||
def run_test(self): | def run_test(self): | ||||
self.successful_signing_test() | self.successful_signing_test() | ||||
self.script_verification_error_test() | self.script_verification_error_test() | ||||
self.test_sighashes() | self.test_sighashes() | ||||
self.multiwallet_signing_test() | self.multiwallet_signing_test() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
SignRawTransactionsTest().main() | SignRawTransactionsTest().main() |