Skip to content

Commit e93046c

Browse files
MOVEONLY: Move signrawtransactionwithwallet test
Put signrawtransactionwithwallet_tests in rpc_signrawtransaction.py, as the test is mainly testing the signrawtransaction RPC. Review with `git show --color-moved=dimmed-zebra`
1 parent 1ab389b commit e93046c

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

test/functional/rpc_rawtransaction.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def run_test(self):
8383

8484
self.getrawtransaction_tests()
8585
self.createrawtransaction_tests()
86-
self.signrawtransactionwithwallet_tests()
8786
self.sendrawtransaction_tests()
8887
self.sendrawtransaction_testmempoolaccept_tests()
8988
self.decoderawtransaction_tests()
@@ -259,55 +258,6 @@ def createrawtransaction_tests(self):
259258
self.nodes[2].createrawtransaction(inputs=[{'txid': TXID, 'vout': 9}], outputs=[{address: 99}, {address2: 99}, {'data': '99'}]),
260259
)
261260

262-
def signrawtransactionwithwallet_tests(self):
263-
for type in ["bech32", "p2sh-segwit", "legacy"]:
264-
self.log.info(f"Test signrawtransactionwithwallet with missing prevtx info ({type})")
265-
addr = self.nodes[0].getnewaddress("", type)
266-
addrinfo = self.nodes[0].getaddressinfo(addr)
267-
pubkey = addrinfo["scriptPubKey"]
268-
inputs = [{'txid': TXID, 'vout': 3, 'sequence': 1000}]
269-
outputs = {self.nodes[0].getnewaddress(): 1}
270-
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
271-
272-
prevtx = dict(txid=TXID, scriptPubKey=pubkey, vout=3, amount=1)
273-
succ = self.nodes[0].signrawtransactionwithwallet(rawtx, [prevtx])
274-
assert succ["complete"]
275-
276-
if type == "legacy":
277-
del prevtx["amount"]
278-
succ = self.nodes[0].signrawtransactionwithwallet(rawtx, [prevtx])
279-
assert succ["complete"]
280-
else:
281-
assert_raises_rpc_error(-3, "Missing amount", self.nodes[0].signrawtransactionwithwallet, rawtx, [
282-
{
283-
"txid": TXID,
284-
"scriptPubKey": pubkey,
285-
"vout": 3,
286-
}
287-
])
288-
289-
assert_raises_rpc_error(-3, "Missing vout", self.nodes[0].signrawtransactionwithwallet, rawtx, [
290-
{
291-
"txid": TXID,
292-
"scriptPubKey": pubkey,
293-
"amount": 1,
294-
}
295-
])
296-
assert_raises_rpc_error(-3, "Missing txid", self.nodes[0].signrawtransactionwithwallet, rawtx, [
297-
{
298-
"scriptPubKey": pubkey,
299-
"vout": 3,
300-
"amount": 1,
301-
}
302-
])
303-
assert_raises_rpc_error(-3, "Missing scriptPubKey", self.nodes[0].signrawtransactionwithwallet, rawtx, [
304-
{
305-
"txid": TXID,
306-
"vout": 3,
307-
"amount": 1
308-
}
309-
])
310-
311261
def sendrawtransaction_tests(self):
312262
self.log.info("Test sendrawtransaction with missing input")
313263
inputs = [{'txid': TXID, 'vout': 1}] # won't exist

test/functional/rpc_signrawtransaction.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,56 @@ def test_signing_with_cltv(self):
334334
assert_equal(signed["complete"], True)
335335
self.nodes[0].sendrawtransaction(signed["hex"])
336336

337+
def test_signing_with_missing_prevtx_info(self):
338+
txid = "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000"
339+
for type in ["bech32", "p2sh-segwit", "legacy"]:
340+
self.log.info(f"Test signing with missing prevtx info ({type})")
341+
addr = self.nodes[0].getnewaddress("", type)
342+
addrinfo = self.nodes[0].getaddressinfo(addr)
343+
pubkey = addrinfo["scriptPubKey"]
344+
inputs = [{'txid': txid, 'vout': 3, 'sequence': 1000}]
345+
outputs = {self.nodes[0].getnewaddress(): 1}
346+
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
347+
348+
prevtx = dict(txid=txid, scriptPubKey=pubkey, vout=3, amount=1)
349+
succ = self.nodes[0].signrawtransactionwithwallet(rawtx, [prevtx])
350+
assert succ["complete"]
351+
352+
if type == "legacy":
353+
del prevtx["amount"]
354+
succ = self.nodes[0].signrawtransactionwithwallet(rawtx, [prevtx])
355+
assert succ["complete"]
356+
else:
357+
assert_raises_rpc_error(-3, "Missing amount", self.nodes[0].signrawtransactionwithwallet, rawtx, [
358+
{
359+
"txid": txid,
360+
"scriptPubKey": pubkey,
361+
"vout": 3,
362+
}
363+
])
364+
365+
assert_raises_rpc_error(-3, "Missing vout", self.nodes[0].signrawtransactionwithwallet, rawtx, [
366+
{
367+
"txid": txid,
368+
"scriptPubKey": pubkey,
369+
"amount": 1,
370+
}
371+
])
372+
assert_raises_rpc_error(-3, "Missing txid", self.nodes[0].signrawtransactionwithwallet, rawtx, [
373+
{
374+
"scriptPubKey": pubkey,
375+
"vout": 3,
376+
"amount": 1,
377+
}
378+
])
379+
assert_raises_rpc_error(-3, "Missing scriptPubKey", self.nodes[0].signrawtransactionwithwallet, rawtx, [
380+
{
381+
"txid": txid,
382+
"vout": 3,
383+
"amount": 1
384+
}
385+
])
386+
337387
def run_test(self):
338388
self.successful_signing_test()
339389
self.script_verification_error_test()
@@ -343,6 +393,7 @@ def run_test(self):
343393
self.test_fully_signed_tx()
344394
self.test_signing_with_csv()
345395
self.test_signing_with_cltv()
396+
self.test_signing_with_missing_prevtx_info()
346397

347398

348399
if __name__ == '__main__':

0 commit comments

Comments
 (0)