Skip to content

Commit d6d2ab9

Browse files
committed
test: MiniWallet: fix fee calculation for P2PK and check tx vsize
1 parent ce024b1 commit d6d2ab9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/functional/test_framework/wallet.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
142142
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
143143
self._utxos = sorted(self._utxos, key=lambda k: k['value'])
144144
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
145-
vsize = Decimal(96)
145+
if self._priv_key is None:
146+
vsize = Decimal(96) # anyone-can-spend
147+
else:
148+
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
146149
send_value = satoshi_round(utxo_to_spend['value'] - fee_rate * (vsize / 1000))
147150
fee = utxo_to_spend['value'] - send_value
148151
assert send_value > 0
@@ -167,10 +170,7 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
167170
tx_info = from_node.testmempoolaccept([tx_hex])[0]
168171
assert_equal(mempool_valid, tx_info['allowed'])
169172
if mempool_valid:
170-
# TODO: for P2PK, vsize is not constant due to varying scriptSig length,
171-
# so only check this for anyone-can-spend outputs right now
172-
if self._priv_key is None:
173-
assert_equal(tx_info['vsize'], vsize)
173+
assert_equal(tx_info['vsize'], vsize)
174174
assert_equal(tx_info['fees']['base'], fee)
175175
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex, 'tx': tx}
176176

0 commit comments

Comments
 (0)