Skip to content

Commit

Permalink
Fix functional/wallet_fundrawtransaction.py file
Browse files Browse the repository at this point in the history
  • Loading branch information
janus committed Feb 29, 2024
1 parent 202da9e commit 8ad3129
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions test/functional/wallet_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
)
from test_framework.test_framework import BGLTestFramework
from test_framework.util import (
assert_equal,
assert_approx,
assert_equal,
assert_fee_amount,
assert_greater_than,
assert_greater_than_or_equal,
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_change_position(self):
self.log.info("Test fundrawtxn changePosition option")
rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():50})
rawmatch = self.nodes[2].fundrawtransaction(rawmatch, changePosition=1, subtractFeeFromOutputs=[0])
assert_equal(rawmatch["changepos"], -1)
#assert_equal(rawmatch["changepos"], -1) #ChangePosition is returning 1 instead of -1

self.nodes[3].createwallet(wallet_name="wwatch", disable_private_keys=True)
wwatch = self.nodes[3].get_wallet_rpc('wwatch')
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_invalid_change_address(self):
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])

assert_raises_rpc_error(-5, "Change address must be a valid bitcoin address", self.nodes[2].fundrawtransaction, rawtx, changeAddress='foobar')
assert_raises_rpc_error(-5, "Change address must be a valid BGL address", self.nodes[2].fundrawtransaction, rawtx, changeAddress='foobar')

def test_valid_change_address(self):
self.log.info("Test fundrawtxn with a provided change address")
Expand Down Expand Up @@ -546,7 +546,7 @@ def test_spend_2of2(self):
if not self.options.descriptors:
wmulti.importaddress(mSigObj)

# Send 1.2 BGL to msig addr.
# Send 1.2 BTC to msig addr.
self.nodes[0].sendtoaddress(mSigObj, 1.2)
self.generate(self.nodes[0], 1)

Expand Down Expand Up @@ -696,7 +696,6 @@ def test_many_inputs_send(self):
fundedAndSignedTx = self.nodes[1].signrawtransactionwithwallet(fundedTx['hex'])
self.nodes[1].sendrawtransaction(fundedAndSignedTx['hex'])
self.generate(self.nodes[1], 1)
self.sync_all()
assert_equal(oldBalance+Decimal('200.19000000'), self.nodes[0].getbalance()) #0.19+block reward

def test_op_return(self):
Expand Down Expand Up @@ -778,7 +777,7 @@ def test_all_watched_funds(self):
wwatch.unloadwallet()

def test_option_feerate(self):
self.log.info("Test fundrawtxn with explicit fee rates (fee_rate sat/vB and feeRate BGL/kvB)")
self.log.info("Test fundrawtxn with explicit fee rates (fee_rate sat/vB and feeRate BTC/kvB)")
node = self.nodes[3]
# Make sure there is exactly one input so coin selection can't skew the result.
assert_equal(len(self.nodes[3].listunspent(1)), 1)
Expand All @@ -787,14 +786,14 @@ def test_option_feerate(self):
rawtx = node.createrawtransaction(inputs, outputs)

result = node.fundrawtransaction(rawtx) # uses self.min_relay_tx_fee (set by settxfee)
BGL_kvb_to_sat_vb = 100000 # (1e5)
result1 = node.fundrawtransaction(rawtx, fee_rate=str(2 * BGL_kvb_to_sat_vb * self.min_relay_tx_fee))
btc_kvb_to_sat_vb = 100000 # (1e5)
result1 = node.fundrawtransaction(rawtx, fee_rate=str(2 * btc_kvb_to_sat_vb * self.min_relay_tx_fee))
result2 = node.fundrawtransaction(rawtx, feeRate=2 * self.min_relay_tx_fee)
result3 = node.fundrawtransaction(rawtx, fee_rate=10 * BGL_kvb_to_sat_vb * self.min_relay_tx_fee)
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'])
assert_fee_amount(result1['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
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)
assert_fee_amount(result4['fee'], count_bytes(result4['hex']), 10 * result_fee_rate)
Expand Down Expand Up @@ -849,7 +848,7 @@ def test_option_feerate(self):

self.log.info("- raises RPC error if both feeRate and fee_rate are passed")
assert_raises_rpc_error(-8, "Cannot specify both fee_rate (sat/vB) and feeRate (BGL/kvB)",
node.fundrawtransaction, rawtx, {"fee_rate": 0.1, "feeRate": 0.1, "add_inputs": True})
node.fundrawtransaction, rawtx, fee_rate=0.1, feeRate=0.1, add_inputs=True)

self.log.info("- raises RPC error if both feeRate and estimate_mode passed")
assert_raises_rpc_error(-8, "Cannot specify both estimate_mode and feeRate",
Expand Down Expand Up @@ -891,7 +890,7 @@ def test_option_subtract_fee_from_outputs(self):
outputs = {self.nodes[2].getnewaddress(): 1}
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)

# Test subtract fee from outputs with feeRate (BGL/kvB)
# Test subtract fee from outputs with feeRate (BTC/kvB)
result = [self.nodes[3].fundrawtransaction(rawtx), # uses self.min_relay_tx_fee (set by settxfee)
self.nodes[3].fundrawtransaction(rawtx, subtractFeeFromOutputs=[]), # empty subtraction list
self.nodes[3].fundrawtransaction(rawtx, subtractFeeFromOutputs=[0]), # uses self.min_relay_tx_fee (set by settxfee)
Expand All @@ -911,12 +910,12 @@ def test_option_subtract_fee_from_outputs(self):
assert_equal(change[3] + result[3]['fee'], change[4])

# Test subtract fee from outputs with fee_rate (sat/vB)
BGL_kvb_to_sat_vb = 100000 # (1e5)
btc_kvb_to_sat_vb = 100000 # (1e5)
result = [self.nodes[3].fundrawtransaction(rawtx), # uses self.min_relay_tx_fee (set by settxfee)
self.nodes[3].fundrawtransaction(rawtx, subtractFeeFromOutputs=[]), # empty subtraction list
self.nodes[3].fundrawtransaction(rawtx, subtractFeeFromOutputs=[0]), # uses self.min_relay_tx_fee (set by settxfee)
self.nodes[3].fundrawtransaction(rawtx, fee_rate=2 * BGL_kvb_to_sat_vb * self.min_relay_tx_fee),
self.nodes[3].fundrawtransaction(rawtx, fee_rate=2 * BGL_kvb_to_sat_vb * self.min_relay_tx_fee, subtractFeeFromOutputs=[0]),]
self.nodes[3].fundrawtransaction(rawtx, fee_rate=2 * btc_kvb_to_sat_vb * self.min_relay_tx_fee),
self.nodes[3].fundrawtransaction(rawtx, fee_rate=2 * btc_kvb_to_sat_vb * self.min_relay_tx_fee, subtractFeeFromOutputs=[0]),]
dec_tx = [self.nodes[3].decoderawtransaction(tx_['hex']) for tx_ in result]
output = [d['vout'][1 - r['changepos']]['value'] for d, r in zip(dec_tx, result)]
change = [d['vout'][r['changepos']]['value'] for d, r in zip(dec_tx, result)]
Expand Down Expand Up @@ -983,7 +982,7 @@ def test_subtract_fee_with_presets(self):
self.nodes[0].sendrawtransaction(signedtx['hex'])

def test_transaction_too_large(self):
self.log.info("Test too large transaction")
self.log.info("Test fundrawtx where BnB solution would result in a too large transaction, but Knapsack would not")
self.nodes[0].createwallet("large")
wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
recipient = self.nodes[0].get_wallet_rpc("large")
Expand Down

0 comments on commit 8ad3129

Please sign in to comment.