Skip to content

Commit b4437d7

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23210: test: Replace satoshi_round with int() or Decimal()
fa2ac58 test: Replace satoshi_round with int() or Decimal() (MarcoFalke) Pull request description: satoshi_round will round down. To make the code easier to parse use Decimal() where possible, which does not round. Or use int(), which explicitly rounds down. ACKs for top commit: lsilva01: Tested ACK bitcoin/bitcoin@fa2ac58 on Ubuntu 20.04. Tree-SHA512: 17795d906aa7652933d43e510e993cdd9cf8926da1febf1c42d463048cb38c92dc518ec08736efe29c0189ffd532b108bc7a715f32b4c2ee58b215df65352eb9
2 parents f8911de + fa2ac58 commit b4437d7

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

test/functional/feature_bip68_sequence.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
assert_equal,
2525
assert_greater_than,
2626
assert_raises_rpc_error,
27-
satoshi_round,
2827
softfork_active,
2928
)
3029
from test_framework.script_util import DUMMY_P2WPKH_SCRIPT
@@ -94,7 +93,7 @@ def test_disable_flag(self):
9493
utxo = utxos[0]
9594

9695
tx1 = CTransaction()
97-
value = int(satoshi_round(utxo["amount"] - self.relayfee)*COIN)
96+
value = int((utxo["amount"] - self.relayfee) * COIN)
9897

9998
# Check that the disable flag disables relative locktime.
10099
# If sequence locks were used, this would require 1 block for the

test/functional/mempool_packages.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
assert_equal,
1515
assert_raises_rpc_error,
1616
chain_transaction,
17-
satoshi_round,
1817
)
1918

2019
# default limits
@@ -209,10 +208,10 @@ def run_test(self):
209208
entry = self.nodes[0].getmempoolentry(x)
210209
descendant_fees += entry['fee']
211210
if (x == chain[-1]):
212-
assert_equal(entry['modifiedfee'], entry['fee']+satoshi_round(0.00002))
213-
assert_equal(entry['fees']['modified'], entry['fee']+satoshi_round(0.00002))
211+
assert_equal(entry['modifiedfee'], entry['fee'] + Decimal("0.00002"))
212+
assert_equal(entry['fees']['modified'], entry['fee'] + Decimal("0.00002"))
214213
assert_equal(entry['descendantfees'], descendant_fees * COIN + 2000)
215-
assert_equal(entry['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
214+
assert_equal(entry['fees']['descendant'], descendant_fees + Decimal("0.00002"))
216215

217216
# Check that node1's mempool is as expected (-> custom ancestor limit)
218217
mempool0 = self.nodes[0].getrawmempool(False)
@@ -308,7 +307,7 @@ def run_test(self):
308307
value = utxo[0]['amount']
309308
vout = utxo[0]['vout']
310309

311-
send_value = satoshi_round((value - fee)/2)
310+
send_value = (value - fee) / 2
312311
inputs = [ {'txid' : txid, 'vout' : vout} ]
313312
outputs = {}
314313
for _ in range(2):

test/functional/test_framework/wallet.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from test_framework.util import (
3434
assert_equal,
3535
assert_greater_than_or_equal,
36-
satoshi_round,
3736
)
3837

3938
DEFAULT_FEE = Decimal("0.0001")
@@ -175,13 +174,12 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
175174
vsize = Decimal(96) # anyone-can-spend
176175
else:
177176
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
178-
send_value = satoshi_round(utxo_to_spend['value'] - fee_rate * (vsize / 1000))
179-
fee = utxo_to_spend['value'] - send_value
177+
send_value = int(COIN * (utxo_to_spend['value'] - fee_rate * (vsize / 1000)))
180178
assert send_value > 0
181179

182180
tx = CTransaction()
183181
tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']), nSequence=sequence)]
184-
tx.vout = [CTxOut(int(send_value * COIN), self._scriptPubKey)]
182+
tx.vout = [CTxOut(send_value, self._scriptPubKey)]
185183
tx.nLockTime = locktime
186184
if not self._address:
187185
# raw script
@@ -200,7 +198,7 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
200198
assert_equal(mempool_valid, tx_info['allowed'])
201199
if mempool_valid:
202200
assert_equal(tx_info['vsize'], vsize)
203-
assert_equal(tx_info['fees']['base'], fee)
201+
assert_equal(tx_info['fees']['base'], utxo_to_spend['value'] - Decimal(send_value) / COIN)
204202
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex, 'tx': tx}
205203

206204
def sendrawtransaction(self, *, from_node, tx_hex):

0 commit comments

Comments
 (0)