Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_signrawtransaction.py
Show First 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | def test_sighashes(self): | ||||
rawTx = self.nodes[0].createrawtransaction(inputs, outputs) | rawTx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
valid_sighashes = [ | valid_sighashes = [ | ||||
"ALL|FORKID", | "ALL|FORKID", | ||||
"NONE|FORKID", | "NONE|FORKID", | ||||
"SINGLE|FORKID", | "SINGLE|FORKID", | ||||
"ALL|FORKID|ANYONECANPAY", | "ALL|FORKID|ANYONECANPAY", | ||||
"NONE|FORKID|ANYONECANPAY", | "NONE|FORKID|ANYONECANPAY", | ||||
"SINGLE|FORKID|ANYONECANPAY" | "SINGLE|FORKID|ANYONECANPAY", | ||||
] | ] | ||||
no_forkid_sighashes = [ | no_forkid_sighashes = [ | ||||
"ALL", | "ALL", | ||||
"NONE", | "NONE", | ||||
"SINGLE", | "SINGLE", | ||||
"ALL|ANYONECANPAY", | "ALL|ANYONECANPAY", | ||||
"NONE|ANYONECANPAY", | "NONE|ANYONECANPAY", | ||||
"SINGLE|ANYONECANPAY" | "SINGLE|ANYONECANPAY", | ||||
] | ] | ||||
invalid_sighashes = [ | invalid_sighashes = [ | ||||
"", | "", | ||||
"ALL|SINGLE|FORKID", | "ALL|SINGLE|FORKID", | ||||
str(0), | str(0), | ||||
str(0x20) | str(0x20), | ||||
] | ] | ||||
# 1) If the sighash is valid with FORKID, the signature is complete | # 1) If the sighash is valid with FORKID, the signature is complete | ||||
for sighash in valid_sighashes: | for sighash in valid_sighashes: | ||||
rawTxSigned = self.nodes[0].signrawtransactionwithkey( | rawTxSigned = self.nodes[0].signrawtransactionwithkey( | ||||
rawTx, privKeys, inputs, sighash) | rawTx, privKeys, inputs, sighash) | ||||
assert 'complete' in rawTxSigned | assert 'complete' in rawTxSigned | ||||
assert_equal(rawTxSigned['complete'], True) | assert_equal(rawTxSigned['complete'], True) | ||||
assert 'errors' not in rawTxSigned | assert 'errors' not in rawTxSigned | ||||
# 2) If FORKID is missing in the sighash, the RPC throws an error | # 2) If FORKID is missing in the sighash, the RPC throws an error | ||||
for sighash in no_forkid_sighashes: | for sighash in no_forkid_sighashes: | ||||
assert_raises_rpc_error(-8, "Signature must use SIGHASH_FORKID", | assert_raises_rpc_error(-8, "Signature must use SIGHASH_FORKID", | ||||
self.nodes[0].signrawtransactionwithkey, | self.nodes[0].signrawtransactionwithkey, | ||||
rawTx, privKeys, inputs, sighash) | rawTx, privKeys, inputs, sighash) | ||||
# 3) If the sighash is invalid the RPC throws an error | # 3) If the sighash is invalid the RPC throws an error | ||||
for sighash in invalid_sighashes: | for sighash in invalid_sighashes: | ||||
assert_raises_rpc_error(-8, "Invalid sighash param", | assert_raises_rpc_error(-1, sighash + " is not a valid sighash parameter.", | ||||
self.nodes[0].signrawtransactionwithkey, | self.nodes[0].signrawtransactionwithkey, | ||||
rawTx, privKeys, inputs, sighash) | rawTx, privKeys, inputs, sighash) | ||||
def multiwallet_signing_test(self): | def multiwallet_signing_test(self): | ||||
"""Creates and signs a raw transaction with a multiwallet node. | """Creates and signs a raw transaction with a multiwallet node. | ||||
Expected results: | Expected results: | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |