mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-12 11:19:08 -05:00
Replace custom funding tx creation with MiniWallet.
setup_clean_chain=True is deleted so it uses the default. Also, vout is now returned from send_to_address, so now there is no need to fetch it manually Also remove not-needed code that was used with the old transaction handling.
This commit is contained in:
parent
6d546336e8
commit
1f4cdb3d69
1 changed files with 10 additions and 17 deletions
|
@ -4,8 +4,8 @@
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test transaction signing using the signrawtransactionwithkey RPC."""
|
"""Test transaction signing using the signrawtransactionwithkey RPC."""
|
||||||
|
|
||||||
from test_framework.blocktools import (
|
from test_framework.messages import (
|
||||||
COINBASE_MATURITY,
|
COIN,
|
||||||
)
|
)
|
||||||
from test_framework.address import (
|
from test_framework.address import (
|
||||||
address_to_scriptpubkey,
|
address_to_scriptpubkey,
|
||||||
|
@ -16,7 +16,6 @@ from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
find_vout_for_address,
|
|
||||||
)
|
)
|
||||||
from test_framework.script_util import (
|
from test_framework.script_util import (
|
||||||
key_to_p2pk_script,
|
key_to_p2pk_script,
|
||||||
|
@ -26,6 +25,7 @@ from test_framework.script_util import (
|
||||||
)
|
)
|
||||||
from test_framework.wallet import (
|
from test_framework.wallet import (
|
||||||
getnewdestination,
|
getnewdestination,
|
||||||
|
MiniWallet,
|
||||||
)
|
)
|
||||||
from test_framework.wallet_util import (
|
from test_framework.wallet_util import (
|
||||||
generate_keypair,
|
generate_keypair,
|
||||||
|
@ -46,16 +46,12 @@ OUTPUTS = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1}
|
||||||
|
|
||||||
class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.setup_clean_chain = True
|
|
||||||
self.num_nodes = 2
|
self.num_nodes = 2
|
||||||
|
|
||||||
def send_to_address(self, addr, amount):
|
def send_to_address(self, addr, amount):
|
||||||
input = {"txid": self.nodes[0].getblock(self.block_hash[self.blk_idx])["tx"][0], "vout": 0}
|
script_pub_key = address_to_scriptpubkey(addr)
|
||||||
output = {addr: amount}
|
tx = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=script_pub_key, amount=int(amount * COIN))
|
||||||
self.blk_idx += 1
|
return tx["txid"], tx["sent_vout"]
|
||||||
rawtx = self.nodes[0].createrawtransaction([input], output)
|
|
||||||
txid = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransactionwithkey(rawtx, [self.nodes[0].get_deterministic_priv_key().key])["hex"], 0)
|
|
||||||
return txid
|
|
||||||
|
|
||||||
def assert_signing_completed_successfully(self, signed_tx):
|
def assert_signing_completed_successfully(self, signed_tx):
|
||||||
assert 'errors' not in signed_tx
|
assert 'errors' not in signed_tx
|
||||||
|
@ -82,8 +78,6 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||||
embedded_privkey, embedded_pubkey = generate_keypair(wif=True)
|
embedded_privkey, embedded_pubkey = generate_keypair(wif=True)
|
||||||
p2sh_p2wsh_address = self.nodes[1].createmultisig(1, [embedded_pubkey.hex()], "p2sh-segwit")
|
p2sh_p2wsh_address = self.nodes[1].createmultisig(1, [embedded_pubkey.hex()], "p2sh-segwit")
|
||||||
# send transaction to P2SH-P2WSH 1-of-1 multisig address
|
# send transaction to P2SH-P2WSH 1-of-1 multisig address
|
||||||
self.block_hash = self.generate(self.nodes[0], COINBASE_MATURITY + 1)
|
|
||||||
self.blk_idx = 0
|
|
||||||
self.send_to_address(p2sh_p2wsh_address["address"], 49.999)
|
self.send_to_address(p2sh_p2wsh_address["address"], 49.999)
|
||||||
self.generate(self.nodes[0], 1)
|
self.generate(self.nodes[0], 1)
|
||||||
# Get the UTXO info from scantxoutset
|
# Get the UTXO info from scantxoutset
|
||||||
|
@ -103,9 +97,9 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def keyless_signing_test(self):
|
def keyless_signing_test(self):
|
||||||
self.log.info("Test that keyless 'signing' of pay-to-anchor input succeeds")
|
self.log.info("Test that keyless 'signing' of pay-to-anchor input succeeds")
|
||||||
funding_txid = self.send_to_address(p2a(), 49.999)
|
[txid, vout] = self.send_to_address(p2a(), 49.999)
|
||||||
spending_tx = self.nodes[0].createrawtransaction(
|
spending_tx = self.nodes[0].createrawtransaction(
|
||||||
[{"txid": funding_txid, "vout": 0}],
|
[{"txid": txid, "vout": vout}],
|
||||||
[{getnewdestination()[2]: Decimal("49.998")}])
|
[{getnewdestination()[2]: Decimal("49.998")}])
|
||||||
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [], [])
|
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [], [])
|
||||||
self.assert_signing_completed_successfully(spending_tx_signed)
|
self.assert_signing_completed_successfully(spending_tx_signed)
|
||||||
|
@ -124,9 +118,7 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||||
addr = script_to_p2sh(redeem_script)
|
addr = script_to_p2sh(redeem_script)
|
||||||
script_pub_key = address_to_scriptpubkey(addr).hex()
|
script_pub_key = address_to_scriptpubkey(addr).hex()
|
||||||
# Fund that address
|
# Fund that address
|
||||||
txid = self.send_to_address(addr, 10)
|
[txid, vout] = self.send_to_address(addr, 10)
|
||||||
vout = find_vout_for_address(self.nodes[0], txid, addr)
|
|
||||||
self.generate(self.nodes[0], 1)
|
|
||||||
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
|
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
|
||||||
spending_tx = self.nodes[0].createrawtransaction([{'txid': txid, 'vout': vout}], {getnewdestination()[2]: Decimal("9.999")})
|
spending_tx = self.nodes[0].createrawtransaction([{'txid': txid, 'vout': vout}], {getnewdestination()[2]: Decimal("9.999")})
|
||||||
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [{'txid': txid, 'vout': vout, 'scriptPubKey': script_pub_key, 'redeemScript': redeem_script, 'witnessScript': witness_script, 'amount': 10}])
|
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [{'txid': txid, 'vout': vout, 'scriptPubKey': script_pub_key, 'redeemScript': redeem_script, 'witnessScript': witness_script, 'amount': 10}])
|
||||||
|
@ -149,6 +141,7 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-22, "TX decode failed. Make sure the tx has at least one input.", self.nodes[0].signrawtransactionwithkey, tx + "00", privkeys)
|
assert_raises_rpc_error(-22, "TX decode failed. Make sure the tx has at least one input.", self.nodes[0].signrawtransactionwithkey, tx + "00", privkeys)
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
self.wallet = MiniWallet(self.nodes[0])
|
||||||
self.successful_signing_test()
|
self.successful_signing_test()
|
||||||
self.witness_script_test()
|
self.witness_script_test()
|
||||||
self.keyless_signing_test()
|
self.keyless_signing_test()
|
||||||
|
|
Loading…
Add table
Reference in a new issue