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
- tx = CTransaction ()
51
- tx .deserialize (BytesIO (hex_str_to_bytes (signed_result ['hex' ])))
52
-
53
43
tx .vin [0 ].scriptSig = CScript (prepend_scriptsig + list (CScript (tx .vin [0 ].scriptSig )))
54
44
tx .rehash ()
55
45
return tx
@@ -97,9 +87,6 @@ def set_test_params(self):
97
87
self .setup_clean_chain = True
98
88
self .rpc_timeout = 480
99
89
100
- def skip_test_if_missing_module (self ):
101
- self .skip_if_no_wallet ()
102
-
103
90
def test_cltv_info (self , * , is_active ):
104
91
assert_equal (self .nodes [0 ].getblockchaininfo ()['softforks' ]['bip65' ], {
105
92
"active" : is_active ,
@@ -110,20 +97,20 @@ def test_cltv_info(self, *, is_active):
110
97
111
98
def run_test (self ):
112
99
peer = self .nodes [0 ].add_p2p_connection (P2PInterface ())
100
+ wallet = MiniWallet (self .nodes [0 ], raw_script = True )
113
101
114
102
self .test_cltv_info (is_active = False )
115
103
116
104
self .log .info ("Mining %d blocks" , CLTV_HEIGHT - 2 )
117
- self . coinbase_txids = [ self . nodes [ 0 ]. getblock ( b )[ 'tx' ][ 0 ] for b in self . nodes [ 0 ]. generate (CLTV_HEIGHT - 2 )]
118
- self .nodeaddress = self . nodes [0 ].getnewaddress ( )
105
+ wallet . generate (10 )
106
+ self .nodes [0 ].generate ( CLTV_HEIGHT - 2 - 10 )
119
107
120
108
self .log .info ("Test that invalid-according-to-CLTV transactions can still appear in a block" )
121
109
122
110
# create one invalid tx per CLTV failure reason (5 in total) and collect them
123
111
invalid_ctlv_txs = []
124
112
for i in range (5 ):
125
- spendtx = create_transaction (self .nodes [0 ], self .coinbase_txids [i ],
126
- self .nodeaddress , amount = 1.0 )
113
+ spendtx = wallet .create_self_transfer (from_node = self .nodes [0 ])['tx' ]
127
114
spendtx = cltv_invalidate (self .nodes [0 ], spendtx , i )
128
115
invalid_ctlv_txs .append (spendtx )
129
116
@@ -158,8 +145,7 @@ def run_test(self):
158
145
159
146
# create and test one invalid tx per CLTV failure reason (5 in total)
160
147
for i in range (5 ):
161
- spendtx = create_transaction (self .nodes [0 ], self .coinbase_txids [10 + i ],
162
- self .nodeaddress , amount = 1.0 )
148
+ spendtx = wallet .create_self_transfer (from_node = self .nodes [0 ])['tx' ]
163
149
spendtx = cltv_invalidate (self .nodes [0 ], spendtx , i )
164
150
165
151
expected_cltv_reject_reason = [
0 commit comments