mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
test: use MiniWallet for p2p_segwit.py
This change only affects the subtest `test_superfluous_witness`. Note that instead of creating a raw transaction first and then signing it, we go the other direction here: MiniWallet creates a transaction spending a segwit v1 output (i.e. including a witness), then we turn it into a raw transaction by dropping the witness. Therefore, the debug log asserts are swapped.
This commit is contained in:
parent
f60a63cc5f
commit
917a89a814
1 changed files with 9 additions and 18 deletions
|
@ -43,7 +43,6 @@ from test_framework.messages import (
|
||||||
ser_uint256,
|
ser_uint256,
|
||||||
ser_vector,
|
ser_vector,
|
||||||
sha256,
|
sha256,
|
||||||
tx_from_hex,
|
|
||||||
)
|
)
|
||||||
from test_framework.p2p import (
|
from test_framework.p2p import (
|
||||||
P2PInterface,
|
P2PInterface,
|
||||||
|
@ -89,6 +88,8 @@ from test_framework.util import (
|
||||||
softfork_active,
|
softfork_active,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet import MiniWallet
|
||||||
|
|
||||||
|
|
||||||
MAX_SIGOP_COST = 80000
|
MAX_SIGOP_COST = 80000
|
||||||
|
|
||||||
|
@ -221,9 +222,6 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
]
|
]
|
||||||
self.supports_cli = False
|
self.supports_cli = False
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
|
||||||
self.skip_if_no_wallet()
|
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
|
|
||||||
def build_next_block(self):
|
def build_next_block(self):
|
||||||
|
@ -259,6 +257,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.log.info("Starting tests before segwit activation")
|
self.log.info("Starting tests before segwit activation")
|
||||||
self.segwit_active = False
|
self.segwit_active = False
|
||||||
|
self.wallet = MiniWallet(self.nodes[0])
|
||||||
|
|
||||||
self.test_non_witness_transaction()
|
self.test_non_witness_transaction()
|
||||||
self.test_v0_outputs_arent_spendable()
|
self.test_v0_outputs_arent_spendable()
|
||||||
|
@ -307,7 +306,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed
|
self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed
|
||||||
txid = block.vtx[0].sha256
|
txid = block.vtx[0].sha256
|
||||||
|
|
||||||
self.generate(self.nodes[0], 99) # let the block mature
|
self.generate(self.wallet, 99) # let the block mature
|
||||||
|
|
||||||
# Create a transaction that spends the coinbase
|
# Create a transaction that spends the coinbase
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
|
@ -1999,22 +1998,14 @@ class SegWitTest(BitcoinTestFramework):
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
return serialize_with_bogus_witness(self.tx)
|
return serialize_with_bogus_witness(self.tx)
|
||||||
|
|
||||||
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(address_type='bech32'), 5)
|
tx = self.wallet.create_self_transfer(from_node=self.nodes[0])['tx']
|
||||||
self.generate(self.nodes[0], 1)
|
|
||||||
unspent = next(u for u in self.nodes[0].listunspent() if u['spendable'] and u['address'].startswith('bcrt'))
|
|
||||||
|
|
||||||
raw = self.nodes[0].createrawtransaction([{"txid": unspent['txid'], "vout": unspent['vout']}], {self.nodes[0].getnewaddress(): 1})
|
|
||||||
tx = tx_from_hex(raw)
|
|
||||||
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
|
|
||||||
with self.nodes[0].assert_debug_log(['Superfluous witness record']):
|
|
||||||
self.test_node.send_and_ping(msg_bogus_tx(tx))
|
|
||||||
raw = self.nodes[0].signrawtransactionwithwallet(raw)
|
|
||||||
assert raw['complete']
|
|
||||||
raw = raw['hex']
|
|
||||||
tx = tx_from_hex(raw)
|
|
||||||
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
|
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
|
||||||
with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):
|
with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):
|
||||||
self.test_node.send_and_ping(msg_bogus_tx(tx))
|
self.test_node.send_and_ping(msg_bogus_tx(tx))
|
||||||
|
tx.wit.vtxinwit = [] # drop witness
|
||||||
|
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
|
||||||
|
with self.nodes[0].assert_debug_log(['Superfluous witness record']):
|
||||||
|
self.test_node.send_and_ping(msg_bogus_tx(tx))
|
||||||
|
|
||||||
@subtest
|
@subtest
|
||||||
def test_wtxid_relay(self):
|
def test_wtxid_relay(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue