aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-10-07 09:09:04 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-10-07 09:09:11 +0200
commitb4437d7dfe23a7a6a39b4a3bd5cb04f017d668c8 (patch)
tree44ba40fd5c07662ac8710bbd0fd5921a28393b1e /test
parentf8911de619d41a3cc21771d62ab077713f1405c5 (diff)
parentfa2ac5881edf8d0d3f15c43f089f1831348dfae2 (diff)
downloadbitcoin-b4437d7dfe23a7a6a39b4a3bd5cb04f017d668c8.tar.xz
Merge bitcoin/bitcoin#23210: test: Replace satoshi_round with int() or Decimal()
fa2ac5881edf8d0d3f15c43f089f1831348dfae2 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 https://github.com/bitcoin/bitcoin/pull/23210/commits/fa2ac5881edf8d0d3f15c43f089f1831348dfae2 on Ubuntu 20.04. Tree-SHA512: 17795d906aa7652933d43e510e993cdd9cf8926da1febf1c42d463048cb38c92dc518ec08736efe29c0189ffd532b108bc7a715f32b4c2ee58b215df65352eb9
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_bip68_sequence.py3
-rwxr-xr-xtest/functional/mempool_packages.py9
-rw-r--r--test/functional/test_framework/wallet.py8
3 files changed, 8 insertions, 12 deletions
diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py
index ee2c71cd42..99ac1b5884 100755
--- a/test/functional/feature_bip68_sequence.py
+++ b/test/functional/feature_bip68_sequence.py
@@ -24,7 +24,6 @@ from test_framework.util import (
assert_equal,
assert_greater_than,
assert_raises_rpc_error,
- satoshi_round,
softfork_active,
)
from test_framework.script_util import DUMMY_P2WPKH_SCRIPT
@@ -94,7 +93,7 @@ class BIP68Test(BitcoinTestFramework):
utxo = utxos[0]
tx1 = CTransaction()
- value = int(satoshi_round(utxo["amount"] - self.relayfee)*COIN)
+ value = int((utxo["amount"] - self.relayfee) * COIN)
# Check that the disable flag disables relative locktime.
# If sequence locks were used, this would require 1 block for the
diff --git a/test/functional/mempool_packages.py b/test/functional/mempool_packages.py
index c042961937..3943bba489 100755
--- a/test/functional/mempool_packages.py
+++ b/test/functional/mempool_packages.py
@@ -14,7 +14,6 @@ from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
chain_transaction,
- satoshi_round,
)
# default limits
@@ -209,10 +208,10 @@ class MempoolPackagesTest(BitcoinTestFramework):
entry = self.nodes[0].getmempoolentry(x)
descendant_fees += entry['fee']
if (x == chain[-1]):
- assert_equal(entry['modifiedfee'], entry['fee']+satoshi_round(0.00002))
- assert_equal(entry['fees']['modified'], entry['fee']+satoshi_round(0.00002))
+ assert_equal(entry['modifiedfee'], entry['fee'] + Decimal("0.00002"))
+ assert_equal(entry['fees']['modified'], entry['fee'] + Decimal("0.00002"))
assert_equal(entry['descendantfees'], descendant_fees * COIN + 2000)
- assert_equal(entry['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
+ assert_equal(entry['fees']['descendant'], descendant_fees + Decimal("0.00002"))
# Check that node1's mempool is as expected (-> custom ancestor limit)
mempool0 = self.nodes[0].getrawmempool(False)
@@ -308,7 +307,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
value = utxo[0]['amount']
vout = utxo[0]['vout']
- send_value = satoshi_round((value - fee)/2)
+ send_value = (value - fee) / 2
inputs = [ {'txid' : txid, 'vout' : vout} ]
outputs = {}
for _ in range(2):
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py
index a0843b796a..d597af5883 100644
--- a/test/functional/test_framework/wallet.py
+++ b/test/functional/test_framework/wallet.py
@@ -33,7 +33,6 @@ from test_framework.script_util import key_to_p2wpkh_script
from test_framework.util import (
assert_equal,
assert_greater_than_or_equal,
- satoshi_round,
)
DEFAULT_FEE = Decimal("0.0001")
@@ -175,13 +174,12 @@ class MiniWallet:
vsize = Decimal(96) # anyone-can-spend
else:
vsize = Decimal(168) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
- send_value = satoshi_round(utxo_to_spend['value'] - fee_rate * (vsize / 1000))
- fee = utxo_to_spend['value'] - send_value
+ send_value = int(COIN * (utxo_to_spend['value'] - fee_rate * (vsize / 1000)))
assert send_value > 0
tx = CTransaction()
tx.vin = [CTxIn(COutPoint(int(utxo_to_spend['txid'], 16), utxo_to_spend['vout']), nSequence=sequence)]
- tx.vout = [CTxOut(int(send_value * COIN), self._scriptPubKey)]
+ tx.vout = [CTxOut(send_value, self._scriptPubKey)]
tx.nLockTime = locktime
if not self._address:
# raw script
@@ -200,7 +198,7 @@ class MiniWallet:
assert_equal(mempool_valid, tx_info['allowed'])
if mempool_valid:
assert_equal(tx_info['vsize'], vsize)
- assert_equal(tx_info['fees']['base'], fee)
+ assert_equal(tx_info['fees']['base'], utxo_to_spend['value'] - Decimal(send_value) / COIN)
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex, 'tx': tx}
def sendrawtransaction(self, *, from_node, tx_hex):