Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,8 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)

// Sign the transaction
LOCK2(cs_main, pwallet->cs_wallet);
EnsureWalletIsUnlocked(pwallet);

return SignTransaction(mtx, request.params[1], pwallet, false, request.params[2]);
}

Expand Down
9 changes: 9 additions & 0 deletions test/functional/rpc_signrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def successful_signing_test(self):
# 2) No script verification error occurred
assert 'errors' not in rawTxSigned

def test_with_lock_outputs(self):
"""Test correct error reporting when trying to sign a locked output"""
self.nodes[0].encryptwallet("password")

rawTx = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could create a transaction that the wallet could actually sign?

Without this fix, this test holds:

        self.nodes[0].generate(101)
        res = self.nodes[0].createrawtransaction([], {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1})
        res = self.nodes[0].fundrawtransaction(res)
        self.nodes[0].encryptwallet("password")
        res = self.nodes[0].signrawtransactionwithwallet(res['hex'])
        assert_equal(res['errors'][0]['error'], 'Unable to sign input, invalid stack size (possibly missing key)')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this test passes on master and 0.17, but the point of this PR is reporting the correct error before signing, so it's sufficient that the tx is well formed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, just saying because I had to write that to test the change is necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to verify the necessity of the change is to run this PR's test_with_lock_outputs in the 0.16 branch, it will pass.


assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].signrawtransactionwithwallet, rawTx)

def script_verification_error_test(self):
"""Create and sign a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script.

Expand Down Expand Up @@ -138,6 +146,7 @@ def script_verification_error_test(self):
def run_test(self):
self.successful_signing_test()
self.script_verification_error_test()
self.test_with_lock_outputs()


if __name__ == '__main__':
Expand Down