mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-21 09:32:39 +02:00
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.
This commit is contained in:
parent
a165bfbe44
commit
59ba7d2861
@ -992,31 +992,31 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
# We receive unconfirmed funds from external keys (unsafe outputs).
|
# We receive unconfirmed funds from external keys (unsafe outputs).
|
||||||
addr = wallet.getnewaddress()
|
addr = wallet.getnewaddress()
|
||||||
txid1 = self.nodes[2].sendtoaddress(addr, 6)
|
inputs = []
|
||||||
txid2 = self.nodes[2].sendtoaddress(addr, 4)
|
for i in range(0, 2):
|
||||||
self.sync_all()
|
txid = self.nodes[2].sendtoaddress(addr, 5)
|
||||||
vout1 = find_vout_for_address(wallet, txid1, addr)
|
self.sync_mempools()
|
||||||
vout2 = find_vout_for_address(wallet, txid2, addr)
|
vout = find_vout_for_address(wallet, txid, addr)
|
||||||
|
inputs.append((txid, vout))
|
||||||
|
|
||||||
# Unsafe inputs are ignored by default.
|
# Unsafe inputs are ignored by default.
|
||||||
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 5}])
|
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 7.5}])
|
||||||
assert_raises_rpc_error(-4, "Insufficient funds", wallet.fundrawtransaction, rawtx)
|
assert_raises_rpc_error(-4, "Insufficient funds", wallet.fundrawtransaction, rawtx)
|
||||||
|
|
||||||
# But we can opt-in to use them for funding.
|
# But we can opt-in to use them for funding.
|
||||||
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
|
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
|
||||||
tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
|
tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
|
||||||
assert any([txin['txid'] == txid1 and txin['vout'] == vout1 for txin in tx_dec['vin']])
|
assert all((txin["txid"], txin["vout"]) in inputs for txin in tx_dec["vin"])
|
||||||
signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
|
signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
|
||||||
wallet.sendrawtransaction(signedtx['hex'])
|
assert wallet.testmempoolaccept([signedtx['hex']])[0]["allowed"]
|
||||||
|
|
||||||
# And we can also use them once they're confirmed.
|
# And we can also use them once they're confirmed.
|
||||||
self.generate(self.nodes[0], 1)
|
self.generate(self.nodes[0], 1)
|
||||||
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 3}])
|
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": False})
|
||||||
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
|
|
||||||
tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
|
tx_dec = wallet.decoderawtransaction(fundedtx['hex'])
|
||||||
assert any([txin['txid'] == txid2 and txin['vout'] == vout2 for txin in tx_dec['vin']])
|
assert all((txin["txid"], txin["vout"]) in inputs for txin in tx_dec["vin"])
|
||||||
signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
|
signedtx = wallet.signrawtransactionwithwallet(fundedtx['hex'])
|
||||||
wallet.sendrawtransaction(signedtx['hex'])
|
assert wallet.testmempoolaccept([signedtx['hex']])[0]["allowed"]
|
||||||
|
|
||||||
def test_22670(self):
|
def test_22670(self):
|
||||||
# In issue #22670, it was observed that ApproximateBestSubset may
|
# In issue #22670, it was observed that ApproximateBestSubset may
|
||||||
|
Loading…
Reference in New Issue
Block a user