Dash Core  0.12.2.1
P2P Digital Currency
bip68-112-113-p2p.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 # Copyright (c) 2015 The Bitcoin Core developers
3 # Distributed under the MIT/X11 software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #
6 
7 from test_framework.test_framework import ComparisonTestFramework
8 from test_framework.util import *
9 from test_framework.mininode import ToHex, CTransaction, NetworkThread
10 from test_framework.blocktools import create_coinbase, create_block
11 from test_framework.comptool import TestInstance, TestManager
12 from test_framework.script import *
13 from io import BytesIO
14 import time
15 
16 '''
17 This test is meant to exercise activation of the first version bits soft fork
18 This soft fork will activate the following BIPS:
19 BIP 68 - nSequence relative lock times
20 BIP 112 - CHECKSEQUENCEVERIFY
21 BIP 113 - MedianTimePast semantics for nLockTime
22 
23 regtest lock-in with 108/144 block signalling
24 activation after a further 144 blocks
25 
26 mine 82 blocks whose coinbases will be used to generate inputs for our tests
27 mine 61 blocks to transition from DEFINED to STARTED
28 mine 144 blocks only 100 of which are signaling readiness in order to fail to change state this period
29 mine 144 blocks with 108 signaling and verify STARTED->LOCKED_IN
30 mine 140 blocks and seed block chain with the 82 inputs will use for our tests at height 572
31 mine 3 blocks and verify still at LOCKED_IN and test that enforcement has not triggered
32 mine 1 block and test that enforcement has triggered (which triggers ACTIVE)
33 Test BIP 113 is enforced
34 Mine 4 blocks so next height is 580 and test BIP 68 is enforced for time and height
35 Mine 1 block so next height is 581 and test BIP 68 now passes time but not height
36 Mine 1 block so next height is 582 and test BIP 68 now passes time and height
37 Test that BIP 112 is enforced
38 
39 Various transactions will be used to test that the BIPs rules are not enforced before the soft fork activates
40 And that after the soft fork activates transactions pass and fail as they should according to the rules.
41 For each BIP, transactions of versions 1 and 2 will be tested.
42 ----------------
43 BIP 113:
44 bip113tx - modify the nLocktime variable
45 
46 BIP 68:
47 bip68txs - 16 txs with nSequence relative locktime of 10 with various bits set as per the relative_locktimes below
48 
49 BIP 112:
50 bip112txs_vary_nSequence - 16 txs with nSequence relative_locktimes of 10 evaluated against 10 OP_CSV OP_DROP
51 bip112txs_vary_nSequence_9 - 16 txs with nSequence relative_locktimes of 9 evaluated against 10 OP_CSV OP_DROP
52 bip112txs_vary_OP_CSV - 16 txs with nSequence = 10 evaluated against varying {relative_locktimes of 10} OP_CSV OP_DROP
53 bip112txs_vary_OP_CSV_9 - 16 txs with nSequence = 9 evaluated against varying {relative_locktimes of 10} OP_CSV OP_DROP
54 bip112tx_special - test negative argument to OP_CSV
55 '''
56 
57 base_relative_locktime = 10
58 seq_disable_flag = 1<<31
59 seq_random_high_bit = 1<<25
60 seq_type_flag = 1<<22
61 seq_random_low_bit = 1<<18
62 
63 # b31,b25,b22,b18 represent the 31st, 25th, 22nd and 18th bits respectively in the nSequence field
64 # relative_locktimes[b31][b25][b22][b18] is a base_relative_locktime with the indicated bits set if their indices are 1
65 relative_locktimes = []
66 for b31 in xrange(2):
67  b25times = []
68  for b25 in xrange(2):
69  b22times = []
70  for b22 in xrange(2):
71  b18times = []
72  for b18 in xrange(2):
73  rlt = base_relative_locktime
74  if (b31):
75  rlt = rlt | seq_disable_flag
76  if (b25):
77  rlt = rlt | seq_random_high_bit
78  if (b22):
79  rlt = rlt | seq_type_flag
80  if (b18):
81  rlt = rlt | seq_random_low_bit
82  b18times.append(rlt)
83  b22times.append(b18times)
84  b25times.append(b22times)
85  relative_locktimes.append(b25times)
86 
87 def all_rlt_txs(txarray):
88  txs = []
89  for b31 in xrange(2):
90  for b25 in xrange(2):
91  for b22 in xrange(2):
92  for b18 in xrange(2):
93  txs.append(txarray[b31][b25][b22][b18])
94  return txs
95 
97  def __init__(self):
98  self.num_nodes = 1
99 
100  def setup_network(self):
101  # Must set the blockversion for this test
102  self.nodes = start_nodes(1, self.options.tmpdir,
103  extra_args=[['-debug', '-whitelist=127.0.0.1', '-blockversion=4']],
104  binary=[self.options.testbinary])
105 
106  def run_test(self):
107  test = TestManager(self, self.options.tmpdir)
108  test.add_all_connections(self.nodes)
109  NetworkThread().start() # Start up network handling in another thread
110  test.run()
111 
112  def send_generic_input_tx(self, node, coinbases):
113  amount = Decimal("499.99")
114  return node.sendrawtransaction(ToHex(self.sign_transaction(node, self.create_transaction(node, node.getblock(coinbases.pop())['tx'][0], self.nodeaddress, amount))))
115 
116  def create_transaction(self, node, txid, to_address, amount):
117  inputs = [{ "txid" : txid, "vout" : 0}]
118  outputs = { to_address : amount }
119  rawtx = node.createrawtransaction(inputs, outputs)
120  tx = CTransaction()
121  f = BytesIO(hex_str_to_bytes(rawtx))
122  tx.deserialize(f)
123  return tx
124 
125  def sign_transaction(self, node, unsignedtx):
126  rawtx = ToHex(unsignedtx)
127  signresult = node.signrawtransaction(rawtx)
128  tx = CTransaction()
129  f = BytesIO(hex_str_to_bytes(signresult['hex']))
130  tx.deserialize(f)
131  return tx
132 
133  def generate_blocks(self, number, version, test_blocks = []):
134  for i in xrange(number):
135  block = self.create_test_block([], version)
136  test_blocks.append([block, True])
137  self.last_block_time += 600
138  self.tip = block.sha256
139  self.tipheight += 1
140  return test_blocks
141 
142  def create_test_block(self, txs, version = 536870912):
143  block = create_block(self.tip, create_coinbase(self.tipheight + 1), self.last_block_time + 600)
144  block.nVersion = version
145  block.vtx.extend(txs)
146  block.hashMerkleRoot = block.calc_merkle_root()
147  block.rehash()
148  block.solve()
149  return block
150 
151  def create_bip68txs(self, bip68inputs, txversion, locktime_delta = 0):
152  txs = []
153  assert(len(bip68inputs) >= 16)
154  i = 0
155  for b31 in xrange(2):
156  b25txs = []
157  for b25 in xrange(2):
158  b22txs = []
159  for b22 in xrange(2):
160  b18txs = []
161  for b18 in xrange(2):
162  tx = self.create_transaction(self.nodes[0], bip68inputs[i], self.nodeaddress, Decimal("499.98"))
163  i += 1
164  tx.nVersion = txversion
165  tx.vin[0].nSequence = relative_locktimes[b31][b25][b22][b18] + locktime_delta
166  b18txs.append(self.sign_transaction(self.nodes[0], tx))
167  b22txs.append(b18txs)
168  b25txs.append(b22txs)
169  txs.append(b25txs)
170  return txs
171 
172  def create_bip112special(self, input, txversion):
173  tx = self.create_transaction(self.nodes[0], input, self.nodeaddress, Decimal("499.98"))
174  tx.nVersion = txversion
175  signtx = self.sign_transaction(self.nodes[0], tx)
176  signtx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig)))
177  return signtx
178 
179  def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta = 0):
180  txs = []
181  assert(len(bip112inputs) >= 16)
182  i = 0
183  for b31 in xrange(2):
184  b25txs = []
185  for b25 in xrange(2):
186  b22txs = []
187  for b22 in xrange(2):
188  b18txs = []
189  for b18 in xrange(2):
190  tx = self.create_transaction(self.nodes[0], bip112inputs[i], self.nodeaddress, Decimal("499.98"))
191  i += 1
192  if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed
193  tx.vin[0].nSequence = base_relative_locktime + locktime_delta
194  else: # vary nSequence instead, OP_CSV is fixed
195  tx.vin[0].nSequence = relative_locktimes[b31][b25][b22][b18] + locktime_delta
196  tx.nVersion = txversion
197  signtx = self.sign_transaction(self.nodes[0], tx)
198  if (varyOP_CSV):
199  signtx.vin[0].scriptSig = CScript([relative_locktimes[b31][b25][b22][b18], OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig)))
200  else:
201  signtx.vin[0].scriptSig = CScript([base_relative_locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig)))
202  b18txs.append(signtx)
203  b22txs.append(b18txs)
204  b25txs.append(b22txs)
205  txs.append(b25txs)
206  return txs
207 
208  def get_tests(self):
209  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
210  self.nodes[0].setmocktime(long_past_time - 100) # enough so that the generated blocks will still all be before long_past_time
211  self.coinbase_blocks = self.nodes[0].generate(1 + 16 + 2*32 + 1) # 82 blocks generated for inputs
212  self.nodes[0].setmocktime(0) # set time back to present so yielded blocks aren't in the future as we advance last_block_time
213  self.tipheight = 82 # height of the next block to build
214  self.last_block_time = long_past_time
215  self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
216  self.nodeaddress = self.nodes[0].getnewaddress()
217 
218  assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'defined')
219  test_blocks = self.generate_blocks(61, 4)
220  yield TestInstance(test_blocks, sync_every_block=False) # 1
221  # Advanced from DEFINED to STARTED, height = 143
222  assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started')
223 
224  # Fail to achieve LOCKED_IN 100 out of 144 signal bit 0
225  # using a variety of bits to simulate multiple parallel softforks
226  test_blocks = self.generate_blocks(50, 536870913) # 0x20000001 (signalling ready)
227  test_blocks = self.generate_blocks(20, 4, test_blocks) # 0x00000004 (signalling not)
228  test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready)
229  test_blocks = self.generate_blocks(24, 536936448, test_blocks) # 0x20010000 (signalling not)
230  yield TestInstance(test_blocks, sync_every_block=False) # 2
231  # Failed to advance past STARTED, height = 287
232  assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started')
233 
234  # 108 out of 144 signal bit 0 to achieve lock-in
235  # using a variety of bits to simulate multiple parallel softforks
236  test_blocks = self.generate_blocks(58, 536870913) # 0x20000001 (signalling ready)
237  test_blocks = self.generate_blocks(26, 4, test_blocks) # 0x00000004 (signalling not)
238  test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready)
239  test_blocks = self.generate_blocks(10, 536936448, test_blocks) # 0x20010000 (signalling not)
240  yield TestInstance(test_blocks, sync_every_block=False) # 3
241  # Advanced from STARTED to LOCKED_IN, height = 431
242  assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in')
243 
244  # 140 more version 4 blocks
245  test_blocks = self.generate_blocks(140, 4)
246  yield TestInstance(test_blocks, sync_every_block=False) # 4
247 
248 
252  bip68inputs = []
253  for i in xrange(16):
254  bip68inputs.append(self.send_generic_input_tx(self.nodes[0], self.coinbase_blocks))
255  # 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
256  bip112basicinputs = []
257  for j in xrange(2):
258  inputs = []
259  for i in xrange(16):
260  inputs.append(self.send_generic_input_tx(self.nodes[0], self.coinbase_blocks))
261  bip112basicinputs.append(inputs)
262  # 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
263  bip112diverseinputs = []
264  for j in xrange(2):
265  inputs = []
266  for i in xrange(16):
267  inputs.append(self.send_generic_input_tx(self.nodes[0], self.coinbase_blocks))
268  bip112diverseinputs.append(inputs)
269  # 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
270  bip112specialinput = self.send_generic_input_tx(self.nodes[0], self.coinbase_blocks)
271  # 1 normal input
272  bip113input = self.send_generic_input_tx(self.nodes[0], self.coinbase_blocks)
273 
274  self.nodes[0].setmocktime(self.last_block_time + 600)
275  inputblockhash = self.nodes[0].generate(1)[0] # 1 block generated for inputs to be in chain at height 572
276  self.nodes[0].setmocktime(0)
277  self.tip = int("0x" + inputblockhash + "L", 0)
278  self.tipheight += 1
279  self.last_block_time += 600
280  assert_equal(len(self.nodes[0].getblock(inputblockhash,True)["tx"]), 82+1)
281 
282  # 2 more version 4 blocks
283  test_blocks = self.generate_blocks(2, 4)
284  yield TestInstance(test_blocks, sync_every_block=False) # 5
285  # Not yet advanced to ACTIVE, height = 574 (will activate for block 576, not 575)
286  assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in')
287 
288  # Test both version 1 and version 2 transactions for all tests
289  # BIP113 test transaction will be modified before each use to put in appropriate block time
290  bip113tx_v1 = self.create_transaction(self.nodes[0], bip113input, self.nodeaddress, Decimal("499.98"))
291  bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE
292  bip113tx_v2 = self.create_transaction(self.nodes[0], bip113input, self.nodeaddress, Decimal("499.98"))
293  bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE
294  bip113tx_v2.nVersion = 2
295 
296  # For BIP68 test all 16 relative sequence locktimes
297  bip68txs_v1 = self.create_bip68txs(bip68inputs, 1)
298  bip68txs_v2 = self.create_bip68txs(bip68inputs, 2)
299 
300  # For BIP112 test:
301  # 16 relative sequence locktimes of 10 against 10 OP_CSV OP_DROP inputs
302  bip112txs_vary_nSequence_v1 = self.create_bip112txs(bip112basicinputs[0], False, 1)
303  bip112txs_vary_nSequence_v2 = self.create_bip112txs(bip112basicinputs[0], False, 2)
304  # 16 relative sequence locktimes of 9 against 10 OP_CSV OP_DROP inputs
305  bip112txs_vary_nSequence_9_v1 = self.create_bip112txs(bip112basicinputs[1], False, 1, -1)
306  bip112txs_vary_nSequence_9_v2 = self.create_bip112txs(bip112basicinputs[1], False, 2, -1)
307  # sequence lock time of 10 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
308  bip112txs_vary_OP_CSV_v1 = self.create_bip112txs(bip112diverseinputs[0], True, 1)
309  bip112txs_vary_OP_CSV_v2 = self.create_bip112txs(bip112diverseinputs[0], True, 2)
310  # sequence lock time of 9 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
311  bip112txs_vary_OP_CSV_9_v1 = self.create_bip112txs(bip112diverseinputs[1], True, 1, -1)
312  bip112txs_vary_OP_CSV_9_v2 = self.create_bip112txs(bip112diverseinputs[1], True, 2, -1)
313  # -1 OP_CSV OP_DROP input
314  bip112tx_special_v1 = self.create_bip112special(bip112specialinput, 1)
315  bip112tx_special_v2 = self.create_bip112special(bip112specialinput, 2)
316 
317 
318 
324  success_txs = []
325  # add BIP113 tx and -1 CSV tx
326  bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
327  bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1)
328  success_txs.append(bip113signed1)
329  success_txs.append(bip112tx_special_v1)
330  # add BIP 68 txs
331  success_txs.extend(all_rlt_txs(bip68txs_v1))
332  # add BIP 112 with seq=10 txs
333  success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v1))
334  success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_v1))
335  # try BIP 112 with seq=9 txs
336  success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1))
337  success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1))
338  yield TestInstance([[self.create_test_block(success_txs), True]]) # 6
339  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
340 
341 
342  success_txs = []
343  # add BIP113 tx and -1 CSV tx
344  bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
345  bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2)
346  success_txs.append(bip113signed2)
347  success_txs.append(bip112tx_special_v2)
348  # add BIP 68 txs
349  success_txs.extend(all_rlt_txs(bip68txs_v2))
350  # add BIP 112 with seq=10 txs
351  success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v2))
352  success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_v2))
353  # try BIP 112 with seq=9 txs
354  success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2))
355  success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2))
356  yield TestInstance([[self.create_test_block(success_txs), True]]) # 7
357  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
358 
359 
360  # 1 more version 4 block to get us to height 575 so the fork should now be active for the next block
361  test_blocks = self.generate_blocks(1, 4)
362  yield TestInstance(test_blocks, sync_every_block=False) # 8
363  assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'active')
364 
365 
366 
371  bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
372  bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1)
373  bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
374  bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2)
375  for bip113tx in [bip113signed1, bip113signed2]:
376  yield TestInstance([[self.create_test_block([bip113tx]), False]]) # 9,10
377  # BIP 113 tests should now pass if the locktime is < MTP
378  bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
379  bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1)
380  bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
381  bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2)
382  for bip113tx in [bip113signed1, bip113signed2]:
383  yield TestInstance([[self.create_test_block([bip113tx]), True]]) # 11,12
384  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
385 
386  # Next block height = 580 after 4 blocks of random version
387  test_blocks = self.generate_blocks(4, 1234)
388  yield TestInstance(test_blocks, sync_every_block=False) # 13
389 
390 
393  success_txs = []
394  success_txs.extend(all_rlt_txs(bip68txs_v1))
395  yield TestInstance([[self.create_test_block(success_txs), True]]) # 14
396  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
397 
398 
399  bip68success_txs = []
400  # All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass
401  for b25 in xrange(2):
402  for b22 in xrange(2):
403  for b18 in xrange(2):
404  bip68success_txs.append(bip68txs_v2[1][b25][b22][b18])
405  yield TestInstance([[self.create_test_block(bip68success_txs), True]]) # 15
406  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
407  # All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512
408  bip68timetxs = []
409  for b25 in xrange(2):
410  for b18 in xrange(2):
411  bip68timetxs.append(bip68txs_v2[0][b25][1][b18])
412  for tx in bip68timetxs:
413  yield TestInstance([[self.create_test_block([tx]), False]]) # 16 - 19
414  bip68heighttxs = []
415  for b25 in xrange(2):
416  for b18 in xrange(2):
417  bip68heighttxs.append(bip68txs_v2[0][b25][0][b18])
418  for tx in bip68heighttxs:
419  yield TestInstance([[self.create_test_block([tx]), False]]) # 20 - 23
420 
421  # Advance one block to 581
422  test_blocks = self.generate_blocks(1, 1234)
423  yield TestInstance(test_blocks, sync_every_block=False) # 24
424 
425  # Height txs should fail and time txs should now pass 9 * 600 > 10 * 512
426  bip68success_txs.extend(bip68timetxs)
427  yield TestInstance([[self.create_test_block(bip68success_txs), True]]) # 25
428  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
429  for tx in bip68heighttxs:
430  yield TestInstance([[self.create_test_block([tx]), False]]) # 26 - 29
431 
432  # Advance one block to 582
433  test_blocks = self.generate_blocks(1, 1234)
434  yield TestInstance(test_blocks, sync_every_block=False) # 30
435 
436  # All BIP 68 txs should pass
437  bip68success_txs.extend(bip68heighttxs)
438  yield TestInstance([[self.create_test_block(bip68success_txs), True]]) # 31
439  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
440 
441 
442 
445  yield TestInstance([[self.create_test_block([bip112tx_special_v1]), False]]) #32
446  # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass
447  success_txs = []
448  for b25 in xrange(2):
449  for b22 in xrange(2):
450  for b18 in xrange(2):
451  success_txs.append(bip112txs_vary_OP_CSV_v1[1][b25][b22][b18])
452  success_txs.append(bip112txs_vary_OP_CSV_9_v1[1][b25][b22][b18])
453  yield TestInstance([[self.create_test_block(success_txs), True]]) # 33
454  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
455 
456  # If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail
457  fail_txs = []
458  fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v1))
459  fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1))
460  for b25 in xrange(2):
461  for b22 in xrange(2):
462  for b18 in xrange(2):
463  fail_txs.append(bip112txs_vary_OP_CSV_v1[0][b25][b22][b18])
464  fail_txs.append(bip112txs_vary_OP_CSV_9_v1[0][b25][b22][b18])
465 
466  for tx in fail_txs:
467  yield TestInstance([[self.create_test_block([tx]), False]]) # 34 - 81
468 
469 
471  yield TestInstance([[self.create_test_block([bip112tx_special_v2]), False]]) #82
472 
473  # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 2 txs should pass (all sequence locks are met)
474  success_txs = []
475  for b25 in xrange(2):
476  for b22 in xrange(2):
477  for b18 in xrange(2):
478  success_txs.append(bip112txs_vary_OP_CSV_v2[1][b25][b22][b18]) # 8/16 of vary_OP_CSV
479  success_txs.append(bip112txs_vary_OP_CSV_9_v2[1][b25][b22][b18]) # 8/16 of vary_OP_CSV_9
480 
481  yield TestInstance([[self.create_test_block(success_txs), True]]) # 83
482  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
483 
484 
486  fail_txs = []
487  fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2)) # 16/16 of vary_nSequence_9
488  for b25 in xrange(2):
489  for b22 in xrange(2):
490  for b18 in xrange(2):
491  fail_txs.append(bip112txs_vary_OP_CSV_9_v2[0][b25][b22][b18]) # 16/16 of vary_OP_CSV_9
492 
493  for tx in fail_txs:
494  yield TestInstance([[self.create_test_block([tx]), False]]) # 84 - 107
495 
496  # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail
497  fail_txs = []
498  for b25 in xrange(2):
499  for b22 in xrange(2):
500  for b18 in xrange(2):
501  fail_txs.append(bip112txs_vary_nSequence_v2[1][b25][b22][b18]) # 8/16 of vary_nSequence
502  for tx in fail_txs:
503  yield TestInstance([[self.create_test_block([tx]), False]]) # 108-115
504 
505  # If sequencelock types mismatch, tx should fail
506  fail_txs = []
507  for b25 in xrange(2):
508  for b18 in xrange(2):
509  fail_txs.append(bip112txs_vary_nSequence_v2[0][b25][1][b18]) # 12/16 of vary_nSequence
510  fail_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][1][b18]) # 12/16 of vary_OP_CSV
511  for tx in fail_txs:
512  yield TestInstance([[self.create_test_block([tx]), False]]) # 116-123
513 
514  # Remaining txs should pass, just test masking works properly
515  success_txs = []
516  for b25 in xrange(2):
517  for b18 in xrange(2):
518  success_txs.append(bip112txs_vary_nSequence_v2[0][b25][0][b18]) # 16/16 of vary_nSequence
519  success_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][0][b18]) # 16/16 of vary_OP_CSV
520  yield TestInstance([[self.create_test_block(success_txs), True]]) # 124
521  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
522 
523  # Additional test, of checking that comparison of two time types works properly
524  time_txs = []
525  for b25 in xrange(2):
526  for b18 in xrange(2):
527  tx = bip112txs_vary_OP_CSV_v2[0][b25][1][b18]
528  tx.vin[0].nSequence = base_relative_locktime | seq_type_flag
529  signtx = self.sign_transaction(self.nodes[0], tx)
530  time_txs.append(signtx)
531  yield TestInstance([[self.create_test_block(time_txs), True]]) # 125
532  self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
533 
534 
536 
537 
538 if __name__ == '__main__':
def sign_transaction(self, node, unsignedtx)
def get_bip9_status(node, key)
Definition: util.py:606
def create_block(hashprev, coinbase, nTime=None)
Definition: blocktools.py:11
def generate_blocks(self, number, version, test_blocks=[])
def hex_str_to_bytes(hex_str)
Definition: util.py:111
tip
Inputs at height = 572 Put inputs for all tests in the chain at height 572 (tip now = 571) (time incr...
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None)
Definition: util.py:305
def create_test_block(self, txs, version=536870912)
UniValue getblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:483
UniValue getnewaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:113
def create_bip112special(self, input, txversion)
def create_coinbase(height, pubkey=None)
Definition: blocktools.py:43
def all_rlt_txs(txarray)
UniValue generate(const UniValue &params, bool fHelp)
Definition: mining.cpp:122
def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0)
def send_generic_input_tx(self, node, coinbases)
UniValue getbestblockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:148
def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0)
UniValue setmocktime(const UniValue &params, bool fHelp)
Definition: misc.cpp:498
def assert_equal(thing1, thing2)
Definition: util.py:461
def create_transaction(self, node, txid, to_address, amount)