@@ -1079,17 +1079,28 @@ def test_weight_calculation(self):
1079
1079
self .nodes [2 ].createwallet ("test_weight_calculation" )
1080
1080
wallet = self .nodes [2 ].get_wallet_rpc ("test_weight_calculation" )
1081
1081
1082
- addr = wallet .getnewaddress ()
1083
- txid = self .nodes [0 ].sendtoaddress (addr , 5 )
1082
+ addr = wallet .getnewaddress (address_type = "bech32" )
1083
+ ext_addr = self .nodes [0 ].getnewaddress (address_type = "bech32" )
1084
+ txid = self .nodes [0 ].send ([{addr : 5 }, {ext_addr : 5 }])["txid" ]
1084
1085
vout = find_vout_for_address (self .nodes [0 ], txid , addr )
1086
+ ext_vout = find_vout_for_address (self .nodes [0 ], txid , ext_addr )
1085
1087
1086
- self .nodes [0 ].sendtoaddress (wallet .getnewaddress (), 5 )
1088
+ self .nodes [0 ].sendtoaddress (wallet .getnewaddress (address_type = "bech32" ), 5 )
1087
1089
self .generate (self .nodes [0 ], 1 )
1088
1090
1089
- rawtx = wallet .createrawtransaction ([{'txid' : txid , 'vout' : vout }], [{self .nodes [0 ].getnewaddress (): 9.999 }])
1090
- fundedtx = wallet .fundrawtransaction (rawtx , {'fee_rate' : 10 })
1091
+ rawtx = wallet .createrawtransaction ([{'txid' : txid , 'vout' : vout }], [{self .nodes [0 ].getnewaddress (address_type = "bech32" ): 8 }])
1092
+ fundedtx = wallet .fundrawtransaction (rawtx , {'fee_rate' : 10 , "change_type" : "bech32" })
1091
1093
# with 71-byte signatures we should expect following tx size
1092
- tx_size = 10 + 41 * 2 + 31 * 2 + (2 + 107 * 2 )/ 4
1094
+ # tx overhead (10) + 2 inputs (41 each) + 2 p2wpkh (31 each) + (segwit marker and flag (2) + 2 p2wpkh 71 byte sig witnesses (107 each)) / witness scaling factor (4)
1095
+ tx_size = ceil (10 + 41 * 2 + 31 * 2 + (2 + 107 * 2 )/ 4 )
1096
+ assert_equal (fundedtx ['fee' ] * COIN , tx_size * 10 )
1097
+
1098
+ # Using the other output should have 72 byte sigs
1099
+ rawtx = wallet .createrawtransaction ([{'txid' : txid , 'vout' : ext_vout }], [{self .nodes [0 ].getnewaddress (): 13 }])
1100
+ ext_desc = self .nodes [0 ].getaddressinfo (ext_addr )["desc" ]
1101
+ fundedtx = wallet .fundrawtransaction (rawtx , {'fee_rate' : 10 , "change_type" : "bech32" , "solving_data" : {"descriptors" : [ext_desc ]}})
1102
+ # tx overhead (10) + 3 inputs (41 each) + 2 p2wpkh(31 each) + (segwit marker and flag (2) + 2 p2wpkh 71 bytes sig witnesses (107 each) + p2wpkh 72 byte sig witness (108)) / witness scaling factor (4)
1103
+ tx_size = ceil (10 + 41 * 3 + 31 * 2 + (2 + 107 * 2 + 108 )/ 4 )
1093
1104
assert_equal (fundedtx ['fee' ] * COIN , tx_size * 10 )
1094
1105
1095
1106
self .nodes [2 ].unloadwallet ("test_weight_calculation" )
0 commit comments