Skip to content

Commit 7832e94

Browse files
committed
test: fundrawtransaction preset input weight calculation
1 parent c3981e3 commit 7832e94

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/functional/rpc_fundrawtransaction.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
from test_framework.descriptors import descsum_create
1313
from test_framework.key import ECKey
14+
from test_framework.messages import (
15+
COIN,
16+
)
1417
from test_framework.test_framework import BitcoinTestFramework
1518
from test_framework.util import (
1619
assert_approx,
@@ -103,6 +106,7 @@ def run_test(self):
103106
self.generate(self.nodes[2], 1)
104107
self.generate(self.nodes[0], 121)
105108

109+
self.test_weight_calculation()
106110
self.test_change_position()
107111
self.test_simple()
108112
self.test_simple_two_coins()
@@ -1069,6 +1073,27 @@ def test_external_inputs(self):
10691073

10701074
self.nodes[2].unloadwallet("extfund")
10711075

1076+
def test_weight_calculation(self):
1077+
self.log.info("Test weight calculation with external inputs")
1078+
1079+
self.nodes[2].createwallet("test_weight_calculation")
1080+
wallet = self.nodes[2].get_wallet_rpc("test_weight_calculation")
1081+
1082+
addr = wallet.getnewaddress()
1083+
txid = self.nodes[0].sendtoaddress(addr, 5)
1084+
vout = find_vout_for_address(self.nodes[0], txid, addr)
1085+
1086+
self.nodes[0].sendtoaddress(wallet.getnewaddress(), 5)
1087+
self.generate(self.nodes[0], 1)
1088+
1089+
rawtx = wallet.createrawtransaction([{'txid': txid, 'vout': vout}], [{self.nodes[0].getnewaddress(): 9.999}])
1090+
fundedtx = wallet.fundrawtransaction(rawtx, {'fee_rate': 10})
1091+
# with 71-byte signatures we should expect following tx size
1092+
tx_size = 10 + 41*2 + 31*2 + (2 + 107*2)/4
1093+
assert_equal(fundedtx['fee'] * COIN, tx_size * 10)
1094+
1095+
self.nodes[2].unloadwallet("test_weight_calculation")
1096+
10721097
def test_include_unsafe(self):
10731098
self.log.info("Test fundrawtxn with unsafe inputs")
10741099

0 commit comments

Comments
 (0)