1111from test_framework .blocktools import (
1212 create_block ,
1313 create_coinbase ,
14- create_transaction ,
1514)
1615from test_framework .messages import (
1716 CTransaction ,
2928from test_framework .util import (
3029 assert_equal ,
3130 assert_raises_rpc_error ,
32- hex_str_to_bytes ,
3331)
34-
35- from io import BytesIO
32+ from test_framework .wallet import MiniWallet
3633
3734CLTV_HEIGHT = 1351
3835
4138# 1) prepending a given script to the scriptSig of vin 0 and
4239# 2) (optionally) modify the nSequence of vin 0 and the tx's nLockTime
4340def cltv_modify_tx (node , tx , prepend_scriptsig , nsequence = None , nlocktime = None ):
41+ assert_equal (len (tx .vin ), 1 )
4442 if nsequence is not None :
4543 tx .vin [0 ].nSequence = nsequence
4644 tx .nLockTime = nlocktime
4745
48- # Need to re-sign, since nSequence and nLockTime changed
49- signed_result = node .signrawtransactionwithwallet (tx .serialize ().hex ())
50- new_tx = CTransaction ()
51- new_tx .deserialize (BytesIO (hex_str_to_bytes (signed_result ['hex' ])))
52- else :
53- new_tx = tx
54-
55- new_tx .vin [0 ].scriptSig = CScript (prepend_scriptsig + list (CScript (new_tx .vin [0 ].scriptSig )))
56- return new_tx
46+ tx .vin [0 ].scriptSig = CScript (prepend_scriptsig + list (CScript (tx .vin [0 ].scriptSig )))
47+ tx .rehash ()
48+ return tx
5749
5850
5951def cltv_invalidate (node , tx , failure_reason ):
@@ -108,27 +100,23 @@ def test_cltv_info(self, *, is_active):
108100 },
109101 )
110102
111- def skip_test_if_missing_module (self ):
112- self .skip_if_no_wallet ()
113-
114103 def run_test (self ):
115104 peer = self .nodes [0 ].add_p2p_connection (P2PInterface ())
105+ wallet = MiniWallet (self .nodes [0 ], raw_script = True )
116106
117107 self .test_cltv_info (is_active = False )
118108
119109 self .log .info ("Mining %d blocks" , CLTV_HEIGHT - 2 )
120- self . coinbase_txids = [ self . nodes [ 0 ]. getblock ( b )[ 'tx' ][ 0 ] for b in self . nodes [ 0 ]. generate (CLTV_HEIGHT - 2 )]
121- self .nodeaddress = self . nodes [0 ].getnewaddress ( )
110+ wallet . generate (10 )
111+ self .nodes [0 ].generate ( CLTV_HEIGHT - 2 - 10 )
122112
123113 self .log .info ("Test that invalid-according-to-CLTV transactions can still appear in a block" )
124114
125115 # create one invalid tx per CLTV failure reason (5 in total) and collect them
126116 invalid_ctlv_txs = []
127117 for i in range (5 ):
128- spendtx = create_transaction (self .nodes [0 ], self .coinbase_txids [i ],
129- self .nodeaddress , amount = 1.0 )
118+ spendtx = wallet .create_self_transfer (from_node = self .nodes [0 ])['tx' ]
130119 spendtx = cltv_invalidate (self .nodes [0 ], spendtx , i )
131- spendtx .rehash ()
132120 invalid_ctlv_txs .append (spendtx )
133121
134122 tip = self .nodes [0 ].getbestblockhash ()
@@ -162,10 +150,8 @@ def run_test(self):
162150
163151 # create and test one invalid tx per CLTV failure reason (5 in total)
164152 for i in range (5 ):
165- spendtx = create_transaction (self .nodes [0 ], self .coinbase_txids [10 + i ],
166- self .nodeaddress , amount = 1.0 )
153+ spendtx = wallet .create_self_transfer (from_node = self .nodes [0 ])['tx' ]
167154 spendtx = cltv_invalidate (self .nodes [0 ], spendtx , i )
168- spendtx .rehash ()
169155
170156 expected_cltv_reject_reason = [
171157 "non-mandatory-script-verify-flag (Operation not valid with the current stack size)" ,
@@ -191,7 +177,6 @@ def run_test(self):
191177
192178 self .log .info ("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted" )
193179 spendtx = cltv_validate (self .nodes [0 ], spendtx , CLTV_HEIGHT - 1 )
194- spendtx .rehash ()
195180
196181 block .vtx .pop (1 )
197182 block .vtx .append (spendtx )
0 commit comments