11
11
from test_framework .blocktools import (
12
12
create_block ,
13
13
create_coinbase ,
14
- create_transaction ,
15
14
)
16
15
from test_framework .messages import (
17
16
CTransaction ,
18
- ToHex ,
19
17
msg_block ,
20
18
)
21
19
from test_framework .p2p import P2PInterface
27
25
OP_DROP ,
28
26
)
29
27
from test_framework .test_framework import BitcoinTestFramework
30
- from test_framework .util import (
31
- assert_equal ,
32
- hex_str_to_bytes ,
33
- )
34
-
35
- from io import BytesIO
28
+ from test_framework .util import assert_equal
29
+ from test_framework .wallet import MiniWallet
36
30
37
31
CLTV_HEIGHT = 1351
38
32
41
35
# 1) prepending a given script to the scriptSig of vin 0 and
42
36
# 2) (optionally) modify the nSequence of vin 0 and the tx's nLockTime
43
37
def cltv_modify_tx (node , tx , prepend_scriptsig , nsequence = None , nlocktime = None ):
38
+ assert_equal (len (tx .vin ), 1 )
44
39
if nsequence is not None :
45
40
tx .vin [0 ].nSequence = nsequence
46
41
tx .nLockTime = nlocktime
47
42
48
- # Need to re-sign, since nSequence and nLockTime changed
49
- signed_result = node .signrawtransactionwithwallet (ToHex (tx ))
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
43
+ tx .vin [0 ].scriptSig = CScript (prepend_scriptsig + list (CScript (tx .vin [0 ].scriptSig )))
44
+ tx .rehash ()
45
+ return tx
57
46
58
47
59
48
def cltv_invalidate (node , tx , failure_reason ):
@@ -98,9 +87,6 @@ def set_test_params(self):
98
87
self .setup_clean_chain = True
99
88
self .rpc_timeout = 480
100
89
101
- def skip_test_if_missing_module (self ):
102
- self .skip_if_no_wallet ()
103
-
104
90
def test_cltv_info (self , * , is_active ):
105
91
assert_equal (self .nodes [0 ].getblockchaininfo ()['softforks' ]['bip65' ], {
106
92
"active" : is_active ,
@@ -111,22 +97,21 @@ def test_cltv_info(self, *, is_active):
111
97
112
98
def run_test (self ):
113
99
peer = self .nodes [0 ].add_p2p_connection (P2PInterface ())
100
+ wallet = MiniWallet (self .nodes [0 ], raw_script = True )
114
101
115
102
self .test_cltv_info (is_active = False )
116
103
117
104
self .log .info ("Mining %d blocks" , CLTV_HEIGHT - 2 )
118
- self . coinbase_txids = [ self . nodes [ 0 ]. getblock ( b )[ 'tx' ][ 0 ] for b in self . nodes [ 0 ]. generate (CLTV_HEIGHT - 2 )]
119
- self .nodeaddress = self . nodes [0 ].getnewaddress ( )
105
+ wallet . generate (10 )
106
+ self .nodes [0 ].generate ( CLTV_HEIGHT - 2 - 10 )
120
107
121
108
self .log .info ("Test that invalid-according-to-CLTV transactions can still appear in a block" )
122
109
123
110
# create one invalid tx per CLTV failure reason (5 in total) and collect them
124
111
invalid_ctlv_txs = []
125
112
for i in range (5 ):
126
- spendtx = create_transaction (self .nodes [0 ], self .coinbase_txids [i ],
127
- self .nodeaddress , amount = 1.0 )
113
+ spendtx = wallet .create_self_transfer (from_node = self .nodes [0 ])['tx' ]
128
114
spendtx = cltv_invalidate (self .nodes [0 ], spendtx , i )
129
- spendtx .rehash ()
130
115
invalid_ctlv_txs .append (spendtx )
131
116
132
117
tip = self .nodes [0 ].getbestblockhash ()
@@ -160,10 +145,8 @@ def run_test(self):
160
145
161
146
# create and test one invalid tx per CLTV failure reason (5 in total)
162
147
for i in range (5 ):
163
- spendtx = create_transaction (self .nodes [0 ], self .coinbase_txids [10 + i ],
164
- self .nodeaddress , amount = 1.0 )
148
+ spendtx = wallet .create_self_transfer (from_node = self .nodes [0 ])['tx' ]
165
149
spendtx = cltv_invalidate (self .nodes [0 ], spendtx , i )
166
- spendtx .rehash ()
167
150
168
151
expected_cltv_reject_reason = [
169
152
"non-mandatory-script-verify-flag (Operation not valid with the current stack size)" ,
@@ -197,7 +180,6 @@ def run_test(self):
197
180
198
181
self .log .info ("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted" )
199
182
spendtx = cltv_validate (self .nodes [0 ], spendtx , CLTV_HEIGHT - 1 )
200
- spendtx .rehash ()
201
183
202
184
block .vtx .pop (1 )
203
185
block .vtx .append (spendtx )
0 commit comments