diff --git a/test/functional/fundrawtransaction.py b/test/functional/fundrawtransaction.py --- a/test/functional/fundrawtransaction.py +++ b/test/functional/fundrawtransaction.py @@ -651,14 +651,18 @@ rawtx) # uses min_relay_tx_fee (set by settxfee) result2 = self.nodes[3].fundrawtransaction( rawtx, {"feeRate": 2 * min_relay_tx_fee}) - result3 = self.nodes[3].fundrawtransaction( - rawtx, {"feeRate": 10 * min_relay_tx_fee}) result_fee_rate = result['fee'] * 1000 / \ FromHex(CTransaction(), result['hex']).billable_size() assert_fee_amount( result2['fee'], FromHex(CTransaction(), result2['hex']).billable_size(), 2 * result_fee_rate) + + result3 = self.nodes[3].fundrawtransaction( + rawtx, {"feeRate": 10 * min_relay_tx_fee}) + # allow this transaction to be underfunded by 10 bytes. This is due + # to the first transaction possibly being overfunded by up to .9 + # satoshi due to fee ceilings being used. assert_fee_amount( - result3['fee'], FromHex(CTransaction(), result3['hex']).billable_size(), 10 * result_fee_rate) + result3['fee'], FromHex(CTransaction(), result3['hex']).billable_size(), 10 * result_fee_rate, 10) # # Test address reuse option # diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -25,14 +25,20 @@ ################## -def assert_fee_amount(fee, tx_size, fee_per_kB): - """Assert the fee was in range""" +def assert_fee_amount(fee, tx_size, fee_per_kB, wiggleroom=2): + """ + Assert the fee was in range + + wiggleroom defines an amount that the test expects the wallet to be off by + when estimating fees. This can be due to the dummy signature that is added + during fee calculation, or due to the wallet funding transactions using the + ceiling of the calculated fee. + """ target_fee = tx_size * fee_per_kB / 1000 - if fee < target_fee: + if fee < (tx_size - wiggleroom) * fee_per_kB / 1000: raise AssertionError( "Fee of %s BTC too low! (Should be %s BTC)" % (str(fee), str(target_fee))) - # allow the wallet's estimation to be at most 2 bytes off - if fee > (tx_size + 2) * fee_per_kB / 1000: + if fee > (tx_size + wiggleroom) * fee_per_kB / 1000: raise AssertionError( "Fee of %s BTC too high! (Should be %s BTC)" % (str(fee), str(target_fee)))