mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 18:09:47 +01:00
test: MiniWallet: support default from_node
for creating txs
If no `from_node` parameter is passed explicitely to the `create_self_transfer` method, the test node passed in the course of creating the MiniWallet instance is used. This seems to be the main use-case in most of the current functional tests, i.e. in many instances the calls can be shortened.
This commit is contained in:
parent
f30041c914
commit
b24f6c6855
@ -115,7 +115,7 @@ class BIP65Test(BitcoinTestFramework):
|
||||
# create one invalid tx per CLTV failure reason (5 in total) and collect them
|
||||
invalid_cltv_txs = []
|
||||
for i in range(5):
|
||||
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
|
||||
spendtx = wallet.create_self_transfer()['tx']
|
||||
cltv_invalidate(spendtx, i)
|
||||
invalid_cltv_txs.append(spendtx)
|
||||
|
||||
@ -146,7 +146,7 @@ class BIP65Test(BitcoinTestFramework):
|
||||
|
||||
# create and test one invalid tx per CLTV failure reason (5 in total)
|
||||
for i in range(5):
|
||||
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
|
||||
spendtx = wallet.create_self_transfer()['tx']
|
||||
cltv_invalidate(spendtx, i)
|
||||
|
||||
expected_cltv_reject_reason = [
|
||||
|
@ -104,7 +104,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
||||
|
||||
def create_self_transfer_from_utxo(self, input_tx):
|
||||
utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False)
|
||||
tx = self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo)['tx']
|
||||
tx = self.miniwallet.create_self_transfer(utxo_to_spend=utxo)['tx']
|
||||
return tx
|
||||
|
||||
def create_bip112special(self, input, txversion):
|
||||
|
@ -57,7 +57,7 @@ class BIP66Test(BitcoinTestFramework):
|
||||
|
||||
def create_tx(self, input_txid):
|
||||
utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid, mark_as_spent=False)
|
||||
return self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx']
|
||||
return self.miniwallet.create_self_transfer(utxo_to_spend=utxo_to_spend)['tx']
|
||||
|
||||
def test_dersig_info(self, *, is_active):
|
||||
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip66'],
|
||||
|
@ -115,7 +115,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
"""Simple doublespend"""
|
||||
# we use MiniWallet to create a transaction template with inputs correctly set,
|
||||
# and modify the output (amount, scriptPubKey) according to our needs
|
||||
tx_template = self.wallet.create_self_transfer(from_node=self.nodes[0])['tx']
|
||||
tx_template = self.wallet.create_self_transfer()['tx']
|
||||
|
||||
tx1a = deepcopy(tx_template)
|
||||
tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT)]
|
||||
@ -563,7 +563,6 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])
|
||||
|
||||
replacement_parent_tx = self.wallet.create_self_transfer(
|
||||
from_node=self.nodes[0],
|
||||
utxo_to_spend=confirmed_utxo,
|
||||
sequence=BIP125_SEQUENCE_NUMBER,
|
||||
fee_rate=Decimal('0.02'),
|
||||
@ -588,7 +587,6 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
assert_equal(True, self.nodes[0].getmempoolentry(optout_child_tx['txid'])['bip125-replaceable'])
|
||||
|
||||
replacement_child_tx = self.wallet.create_self_transfer(
|
||||
from_node=self.nodes[0],
|
||||
utxo_to_spend=parent_utxo,
|
||||
sequence=SEQUENCE_FINAL,
|
||||
fee_rate=Decimal('0.02'),
|
||||
|
@ -45,14 +45,13 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||
utxo_2 = wallet.get_utxo(txid=coinbase_txids[2])
|
||||
utxo_3 = wallet.get_utxo(txid=coinbase_txids[3])
|
||||
self.log.info("Create three transactions spending from coinbase utxos: spend_1, spend_2, spend_3")
|
||||
spend_1 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_1)
|
||||
spend_2 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_2)
|
||||
spend_3 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_3)
|
||||
spend_1 = wallet.create_self_transfer(utxo_to_spend=utxo_1)
|
||||
spend_2 = wallet.create_self_transfer(utxo_to_spend=utxo_2)
|
||||
spend_3 = wallet.create_self_transfer(utxo_to_spend=utxo_3)
|
||||
|
||||
self.log.info("Create another transaction which is time-locked to two blocks in the future")
|
||||
utxo = wallet.get_utxo(txid=coinbase_txids[0])
|
||||
timelock_tx = wallet.create_self_transfer(
|
||||
from_node=self.nodes[0],
|
||||
utxo_to_spend=utxo,
|
||||
mempool_valid=False,
|
||||
locktime=self.nodes[0].getblockcount() + 2
|
||||
@ -71,9 +70,9 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info("Create spend_2_1 and spend_3_1")
|
||||
spend_2_utxo = wallet.get_utxo(txid=spend_2['txid'])
|
||||
spend_2_1 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=spend_2_utxo)
|
||||
spend_2_1 = wallet.create_self_transfer(utxo_to_spend=spend_2_utxo)
|
||||
spend_3_utxo = wallet.get_utxo(txid=spend_3['txid'])
|
||||
spend_3_1 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=spend_3_utxo)
|
||||
spend_3_1 = wallet.create_self_transfer(utxo_to_spend=spend_3_utxo)
|
||||
|
||||
self.log.info("Broadcast and mine spend_3_1")
|
||||
spend_3_1_id = self.nodes[0].sendrawtransaction(spend_3_1['hex'])
|
||||
|
@ -40,7 +40,7 @@ class MempoolSpendCoinbaseTest(BitcoinTestFramework):
|
||||
spend_mature_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_mature)["txid"]
|
||||
|
||||
# other coinbase should be too immature to spend
|
||||
immature_tx = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_immature, mempool_valid=False)
|
||||
immature_tx = wallet.create_self_transfer(utxo_to_spend=utxo_immature, mempool_valid=False)
|
||||
assert_raises_rpc_error(-26,
|
||||
"bad-txns-premature-spend-of-coinbase",
|
||||
lambda: self.nodes[0].sendrawtransaction(immature_tx['hex']))
|
||||
|
@ -102,7 +102,7 @@ class P2PBlocksOnly(BitcoinTestFramework):
|
||||
|
||||
def check_p2p_tx_violation(self):
|
||||
self.log.info('Check that txs from P2P are rejected and result in disconnect')
|
||||
spendtx = self.miniwallet.create_self_transfer(from_node=self.nodes[0])
|
||||
spendtx = self.miniwallet.create_self_transfer()
|
||||
|
||||
with self.nodes[0].assert_debug_log(['transaction sent in violation of protocol peer=0']):
|
||||
self.nodes[0].p2ps[0].send_message(msg_tx(spendtx['tx']))
|
||||
|
@ -63,7 +63,7 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
assert_equal(block['tx'][1], txid)
|
||||
|
||||
self.log.info('Generate block with raw tx')
|
||||
rawtx = miniwallet.create_self_transfer(from_node=node)['hex']
|
||||
rawtx = miniwallet.create_self_transfer()['hex']
|
||||
hash = self.generateblock(node, address, [rawtx])['hash']
|
||||
|
||||
block = node.getblock(hash, 1)
|
||||
@ -74,7 +74,7 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
self.log.info('Fail to generate block with out of order txs')
|
||||
txid1 = miniwallet.send_self_transfer(from_node=node)['txid']
|
||||
utxo1 = miniwallet.get_utxo(txid=txid1)
|
||||
rawtx2 = miniwallet.create_self_transfer(from_node=node, utxo_to_spend=utxo1)['hex']
|
||||
rawtx2 = miniwallet.create_self_transfer(utxo_to_spend=utxo1)['hex']
|
||||
assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1])
|
||||
|
||||
self.log.info('Fail to generate block with txid not in mempool')
|
||||
|
@ -179,8 +179,9 @@ class MiniWallet:
|
||||
txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
|
||||
return txid, 1
|
||||
|
||||
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
|
||||
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
|
||||
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
||||
from_node = from_node or self._test_node
|
||||
utxo_to_spend = utxo_to_spend or self.get_utxo()
|
||||
if self._priv_key is None:
|
||||
vsize = Decimal(104) # anyone-can-spend
|
||||
|
Loading…
Reference in New Issue
Block a user