diff --git a/test/functional/bip68-112-113-p2p.py b/test/functional/bip68-112-113-p2p.py --- a/test/functional/bip68-112-113-p2p.py +++ b/test/functional/bip68-112-113-p2p.py @@ -212,13 +212,15 @@ return txs def get_tests(self): - # enough to build up to 1000 blocks 10 minutes apart without worrying about getting into the future + # Enough to build up to 1000 blocks 10 minutes apart without worrying + # about getting into the future long_past_time = int(time.time()) - 600 * 1000 - # enough so that the generated blocks will still all be before long_past_time + # Enough so that the generated blocks will still all be before long_past_time self.nodes[0].setmocktime(long_past_time - 100) - self.coinbase_blocks = self.nodes[0].generate( - 1 + 16 + 2 * 32 + 1) # 82 blocks generated for inputs - # set time back to present so yielded blocks aren't in the future as we advance last_block_time + # 82 blocks generated for inputs + self.coinbase_blocks = self.nodes[0].generate(1 + 16 + 2 * 32 + 1) + # Set time back to present so yielded blocks aren't in the future as + # we advance last_block_time self.nodes[0].setmocktime(0) self.tipheight = 82 # height of the next block to build self.last_block_time = long_past_time @@ -235,14 +237,15 @@ # Fail to achieve LOCKED_IN 100 out of 144 signal bit 0 # using a variety of bits to simulate multiple parallel softforks - test_blocks = self.generate_blocks( - 50, 536870913) # 0x20000001 (signalling ready) - test_blocks = self.generate_blocks( - 20, 4, test_blocks) # 0x00000004 (signalling not) - test_blocks = self.generate_blocks( - 50, 536871169, test_blocks) # 0x20000101 (signalling ready) - test_blocks = self.generate_blocks( - 24, 536936448, test_blocks) # 0x20010000 (signalling not) + + # 0x20000001 (signalling ready) + test_blocks = self.generate_blocks(50, 536870913) + # 0x00000004 (signalling not) + test_blocks = self.generate_blocks(20, 4, test_blocks) + # 0x20000101 (signalling ready) + test_blocks = self.generate_blocks(50, 536871169, test_blocks) + # 0x20010000 (signalling not) + test_blocks = self.generate_blocks(24, 536936448, test_blocks) yield TestInstance(test_blocks, sync_every_block=False) # 2 # Failed to advance past STARTED, height = 287 assert_equal(get_bip9_status(self.nodes[0], 'csv')[ @@ -250,14 +253,14 @@ # 108 out of 144 signal bit 0 to achieve lock-in # using a variety of bits to simulate multiple parallel softforks - test_blocks = self.generate_blocks( - 58, 536870913) # 0x20000001 (signalling ready) - test_blocks = self.generate_blocks( - 26, 4, test_blocks) # 0x00000004 (signalling not) - test_blocks = self.generate_blocks( - 50, 536871169, test_blocks) # 0x20000101 (signalling ready) - test_blocks = self.generate_blocks( - 10, 536936448, test_blocks) # 0x20010000 (signalling not) + # 0x20000001 (signalling ready) + test_blocks = self.generate_blocks(58, 536870913) + # 0x00000004 (signalling not) + test_blocks = self.generate_blocks(26, 4, test_blocks) + # 0x20000101 (signalling ready) + test_blocks = self.generate_blocks(50, 536871169, test_blocks) + # 0x20010000 (signalling not) + test_blocks = self.generate_blocks(10, 536936448, test_blocks) yield TestInstance(test_blocks, sync_every_block=False) # 3 # Advanced from STARTED to LOCKED_IN, height = 431 assert_equal(get_bip9_status(self.nodes[0], 'csv')[ @@ -316,7 +319,8 @@ 'status'], 'locked_in') # Test both version 1 and version 2 transactions for all tests - # BIP113 test transaction will be modified before each use to put in appropriate block time + # BIP113 test transaction will be modified before each use to + # put in appropriate block time bip113tx_v1 = self.create_transaction( self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98")) bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE @@ -398,7 +402,8 @@ yield TestInstance([[self.create_test_block(success_txs), True]]) # 7 self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) - # 1 more version 4 block to get us to height 575 so the fork should now be active for the next block + # 1 more version 4 block to get us to height 575 so the fork should + # now be active for the next block test_blocks = self.generate_blocks(1, 4) yield TestInstance(test_blocks, sync_every_block=False) # 8 assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'active') @@ -407,7 +412,8 @@ ### After Soft Forks Activate ### ################################# ### BIP 113 ### - # BIP 113 tests should now fail regardless of version number if nLockTime isn't satisfied by new rules + # BIP 113 tests should now fail regardless of version number + # if nLockTime isn't satisfied by new rules # = MTP of prior block (not <) but < time put on current block bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1) @@ -418,11 +424,12 @@ # 9,10 yield TestInstance([[self.create_test_block([bip113tx]), False]]) # BIP 113 tests should now pass if the locktime is < MTP - bip113tx_v1.nLockTime = self.last_block_time - \ - 600 * 5 - 1 # < MTP of prior block + + # < MTP of prior block + bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1) - bip113tx_v2.nLockTime = self.last_block_time - \ - 600 * 5 - 1 # < MTP of prior block + # < MTP of prior block + bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2) for bip113tx in [bip113signed1, bip113signed2]: # 11,12 @@ -451,7 +458,8 @@ # 15 yield TestInstance([[self.create_test_block(bip68success_txs), True]]) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) - # All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512 + # All txs without flag fail as we are at delta height = 8 < 10 and + # delta time = 8 * 600 < 10 * 512 bip68timetxs = [] for b25 in range(2): for b18 in range(2): @@ -495,7 +503,8 @@ # -1 OP_CSV tx should fail # 32 yield TestInstance([[self.create_test_block([bip112tx_special_v1]), False]]) - # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass + # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, + # version 1 txs should still pass success_txs = [] for b25 in range(2): for b22 in range(2): @@ -507,7 +516,8 @@ yield TestInstance([[self.create_test_block(success_txs), True]]) # 33 self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) - # If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail + # If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, + # version 1 txs should now fail fail_txs = [] fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v1)) fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1)) @@ -527,7 +537,8 @@ # 82 yield TestInstance([[self.create_test_block([bip112tx_special_v2]), False]]) - # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 2 txs should pass (all sequence locks are met) + # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, + # version 2 txs should pass (all sequence locks are met) success_txs = [] for b25 in range(2): for b22 in range(2): @@ -543,7 +554,8 @@ self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) ## SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all remaining txs ## - # All txs with nSequence 9 should fail either due to earlier mismatch or failing the CSV check + # All txs with nSequence 9 should fail either due to earlier mismatch + # or failing the CSV check fail_txs = [] # 16/16 of vary_nSequence_9 fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2))