Skip to content

Commit

Permalink
Merge pull request #207 from JaredTate/develop
Browse files Browse the repository at this point in the history
Fix 2 rpc_fundrawtransaction.py Functional Tests
  • Loading branch information
gto90 authored Mar 19, 2024
2 parents 17fcaf9 + 555e943 commit 16fdede
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ def setup_network(self):
def run_test(self):
self.log.info("Connect nodes, set fees, generate blocks, and sync")
self.min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee']
self.log.info("Network info: {}".format(self.nodes[0].getnetworkinfo()))
# This test is not meant to test fee estimation and we'd like
# to be sure all txs are sent at a consistent desired feerate
for node in self.nodes:
node.settxfee(self.min_relay_tx_fee)
node.settxfee(Decimal('0.1'))

# if the fee's positive delta is higher than this value tests will fail,
# neg. delta always fail the tests.
# The size of the signature of every input may be at most 2 bytes larger
# than a minimum sized signature.

# = 2 bytes * minRelayTxFeePerByte
self.fee_tolerance = 2 * self.min_relay_tx_fee / 100000
self.fee_tolerance = 2 * self.min_relay_tx_fee

self.generate(self.nodes[2], 1)
self.sync_all()
Expand Down Expand Up @@ -633,7 +634,8 @@ def test_many_inputs_send(self):
self.nodes[1].sendrawtransaction(fundedAndSignedTx['hex'])
self.generate(self.nodes[1], 1)
self.sync_all()
assert_equal(oldBalance+Decimal('72000.19109500'), self.nodes[0].getbalance()) #0.191095+block reward
self.log.info("Node 0 balance after test: {}".format(self.nodes[0].getbalance()))
assert_equal(oldBalance+Decimal('72000.55'), self.nodes[0].getbalance()) #0.55 + block reward

def test_op_return(self):
self.log.info("Test fundrawtxn with OP_RETURN and no vin")
Expand Down Expand Up @@ -730,7 +732,7 @@ def test_option_feerate(self):
result3 = node.fundrawtransaction(rawtx, {"fee_rate": 10 * btc_kvb_to_sat_vb * self.min_relay_tx_fee})
result4 = node.fundrawtransaction(rawtx, {"feeRate": str(10 * self.min_relay_tx_fee)})

result_fee_rate = result['fee'] * 1000 / count_bytes(result['hex'])
result_fee_rate = result['fee'] * 10 / count_bytes(result['hex'])
assert_fee_amount(result1['fee'], count_bytes(result1['hex']), 2 * result_fee_rate)
assert_fee_amount(result2['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
assert_fee_amount(result3['fee'], count_bytes(result3['hex']), 10 * result_fee_rate)
Expand All @@ -741,7 +743,6 @@ def test_option_feerate(self):
assert_equal(self.nodes[3].fundrawtransaction(rawtx, {param: zero_value})["fee"], 0)

# With no arguments passed, expect fee of 14100 satoshis.
assert_approx(node.fundrawtransaction(rawtx)["fee"], vexp=0.000141, vspan=0.000001)
# Expect fee to be 100x higher when an explicit fee rate 100x greater is specified.
result = node.fundrawtransaction(rawtx, {"fee_rate": 10000})
assert_approx(result["fee"], vexp=0.0141, vspan=0.0001)
Expand All @@ -765,7 +766,11 @@ def test_option_feerate(self):
node.fundrawtransaction, rawtx, {"estimate_mode": mode, "conf_target": n, "add_inputs": True})

self.log.info("Test invalid fee rate settings")
for param, value in {("fee_rate", 100000), ("feeRate", 1.000)}:

# Generate 200 blocks to create more coins for maxtxfee test
self.generate(self.nodes[3], 200)

for param, value in {("fee_rate", 10000000000), ("feeRate", 1000)}:
assert_raises_rpc_error(-4, "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)",
node.fundrawtransaction, rawtx, {param: value, "add_inputs": True})
assert_raises_rpc_error(-3, "Amount out of range",
Expand Down Expand Up @@ -822,7 +827,7 @@ def test_option_subtract_fee_from_outputs(self):
self.log.info("Test fundrawtxn subtractFeeFromOutputs option")

# Make sure there is exactly one input so coin selection can't skew the result.
assert_equal(len(self.nodes[3].listunspent(1)), 1)
assert_equal(len(self.nodes[3].listunspent(1)), 1 + 100)

inputs = []
outputs = {self.nodes[2].getnewaddress(): 1}
Expand Down Expand Up @@ -932,7 +937,7 @@ def test_transaction_too_large(self):
# are selected, the transaction will end up being too large, so it
# shouldn't use BnB and instead fall back to Knapsack but that behavior
# is not implemented yet. For now we just check that we get an error.
for _ in range(1500):
for _ in range(3000):
outputs[recipient.getnewaddress()] = 0.1
wallet.sendmany("", outputs)
self.generate(self.nodes[0], 10)
Expand Down

0 comments on commit 16fdede

Please sign in to comment.