Skip to content

Commit fa2ac58

Browse files
author
MarcoFalke
committed
test: Replace satoshi_round with int() or Decimal()
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.
1 parent 66d11b1 commit fa2ac58

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

test/functional/feature_bip68_sequence.py

Lines changed: 1 addition & 2 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from test_framework.util import (
3333
assert_equal,
3434
assert_greater_than_or_equal,
35-
satoshi_round,
3635
)
3736

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

181179
tx = CTransaction()
182180
tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']), nSequence=sequence)]
183-
tx.vout = [CTxOut(int(send_value * COIN), self._scriptPubKey)]
181+
tx.vout = [CTxOut(send_value, self._scriptPubKey)]
184182
tx.nLockTime = locktime
185183
if not self._address:
186184
# raw script
@@ -199,7 +197,7 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
199197
assert_equal(mempool_valid, tx_info['allowed'])
200198
if mempool_valid:
201199
assert_equal(tx_info['vsize'], vsize)
202-
assert_equal(tx_info['fees']['base'], fee)
200+
assert_equal(tx_info['fees']['base'], utxo_to_spend['value'] - Decimal(send_value) / COIN)
203201
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex, 'tx': tx}
204202

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

0 commit comments

Comments
 (0)