@@ -83,61 +83,6 @@ def relative_locktime(sdf, srhb, stf, srlb):
83
83
def all_rlt_txs (txs ):
84
84
return [tx ['tx' ] for tx in txs ]
85
85
86
- def create_self_transfer_from_utxo (node , input_tx ):
87
- utxo = miniwallet .get_utxo (txid = input_tx .rehash (), mark_as_spent = False )
88
- tx = miniwallet .create_self_transfer (from_node = node , utxo_to_spend = utxo )['tx' ]
89
- return tx
90
-
91
- def create_bip112special (node , input , txversion ):
92
- tx = create_self_transfer_from_utxo (node , input )
93
- tx .nVersion = txversion
94
- tx .vin [0 ].scriptSig = CScript ([- 1 , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list (CScript (tx .vin [0 ].scriptSig )))
95
- return tx
96
-
97
- def create_bip112emptystack (node , input , txversion ):
98
- tx = create_self_transfer_from_utxo (node , input )
99
- tx .nVersion = txversion
100
- tx .vin [0 ].scriptSig = CScript ([OP_CHECKSEQUENCEVERIFY ] + list (CScript (tx .vin [0 ].scriptSig )))
101
- return tx
102
-
103
- def send_generic_input_tx (node , coinbases ):
104
- input_txid = node .getblock (coinbases .pop (), 2 )['tx' ][0 ]['txid' ]
105
- utxo_to_spend = miniwallet .get_utxo (txid = input_txid )
106
- return miniwallet .send_self_transfer (from_node = node , utxo_to_spend = utxo_to_spend )['tx' ]
107
-
108
- def create_bip68txs (node , bip68inputs , txversion , locktime_delta = 0 ):
109
- """Returns a list of bip68 transactions with different bits set."""
110
- txs = []
111
- assert len (bip68inputs ) >= 16
112
- for i , (sdf , srhb , stf , srlb ) in enumerate (product (* [[True , False ]] * 4 )):
113
- locktime = relative_locktime (sdf , srhb , stf , srlb )
114
- tx = create_self_transfer_from_utxo (node , bip68inputs [i ])
115
- tx .nVersion = txversion
116
- tx .vin [0 ].nSequence = locktime + locktime_delta
117
- tx .rehash ()
118
- txs .append ({'tx' : tx , 'sdf' : sdf , 'stf' : stf })
119
-
120
- return txs
121
-
122
- def create_bip112txs (node , bip112inputs , varyOP_CSV , txversion , locktime_delta = 0 ):
123
- """Returns a list of bip68 transactions with different bits set."""
124
- txs = []
125
- assert len (bip112inputs ) >= 16
126
- for i , (sdf , srhb , stf , srlb ) in enumerate (product (* [[True , False ]] * 4 )):
127
- locktime = relative_locktime (sdf , srhb , stf , srlb )
128
- tx = create_self_transfer_from_utxo (node , bip112inputs [i ])
129
- if (varyOP_CSV ): # if varying OP_CSV, nSequence is fixed
130
- tx .vin [0 ].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta
131
- else : # vary nSequence instead, OP_CSV is fixed
132
- tx .vin [0 ].nSequence = locktime + locktime_delta
133
- tx .nVersion = txversion
134
- if (varyOP_CSV ):
135
- tx .vin [0 ].scriptSig = CScript ([locktime , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list (CScript (tx .vin [0 ].scriptSig )))
136
- else :
137
- tx .vin [0 ].scriptSig = CScript ([BASE_RELATIVE_LOCKTIME , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list (CScript (tx .vin [0 ].scriptSig )))
138
- tx .rehash ()
139
- txs .append ({'tx' : tx , 'sdf' : sdf , 'stf' : stf })
140
- return txs
141
86
142
87
class BIP68_112_113Test (BitcoinTestFramework ):
143
88
def set_test_params (self ):
@@ -150,6 +95,62 @@ def set_test_params(self):
150
95
]]
151
96
self .supports_cli = False
152
97
98
+ def create_self_transfer_from_utxo (self , input_tx ):
99
+ utxo = self .miniwallet .get_utxo (txid = input_tx .rehash (), mark_as_spent = False )
100
+ tx = self .miniwallet .create_self_transfer (from_node = self .nodes [0 ], utxo_to_spend = utxo )['tx' ]
101
+ return tx
102
+
103
+ def create_bip112special (self , input , txversion ):
104
+ tx = self .create_self_transfer_from_utxo (input )
105
+ tx .nVersion = txversion
106
+ tx .vin [0 ].scriptSig = CScript ([- 1 , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list (CScript (tx .vin [0 ].scriptSig )))
107
+ return tx
108
+
109
+ def create_bip112emptystack (self , input , txversion ):
110
+ tx = self .create_self_transfer_from_utxo (input )
111
+ tx .nVersion = txversion
112
+ tx .vin [0 ].scriptSig = CScript ([OP_CHECKSEQUENCEVERIFY ] + list (CScript (tx .vin [0 ].scriptSig )))
113
+ return tx
114
+
115
+ def send_generic_input_tx (self , coinbases ):
116
+ input_txid = self .nodes [0 ].getblock (coinbases .pop (), 2 )['tx' ][0 ]['txid' ]
117
+ utxo_to_spend = self .miniwallet .get_utxo (txid = input_txid )
118
+ return self .miniwallet .send_self_transfer (from_node = self .nodes [0 ], utxo_to_spend = utxo_to_spend )['tx' ]
119
+
120
+ def create_bip68txs (self , bip68inputs , txversion , locktime_delta = 0 ):
121
+ """Returns a list of bip68 transactions with different bits set."""
122
+ txs = []
123
+ assert len (bip68inputs ) >= 16
124
+ for i , (sdf , srhb , stf , srlb ) in enumerate (product (* [[True , False ]] * 4 )):
125
+ locktime = relative_locktime (sdf , srhb , stf , srlb )
126
+ tx = self .create_self_transfer_from_utxo (bip68inputs [i ])
127
+ tx .nVersion = txversion
128
+ tx .vin [0 ].nSequence = locktime + locktime_delta
129
+ tx .rehash ()
130
+ txs .append ({'tx' : tx , 'sdf' : sdf , 'stf' : stf })
131
+
132
+ return txs
133
+
134
+ def create_bip112txs (self , bip112inputs , varyOP_CSV , txversion , locktime_delta = 0 ):
135
+ """Returns a list of bip68 transactions with different bits set."""
136
+ txs = []
137
+ assert len (bip112inputs ) >= 16
138
+ for i , (sdf , srhb , stf , srlb ) in enumerate (product (* [[True , False ]] * 4 )):
139
+ locktime = relative_locktime (sdf , srhb , stf , srlb )
140
+ tx = self .create_self_transfer_from_utxo (bip112inputs [i ])
141
+ if (varyOP_CSV ): # if varying OP_CSV, nSequence is fixed
142
+ tx .vin [0 ].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta
143
+ else : # vary nSequence instead, OP_CSV is fixed
144
+ tx .vin [0 ].nSequence = locktime + locktime_delta
145
+ tx .nVersion = txversion
146
+ if (varyOP_CSV ):
147
+ tx .vin [0 ].scriptSig = CScript ([locktime , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list (CScript (tx .vin [0 ].scriptSig )))
148
+ else :
149
+ tx .vin [0 ].scriptSig = CScript ([BASE_RELATIVE_LOCKTIME , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list (CScript (tx .vin [0 ].scriptSig )))
150
+ tx .rehash ()
151
+ txs .append ({'tx' : tx , 'sdf' : sdf , 'stf' : stf })
152
+ return txs
153
+
153
154
def generate_blocks (self , number ):
154
155
test_blocks = []
155
156
for _ in range (number ):
@@ -177,14 +178,12 @@ def send_blocks(self, blocks, success=True, reject_reason=None):
177
178
178
179
def run_test (self ):
179
180
self .helper_peer = self .nodes [0 ].add_p2p_connection (P2PDataStore ())
180
- # TODO: store as class member to get rid of global variable
181
- global miniwallet
182
- miniwallet = MiniWallet (self .nodes [0 ], raw_script = True )
181
+ self .miniwallet = MiniWallet (self .nodes [0 ], raw_script = True )
183
182
184
183
self .log .info ("Generate blocks in the past for coinbase outputs." )
185
184
long_past_time = int (time .time ()) - 600 * 1000 # enough to build up to 1000 blocks 10 minutes apart without worrying about getting into the future
186
185
self .nodes [0 ].setmocktime (long_past_time - 100 ) # enough so that the generated blocks will still all be before long_past_time
187
- self .coinbase_blocks = miniwallet .generate (COINBASE_BLOCK_COUNT ) # blocks generated for inputs
186
+ self .coinbase_blocks = self . miniwallet .generate (COINBASE_BLOCK_COUNT ) # blocks generated for inputs
188
187
self .nodes [0 ].setmocktime (0 ) # set time back to present so yielded blocks aren't in the future as we advance last_block_time
189
188
self .tipheight = COINBASE_BLOCK_COUNT # height of the next block to build
190
189
self .last_block_time = long_past_time
@@ -203,31 +202,31 @@ def run_test(self):
203
202
# 16 normal inputs
204
203
bip68inputs = []
205
204
for _ in range (16 ):
206
- bip68inputs .append (send_generic_input_tx ( self .nodes [ 0 ], self .coinbase_blocks ))
205
+ bip68inputs .append (self .send_generic_input_tx ( self .coinbase_blocks ))
207
206
208
207
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
209
208
bip112basicinputs = []
210
209
for _ in range (2 ):
211
210
inputs = []
212
211
for _ in range (16 ):
213
- inputs .append (send_generic_input_tx ( self .nodes [ 0 ], self .coinbase_blocks ))
212
+ inputs .append (self .send_generic_input_tx ( self .coinbase_blocks ))
214
213
bip112basicinputs .append (inputs )
215
214
216
215
# 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
217
216
bip112diverseinputs = []
218
217
for _ in range (2 ):
219
218
inputs = []
220
219
for _ in range (16 ):
221
- inputs .append (send_generic_input_tx ( self .nodes [ 0 ], self .coinbase_blocks ))
220
+ inputs .append (self .send_generic_input_tx ( self .coinbase_blocks ))
222
221
bip112diverseinputs .append (inputs )
223
222
224
223
# 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
225
- bip112specialinput = send_generic_input_tx ( self .nodes [ 0 ], self .coinbase_blocks )
224
+ bip112specialinput = self .send_generic_input_tx ( self .coinbase_blocks )
226
225
# 1 special input with (empty stack) OP_CSV (actually will be prepended to spending scriptSig)
227
- bip112emptystackinput = send_generic_input_tx ( self .nodes [ 0 ], self .coinbase_blocks )
226
+ bip112emptystackinput = self .send_generic_input_tx ( self .coinbase_blocks )
228
227
229
228
# 1 normal input
230
- bip113input = send_generic_input_tx ( self .nodes [ 0 ], self .coinbase_blocks )
229
+ bip113input = self .send_generic_input_tx ( self .coinbase_blocks )
231
230
232
231
self .nodes [0 ].setmocktime (self .last_block_time + 600 )
233
232
inputblockhash = self .nodes [0 ].generate (1 )[0 ] # 1 block generated for inputs to be in chain at height 431
@@ -247,36 +246,36 @@ def run_test(self):
247
246
248
247
# Test both version 1 and version 2 transactions for all tests
249
248
# BIP113 test transaction will be modified before each use to put in appropriate block time
250
- bip113tx_v1 = create_self_transfer_from_utxo ( self .nodes [ 0 ], bip113input )
249
+ bip113tx_v1 = self .create_self_transfer_from_utxo ( bip113input )
251
250
bip113tx_v1 .vin [0 ].nSequence = 0xFFFFFFFE
252
251
bip113tx_v1 .nVersion = 1
253
- bip113tx_v2 = create_self_transfer_from_utxo ( self .nodes [ 0 ], bip113input )
252
+ bip113tx_v2 = self .create_self_transfer_from_utxo ( bip113input )
254
253
bip113tx_v2 .vin [0 ].nSequence = 0xFFFFFFFE
255
254
bip113tx_v2 .nVersion = 2
256
255
257
256
# For BIP68 test all 16 relative sequence locktimes
258
- bip68txs_v1 = create_bip68txs ( self .nodes [ 0 ], bip68inputs , 1 )
259
- bip68txs_v2 = create_bip68txs ( self .nodes [ 0 ], bip68inputs , 2 )
257
+ bip68txs_v1 = self .create_bip68txs ( bip68inputs , 1 )
258
+ bip68txs_v2 = self .create_bip68txs ( bip68inputs , 2 )
260
259
261
260
# For BIP112 test:
262
261
# 16 relative sequence locktimes of 10 against 10 OP_CSV OP_DROP inputs
263
- bip112txs_vary_nSequence_v1 = create_bip112txs ( self .nodes [ 0 ], bip112basicinputs [0 ], False , 1 )
264
- bip112txs_vary_nSequence_v2 = create_bip112txs ( self .nodes [ 0 ], bip112basicinputs [0 ], False , 2 )
262
+ bip112txs_vary_nSequence_v1 = self .create_bip112txs ( bip112basicinputs [0 ], False , 1 )
263
+ bip112txs_vary_nSequence_v2 = self .create_bip112txs ( bip112basicinputs [0 ], False , 2 )
265
264
# 16 relative sequence locktimes of 9 against 10 OP_CSV OP_DROP inputs
266
- bip112txs_vary_nSequence_9_v1 = create_bip112txs ( self .nodes [ 0 ], bip112basicinputs [1 ], False , 1 , - 1 )
267
- bip112txs_vary_nSequence_9_v2 = create_bip112txs ( self .nodes [ 0 ], bip112basicinputs [1 ], False , 2 , - 1 )
265
+ bip112txs_vary_nSequence_9_v1 = self .create_bip112txs ( bip112basicinputs [1 ], False , 1 , - 1 )
266
+ bip112txs_vary_nSequence_9_v2 = self .create_bip112txs ( bip112basicinputs [1 ], False , 2 , - 1 )
268
267
# sequence lock time of 10 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
269
- bip112txs_vary_OP_CSV_v1 = create_bip112txs ( self .nodes [ 0 ], bip112diverseinputs [0 ], True , 1 )
270
- bip112txs_vary_OP_CSV_v2 = create_bip112txs ( self .nodes [ 0 ], bip112diverseinputs [0 ], True , 2 )
268
+ bip112txs_vary_OP_CSV_v1 = self .create_bip112txs ( bip112diverseinputs [0 ], True , 1 )
269
+ bip112txs_vary_OP_CSV_v2 = self .create_bip112txs ( bip112diverseinputs [0 ], True , 2 )
271
270
# sequence lock time of 9 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
272
- bip112txs_vary_OP_CSV_9_v1 = create_bip112txs ( self .nodes [ 0 ], bip112diverseinputs [1 ], True , 1 , - 1 )
273
- bip112txs_vary_OP_CSV_9_v2 = create_bip112txs ( self .nodes [ 0 ], bip112diverseinputs [1 ], True , 2 , - 1 )
271
+ bip112txs_vary_OP_CSV_9_v1 = self .create_bip112txs ( bip112diverseinputs [1 ], True , 1 , - 1 )
272
+ bip112txs_vary_OP_CSV_9_v2 = self .create_bip112txs ( bip112diverseinputs [1 ], True , 2 , - 1 )
274
273
# -1 OP_CSV OP_DROP input
275
- bip112tx_special_v1 = create_bip112special ( self .nodes [ 0 ], bip112specialinput , 1 )
276
- bip112tx_special_v2 = create_bip112special ( self .nodes [ 0 ], bip112specialinput , 2 )
274
+ bip112tx_special_v1 = self .create_bip112special ( bip112specialinput , 1 )
275
+ bip112tx_special_v2 = self .create_bip112special ( bip112specialinput , 2 )
277
276
# (empty stack) OP_CSV input
278
- bip112tx_emptystack_v1 = create_bip112emptystack ( self .nodes [ 0 ], bip112emptystackinput , 1 )
279
- bip112tx_emptystack_v2 = create_bip112emptystack ( self .nodes [ 0 ], bip112emptystackinput , 2 )
277
+ bip112tx_emptystack_v1 = self .create_bip112emptystack ( bip112emptystackinput , 1 )
278
+ bip112tx_emptystack_v2 = self .create_bip112emptystack ( bip112emptystackinput , 2 )
280
279
281
280
self .log .info ("TESTING" )
282
281
0 commit comments