Skip to content

Commit a73775e

Browse files
committed
Merge #16917: tests: Move common function assert_approx() into util.py
96299a9 Test: Move common function assert_approx() into util.py (fridokus) Pull request description: To reduce code duplication, move `assert_approx` into common framework `util.py`. `assert_approx()` is used in two functional tests. ACKs for top commit: theStack: ACK 96299a9 practicalswift: ACK 96299a9 -- DRY is good and diff looks correct fanquake: ACK 96299a9 - thanks for contributing 🍻 Tree-SHA512: 8e9d397222c49536c7b3d6d0756cc5af17113e5af8707ac48a500fff1811167fb2e03f3c0445b0b9e80f34935f4d57cfb935c4790f6f5463a32a67df5f736939
2 parents 587003d + 96299a9 commit a73775e

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

test/functional/test_framework/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
# Assert functions
2626
##################
2727

28+
def assert_approx(v, vexp, vspan=0.00001):
29+
"""Assert that `v` is within `vspan` of `vexp`"""
30+
if v < vexp - vspan:
31+
raise AssertionError("%s < [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
32+
if v > vexp + vspan:
33+
raise AssertionError("%s > [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
34+
2835
def assert_fee_amount(fee, tx_size, fee_per_kB):
2936
"""Assert the fee was in range"""
3037
target_fee = round(tx_size * fee_per_kB / 1000, 8)

test/functional/wallet_avoidreuse.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@
66

77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import (
9+
assert_approx,
910
assert_equal,
1011
assert_raises_rpc_error,
1112
connect_nodes,
1213
)
1314

14-
# TODO: Copied from wallet_groups.py -- should perhaps move into util.py
15-
def assert_approx(v, vexp, vspan=0.00001):
16-
if v < vexp - vspan:
17-
raise AssertionError("%s < [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
18-
if v > vexp + vspan:
19-
raise AssertionError("%s > [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
20-
2115
def reset_balance(node, discardaddr):
2216
'''Throw away all owned coins by the node so it gets a balance of 0.'''
2317
balance = node.getbalance(avoid_reuse=False)

test/functional/wallet_groups.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@
77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.messages import CTransaction, FromHex, ToHex
99
from test_framework.util import (
10+
assert_approx,
1011
assert_equal,
1112
)
1213

13-
def assert_approx(v, vexp, vspan=0.00001):
14-
if v < vexp - vspan:
15-
raise AssertionError("%s < [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
16-
if v > vexp + vspan:
17-
raise AssertionError("%s > [%s..%s]" % (str(v), str(vexp - vspan), str(vexp + vspan)))
18-
1914
class WalletGroupTest(BitcoinTestFramework):
2015
def set_test_params(self):
2116
self.setup_clean_chain = True

0 commit comments

Comments
 (0)