mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 18:20:58 +02:00
test: Create MiniWallet.create_self_transfer
This commit is contained in:
@ -40,9 +40,10 @@ class MempoolSpendCoinbaseTest(BitcoinTestFramework):
|
|||||||
spend_101_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_101)["txid"]
|
spend_101_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_101)["txid"]
|
||||||
|
|
||||||
# coinbase at height 102 should be too immature to spend
|
# coinbase at height 102 should be too immature to spend
|
||||||
|
immature_tx = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_102, mempool_valid=False)
|
||||||
assert_raises_rpc_error(-26,
|
assert_raises_rpc_error(-26,
|
||||||
"bad-txns-premature-spend-of-coinbase",
|
"bad-txns-premature-spend-of-coinbase",
|
||||||
lambda: wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_102))
|
lambda: self.nodes[0].sendrawtransaction(immature_tx['hex']))
|
||||||
|
|
||||||
# mempool should have just spend_101:
|
# mempool should have just spend_101:
|
||||||
assert_equal(self.nodes[0].getrawmempool(), [spend_101_id])
|
assert_equal(self.nodes[0].getrawmempool(), [spend_101_id])
|
||||||
@ -52,7 +53,7 @@ class MempoolSpendCoinbaseTest(BitcoinTestFramework):
|
|||||||
assert_equal(set(self.nodes[0].getrawmempool()), set())
|
assert_equal(set(self.nodes[0].getrawmempool()), set())
|
||||||
|
|
||||||
# ... and now height 102 can be spent:
|
# ... and now height 102 can be spent:
|
||||||
spend_102_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_102)["txid"]
|
spend_102_id = self.nodes[0].sendrawtransaction(immature_tx['hex'])
|
||||||
assert_equal(self.nodes[0].getrawmempool(), [spend_102_id])
|
assert_equal(self.nodes[0].getrawmempool(), [spend_102_id])
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +73,12 @@ class MiniWallet:
|
|||||||
|
|
||||||
def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None):
|
def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None):
|
||||||
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
||||||
|
tx = self.create_self_transfer(fee_rate=fee_rate, from_node=from_node, utxo_to_spend=utxo_to_spend)
|
||||||
|
self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
|
||||||
|
return tx
|
||||||
|
|
||||||
|
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True):
|
||||||
|
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
||||||
self._utxos = sorted(self._utxos, key=lambda k: k['value'])
|
self._utxos = sorted(self._utxos, key=lambda k: k['value'])
|
||||||
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
|
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
|
||||||
vsize = Decimal(96)
|
vsize = Decimal(96)
|
||||||
@ -88,7 +94,8 @@ class MiniWallet:
|
|||||||
tx_hex = tx.serialize().hex()
|
tx_hex = tx.serialize().hex()
|
||||||
|
|
||||||
tx_info = from_node.testmempoolaccept([tx_hex])[0]
|
tx_info = from_node.testmempoolaccept([tx_hex])[0]
|
||||||
self.sendrawtransaction(from_node=from_node, tx_hex=tx_hex)
|
assert_equal(mempool_valid, tx_info['allowed'])
|
||||||
|
if mempool_valid:
|
||||||
assert_equal(tx_info['vsize'], vsize)
|
assert_equal(tx_info['vsize'], vsize)
|
||||||
assert_equal(tx_info['fees']['base'], fee)
|
assert_equal(tx_info['fees']['base'], fee)
|
||||||
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex}
|
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex}
|
||||||
|
Reference in New Issue
Block a user