|
11 | 11 |
|
12 | 12 | from test_framework.descriptors import descsum_create
|
13 | 13 | from test_framework.key import ECKey
|
| 14 | +from test_framework.messages import ( |
| 15 | + COIN, |
| 16 | +) |
14 | 17 | from test_framework.test_framework import BitcoinTestFramework
|
15 | 18 | from test_framework.util import (
|
16 | 19 | assert_approx,
|
@@ -103,6 +106,7 @@ def run_test(self):
|
103 | 106 | self.generate(self.nodes[2], 1)
|
104 | 107 | self.generate(self.nodes[0], 121)
|
105 | 108 |
|
| 109 | + self.test_weight_calculation() |
106 | 110 | self.test_change_position()
|
107 | 111 | self.test_simple()
|
108 | 112 | self.test_simple_two_coins()
|
@@ -1069,6 +1073,27 @@ def test_external_inputs(self):
|
1069 | 1073 |
|
1070 | 1074 | self.nodes[2].unloadwallet("extfund")
|
1071 | 1075 |
|
| 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 | + |
1072 | 1097 | def test_include_unsafe(self):
|
1073 | 1098 | self.log.info("Test fundrawtxn with unsafe inputs")
|
1074 | 1099 |
|
|
0 commit comments