13 from io
import BytesIO
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 23 regtest lock-in with 108/144 block signalling 24 activation after a further 144 blocks 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 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. 44 bip113tx - modify the nLocktime variable 47 bip68txs - 16 txs with nSequence relative locktime of 10 with various bits set as per the relative_locktimes below 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 57 base_relative_locktime = 10
58 seq_disable_flag = 1<<31
59 seq_random_high_bit = 1<<25
61 seq_random_low_bit = 1<<18
65 relative_locktimes = []
73 rlt = base_relative_locktime
75 rlt = rlt | seq_disable_flag
77 rlt = rlt | seq_random_high_bit
79 rlt = rlt | seq_type_flag
81 rlt = rlt | seq_random_low_bit
83 b22times.append(b18times)
84 b25times.append(b22times)
85 relative_locktimes.append(b25times)
93 txs.append(txarray[b31][b25][b22][b18])
103 extra_args=[[
'-debug',
'-whitelist=127.0.0.1',
'-blockversion=4']],
104 binary=[self.options.testbinary])
108 test.add_all_connections(self.
nodes)
113 amount = Decimal(
"499.99")
117 inputs = [{
"txid" : txid,
"vout" : 0}]
118 outputs = { to_address : amount }
119 rawtx = node.createrawtransaction(inputs, outputs)
126 rawtx =
ToHex(unsignedtx)
127 signresult = node.signrawtransaction(rawtx)
134 for i
in xrange(number):
136 test_blocks.append([block,
True])
144 block.nVersion = version
145 block.vtx.extend(txs)
146 block.hashMerkleRoot = block.calc_merkle_root()
153 assert(len(bip68inputs) >= 16)
155 for b31
in xrange(2):
157 for b25
in xrange(2):
159 for b22
in xrange(2):
161 for b18
in xrange(2):
164 tx.nVersion = txversion
165 tx.vin[0].nSequence = relative_locktimes[b31][b25][b22][b18] + locktime_delta
167 b22txs.append(b18txs)
168 b25txs.append(b22txs)
174 tx.nVersion = txversion
176 signtx.vin[0].scriptSig =
CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(
CScript(signtx.vin[0].scriptSig)))
181 assert(len(bip112inputs) >= 16)
183 for b31
in xrange(2):
185 for b25
in xrange(2):
187 for b22
in xrange(2):
189 for b18
in xrange(2):
193 tx.vin[0].nSequence = base_relative_locktime + locktime_delta
195 tx.vin[0].nSequence = relative_locktimes[b31][b25][b22][b18] + locktime_delta
196 tx.nVersion = txversion
199 signtx.vin[0].scriptSig =
CScript([relative_locktimes[b31][b25][b22][b18], OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(
CScript(signtx.vin[0].scriptSig)))
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)
209 long_past_time = int(time.time()) - 600 * 1000
256 bip112basicinputs = []
261 bip112basicinputs.append(inputs)
263 bip112diverseinputs = []
268 bip112diverseinputs.append(inputs)
277 self.
tip = int(
"0x" + inputblockhash +
"L", 0)
291 bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE
293 bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE
294 bip113tx_v2.nVersion = 2
302 bip112txs_vary_nSequence_v1 = self.
create_bip112txs(bip112basicinputs[0],
False, 1)
303 bip112txs_vary_nSequence_v2 = self.
create_bip112txs(bip112basicinputs[0],
False, 2)
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)
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)
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)
328 success_txs.append(bip113signed1)
329 success_txs.append(bip112tx_special_v1)
333 success_txs.extend(
all_rlt_txs(bip112txs_vary_nSequence_v1))
334 success_txs.extend(
all_rlt_txs(bip112txs_vary_OP_CSV_v1))
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))
346 success_txs.append(bip113signed2)
347 success_txs.append(bip112tx_special_v2)
351 success_txs.extend(
all_rlt_txs(bip112txs_vary_nSequence_v2))
352 success_txs.extend(
all_rlt_txs(bip112txs_vary_OP_CSV_v2))
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))
375 for bip113tx
in [bip113signed1, bip113signed2]:
382 for bip113tx
in [bip113signed1, bip113signed2]:
399 bip68success_txs = []
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])
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:
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:
426 bip68success_txs.extend(bip68timetxs)
429 for tx
in bip68heighttxs:
437 bip68success_txs.extend(bip68heighttxs)
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])
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])
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])
479 success_txs.append(bip112txs_vary_OP_CSV_9_v2[1][b25][b22][b18])
487 fail_txs.extend(
all_rlt_txs(bip112txs_vary_nSequence_9_v2))
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])
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])
507 for b25
in xrange(2):
508 for b18
in xrange(2):
509 fail_txs.append(bip112txs_vary_nSequence_v2[0][b25][1][b18])
510 fail_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][1][b18])
516 for b25
in xrange(2):
517 for b18
in xrange(2):
518 success_txs.append(bip112txs_vary_nSequence_v2[0][b25][0][b18])
519 success_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][0][b18])
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
530 time_txs.append(signtx)
538 if __name__ ==
'__main__':
def sign_transaction(self, node, unsignedtx)
def get_bip9_status(node, key)
def generate_blocks(self, number, version, test_blocks=[])
def hex_str_to_bytes(hex_str)
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)
def create_test_block(self, txs, version=536870912)
UniValue getblock(const UniValue ¶ms, bool fHelp)
UniValue getnewaddress(const UniValue ¶ms, bool fHelp)
def create_bip112special(self, input, txversion)
UniValue generate(const UniValue ¶ms, bool fHelp)
def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0)
def send_generic_input_tx(self, node, coinbases)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)
def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0)
UniValue setmocktime(const UniValue ¶ms, bool fHelp)
def assert_equal(thing1, thing2)
def create_transaction(self, node, txid, to_address, amount)