aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-04-22 13:44:05 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-04-23 09:39:21 +0200
commitfa085b470a9647f3b261f506b46f4e7ca2baf0b0 (patch)
tree12742857fda9411cc33166e520c64b46f2ce713b /test
parentfa1bedb4944b513a3c9184ad549f58bfbe69e20e (diff)
downloadbitcoin-fa085b470a9647f3b261f506b46f4e7ca2baf0b0.tar.xz
test: Create MiniWallet.create_self_transfer
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/mempool_spend_coinbase.py5
-rw-r--r--test/functional/test_framework/wallet.py13
2 files changed, 13 insertions, 5 deletions
diff --git a/test/functional/mempool_spend_coinbase.py b/test/functional/mempool_spend_coinbase.py
index a249a73315..b662b7b3ad 100755
--- a/test/functional/mempool_spend_coinbase.py
+++ b/test/functional/mempool_spend_coinbase.py
@@ -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"]
# 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,
"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:
assert_equal(self.nodes[0].getrawmempool(), [spend_101_id])
@@ -52,7 +53,7 @@ class MempoolSpendCoinbaseTest(BitcoinTestFramework):
assert_equal(set(self.nodes[0].getrawmempool()), set())
# ... 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])
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py
index 26294d6a9d..59ef18635b 100644
--- a/test/functional/test_framework/wallet.py
+++ b/test/functional/test_framework/wallet.py
@@ -73,6 +73,12 @@ class MiniWallet:
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."""
+ 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'])
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)
@@ -88,9 +94,10 @@ class MiniWallet:
tx_hex = tx.serialize().hex()
tx_info = from_node.testmempoolaccept([tx_hex])[0]
- self.sendrawtransaction(from_node=from_node, tx_hex=tx_hex)
- assert_equal(tx_info['vsize'], vsize)
- assert_equal(tx_info['fees']['base'], fee)
+ assert_equal(mempool_valid, tx_info['allowed'])
+ if mempool_valid:
+ assert_equal(tx_info['vsize'], vsize)
+ assert_equal(tx_info['fees']['base'], fee)
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex}
def sendrawtransaction(self, *, from_node, tx_hex):