Skip to content

Commit 59ba7d2

Browse files
committed
tests: rpc_fundrawtx better test for UTXO inclusion with include_unsafe
Don't assume that specific inputs are going to be used when they aren't specified explicitly. Also fixes a bug in the include_unsafe test where after the inputs confirm, include_unsafe should be set to False rather than True.
1 parent a165bfb commit 59ba7d2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

test/functional/rpc_fundrawtransaction.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -992,31 +992,31 @@ def test_include_unsafe(self):
992992

993993
# We receive unconfirmed funds from external keys (unsafe outputs).
994994
addr = wallet.getnewaddress()
995-
txid1 = self.nodes[2].sendtoaddress(addr, 6)
996-
txid2 = self.nodes[2].sendtoaddress(addr, 4)
997-
self.sync_all()
998-
vout1 = find_vout_for_address(wallet, txid1, addr)
999-
vout2 = find_vout_for_address(wallet, txid2, addr)
995+
inputs = []
996+
for i in range(0, 2):
997+
txid = self.nodes[2].sendtoaddress(addr, 5)
998+
self.sync_mempools()
999+
vout = find_vout_for_address(wallet, txid, addr)
1000+
inputs.append((txid, vout))
10001001

10011002
# Unsafe inputs are ignored by default.
1002-
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 5}])
1003+
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 7.5}])
10031004
assert_raises_rpc_error(-4, "Insufficient funds", wallet.fundrawtransaction, rawtx)
10041005

10051006
# But we can opt-in to use them for funding.
10061007
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
10071008
tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
1008-
assert any([txin['txid'] == txid1 and txin['vout'] == vout1 for txin in tx_dec['vin']])
1009+
assert all((txin["txid"], txin["vout"]) in inputs for txin in tx_dec["vin"])
10091010
signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
1010-
wallet.sendrawtransaction(signedtx['hex'])
1011+
assert wallet.testmempoolaccept([signedtx['hex']])[0]["allowed"]
10111012

10121013
# And we can also use them once they're confirmed.
10131014
self.generate(self.nodes[0], 1)
1014-
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 3}])
1015-
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
1015+
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": False})
10161016
tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
1017-
assert any([txin['txid'] == txid2 and txin['vout'] == vout2 for txin in tx_dec['vin']])
1017+
assert all((txin["txid"], txin["vout"]) in inputs for txin in tx_dec["vin"])
10181018
signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
1019-
wallet.sendrawtransaction(signedtx['hex'])
1019+
assert wallet.testmempoolaccept([signedtx['hex']])[0]["allowed"]
10201020

10211021
def test_22670(self):
10221022
# In issue #22670, it was observed that ApproximateBestSubset may

0 commit comments

Comments
 (0)