mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05: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
1 changed files with 12 additions and 12 deletions
|
@ -992,31 +992,31 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
|
||||
# We receive unconfirmed funds from external keys (unsafe outputs).
|
||||
addr = wallet.getnewaddress()
|
||||
txid1 = self.nodes[2].sendtoaddress(addr, 6)
|
||||
txid2 = self.nodes[2].sendtoaddress(addr, 4)
|
||||
self.sync_all()
|
||||
vout1 = find_vout_for_address(wallet, txid1, addr)
|
||||
vout2 = find_vout_for_address(wallet, txid2, addr)
|
||||
inputs = []
|
||||
for i in range(0, 2):
|
||||
txid = self.nodes[2].sendtoaddress(addr, 5)
|
||||
self.sync_mempools()
|
||||
vout = find_vout_for_address(wallet, txid, addr)
|
||||
inputs.append((txid, vout))
|
||||
|
||||
# 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)
|
||||
|
||||
# But we can opt-in to use them for funding.
|
||||
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
|
||||
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'])
|
||||
wallet.sendrawtransaction(signedtx['hex'])
|
||||
assert wallet.testmempoolaccept([signedtx['hex']])[0]["allowed"]
|
||||
|
||||
# And we can also use them once they're confirmed.
|
||||
self.generate(self.nodes[0], 1)
|
||||
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 3}])
|
||||
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": True})
|
||||
fundedtx = wallet.fundrawtransaction(rawtx, {"include_unsafe": False})
|
||||
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'])
|
||||
wallet.sendrawtransaction(signedtx['hex'])
|
||||
assert wallet.testmempoolaccept([signedtx['hex']])[0]["allowed"]
|
||||
|
||||
def test_22670(self):
|
||||
# In issue #22670, it was observed that ApproximateBestSubset may
|
||||
|
|
Loading…
Add table
Reference in a new issue