@@ -73,6 +73,12 @@ def get_utxo(self, *, txid=''):
7373
7474 def send_self_transfer (self , * , fee_rate = Decimal ("0.003" ), from_node , utxo_to_spend = None ):
7575 """Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
76+ tx = self .create_self_transfer (fee_rate = fee_rate , from_node = from_node , utxo_to_spend = utxo_to_spend )
77+ self .sendrawtransaction (from_node = from_node , tx_hex = tx ['hex' ])
78+ return tx
79+
80+ def create_self_transfer (self , * , fee_rate = Decimal ("0.003" ), from_node , utxo_to_spend = None , mempool_valid = True ):
81+ """Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
7682 self ._utxos = sorted (self ._utxos , key = lambda k : k ['value' ])
7783 utxo_to_spend = utxo_to_spend or self ._utxos .pop () # Pick the largest utxo (if none provided) and hope it covers the fee
7884 vsize = Decimal (96 )
@@ -88,9 +94,10 @@ def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_sp
8894 tx_hex = tx .serialize ().hex ()
8995
9096 tx_info = from_node .testmempoolaccept ([tx_hex ])[0 ]
91- self .sendrawtransaction (from_node = from_node , tx_hex = tx_hex )
92- assert_equal (tx_info ['vsize' ], vsize )
93- assert_equal (tx_info ['fees' ]['base' ], fee )
97+ assert_equal (mempool_valid , tx_info ['allowed' ])
98+ if mempool_valid :
99+ assert_equal (tx_info ['vsize' ], vsize )
100+ assert_equal (tx_info ['fees' ]['base' ], fee )
94101 return {'txid' : tx_info ['txid' ], 'wtxid' : tx_info ['wtxid' ], 'hex' : tx_hex }
95102
96103 def sendrawtransaction (self , * , from_node , tx_hex ):
0 commit comments