Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_csv_activation.py
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0): | ||||
signtx.rehash() | signtx.rehash() | ||||
b18txs.append(signtx) | b18txs.append(signtx) | ||||
b22txs.append(b18txs) | b22txs.append(b18txs) | ||||
b25txs.append(b22txs) | b25txs.append(b22txs) | ||||
txs.append(b25txs) | txs.append(b25txs) | ||||
return txs | return txs | ||||
def get_tests(self): | def get_tests(self): | ||||
self.log.info("Generate blocks in the past for coinbase outputs.") | |||||
# Enough to build up to 1000 blocks 10 minutes apart without worrying | # Enough to build up to 1000 blocks 10 minutes apart without worrying | ||||
# about getting into the future | # about getting into the future | ||||
long_past_time = int(time.time()) - 600 * 1000 | 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.nodes[0].setmocktime(long_past_time - 100) | ||||
# 82 blocks generated for inputs | # 82 blocks generated for inputs | ||||
self.coinbase_blocks = self.nodes[0].generate(1 + 16 + 2 * 32 + 1) | 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 | # Set time back to present so yielded blocks aren't in the future as | ||||
# we advance last_block_time | # we advance last_block_time | ||||
self.nodes[0].setmocktime(0) | self.nodes[0].setmocktime(0) | ||||
# height of the next block to build | # height of the next block to build | ||||
self.tipheight = 82 | self.tipheight = 82 | ||||
self.last_block_time = long_past_time | self.last_block_time = long_past_time | ||||
self.tip = int("0x" + self.nodes[0].getbestblockhash(), 0) | self.tip = int("0x" + self.nodes[0].getbestblockhash(), 0) | ||||
self.nodeaddress = self.nodes[0].getnewaddress() | self.nodeaddress = self.nodes[0].getnewaddress() | ||||
# CSV is not activated yet. | # CSV is not activated yet. | ||||
assert_equal(get_csv_status(self.nodes[0]), False) | assert_equal(get_csv_status(self.nodes[0]), False) | ||||
# 489 more version 4 blocks | # Generate 489 more version 4 blocks | ||||
test_blocks = self.generate_blocks(489) | test_blocks = self.generate_blocks(489) | ||||
# Test #1 | # Test #1 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | yield TestInstance(test_blocks, sync_every_block=False) | ||||
# Still not activated. | # Still not activated. | ||||
assert_equal(get_csv_status(self.nodes[0]), False) | assert_equal(get_csv_status(self.nodes[0]), False) | ||||
# Inputs at height = 572 | # Inputs at height = 572 | ||||
# Put inputs for all tests in the chain at height 572 (tip now = 571) (time increases by 600s per block) | # Put inputs for all tests in the chain at height 572 (tip now = 571) (time increases by 600s per block) | ||||
# Note we reuse inputs for v1 and v2 txs so must test these separately | # Note we reuse inputs for v1 and v2 txs so must test these separately | ||||
# 16 normal inputs | # 16 normal inputs | ||||
bip68inputs = [] | bip68inputs = [] | ||||
for i in range(16): | for i in range(16): | ||||
bip68inputs.append(self.send_generic_input_tx( | bip68inputs.append(self.send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks)) | self.nodes[0], self.coinbase_blocks)) | ||||
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig) | # 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig) | ||||
bip112basicinputs = [] | bip112basicinputs = [] | ||||
for j in range(2): | for j in range(2): | ||||
inputs = [] | inputs = [] | ||||
for i in range(16): | for i in range(16): | ||||
inputs.append(self.send_generic_input_tx( | inputs.append(self.send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks)) | self.nodes[0], self.coinbase_blocks)) | ||||
bip112basicinputs.append(inputs) | bip112basicinputs.append(inputs) | ||||
# 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig) | # 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig) | ||||
bip112diverseinputs = [] | bip112diverseinputs = [] | ||||
for j in range(2): | for j in range(2): | ||||
inputs = [] | inputs = [] | ||||
for i in range(16): | for i in range(16): | ||||
inputs.append(self.send_generic_input_tx( | inputs.append(self.send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks)) | self.nodes[0], self.coinbase_blocks)) | ||||
bip112diverseinputs.append(inputs) | bip112diverseinputs.append(inputs) | ||||
# 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to spending scriptSig) | # 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to spending scriptSig) | ||||
bip112specialinput = self.send_generic_input_tx( | bip112specialinput = self.send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks) | self.nodes[0], self.coinbase_blocks) | ||||
# 1 normal input | # 1 normal input | ||||
bip113input = self.send_generic_input_tx( | bip113input = self.send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks) | self.nodes[0], self.coinbase_blocks) | ||||
self.nodes[0].setmocktime(self.last_block_time + 600) | self.nodes[0].setmocktime(self.last_block_time + 600) | ||||
# 1 block generated for inputs to be in chain at height 572 | # 1 block generated for inputs to be in chain at height 572 | ||||
inputblockhash = self.nodes[0].generate(1)[0] | inputblockhash = self.nodes[0].generate(1)[0] | ||||
self.nodes[0].setmocktime(0) | self.nodes[0].setmocktime(0) | ||||
self.tip = int("0x" + inputblockhash, 0) | self.tip = int("0x" + inputblockhash, 0) | ||||
self.tipheight += 1 | self.tipheight += 1 | ||||
self.last_block_time += 600 | self.last_block_time += 600 | ||||
assert_equal(len(self.nodes[0].getblock( | assert_equal(len(self.nodes[0].getblock( | ||||
inputblockhash, True)["tx"]), 82 + 1) | inputblockhash, True)["tx"]), 82 + 1) | ||||
# 2 more version 4 blocks | # 2 more version 4 blocks | ||||
test_blocks = self.generate_blocks(2) | test_blocks = self.generate_blocks(2) | ||||
# Test #2 | # Test #2 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | yield TestInstance(test_blocks, sync_every_block=False) | ||||
# Not yet activated, height = 574 (will activate for block 576, not 575) | |||||
self.log.info( | |||||
"Not yet activated, height = 574 (will activate for block 576, not 575)") | |||||
assert_equal(get_csv_status(self.nodes[0]), False) | assert_equal(get_csv_status(self.nodes[0]), False) | ||||
# Test both version 1 and version 2 transactions for all tests | # Test both version 1 and version 2 transactions for all tests | ||||
# BIP113 test transaction will be modified before each use to | # BIP113 test transaction will be modified before each use to | ||||
# put in appropriate block time | # put in appropriate block time | ||||
bip113tx_v1 = self.create_transaction( | bip113tx_v1 = self.create_transaction( | ||||
self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98")) | self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98")) | ||||
bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | ||||
Show All 27 Lines | def get_tests(self): | ||||
bip112txs_vary_OP_CSV_9_v1 = self.create_bip112txs( | bip112txs_vary_OP_CSV_9_v1 = self.create_bip112txs( | ||||
bip112diverseinputs[1], True, 1, -1) | bip112diverseinputs[1], True, 1, -1) | ||||
bip112txs_vary_OP_CSV_9_v2 = self.create_bip112txs( | bip112txs_vary_OP_CSV_9_v2 = self.create_bip112txs( | ||||
bip112diverseinputs[1], True, 2, -1) | bip112diverseinputs[1], True, 2, -1) | ||||
# -1 OP_CSV OP_DROP input | # -1 OP_CSV OP_DROP input | ||||
bip112tx_special_v1 = self.create_bip112special(bip112specialinput, 1) | bip112tx_special_v1 = self.create_bip112special(bip112specialinput, 1) | ||||
bip112tx_special_v2 = self.create_bip112special(bip112specialinput, 2) | bip112tx_special_v2 = self.create_bip112special(bip112specialinput, 2) | ||||
### TESTING ### | self.log.info("TESTING") | ||||
################################## | |||||
### Before Soft Forks Activate ### | self.log.info("Pre-Soft Fork Tests. All txs should pass.") | ||||
################################## | self.log.info("Test version 1 txs") | ||||
# All txs should pass | |||||
### Version 1 txs ### | |||||
success_txs = [] | success_txs = [] | ||||
# add BIP113 tx and -1 CSV tx | # add BIP113 tx and -1 CSV tx | ||||
# = MTP of prior block (not <) but < time put on current block | # = MTP of prior block (not <) but < time put on current block | ||||
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 | bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 | ||||
bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1) | bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1) | ||||
success_txs.append(bip113signed1) | success_txs.append(bip113signed1) | ||||
success_txs.append(bip112tx_special_v1) | success_txs.append(bip112tx_special_v1) | ||||
success_txs.append(self.spend_tx(self.nodes[0], bip112tx_special_v1)) | success_txs.append(self.spend_tx(self.nodes[0], bip112tx_special_v1)) | ||||
Show All 12 Lines | def get_tests(self): | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v1)]) | for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v1)]) | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)) | ||||
success_txs.extend([self.spend_tx(self.nodes[0], tx) | success_txs.extend([self.spend_tx(self.nodes[0], tx) | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)]) | for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)]) | ||||
# Test #3 | # Test #3 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | yield TestInstance([[self.create_test_block(success_txs), True]]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
### Version 2 txs ### | self.log.info("Test version 2 txs") | ||||
success_txs = [] | success_txs = [] | ||||
# add BIP113 tx and -1 CSV tx | # add BIP113 tx and -1 CSV tx | ||||
# = MTP of prior block (not <) but < time put on current block | # = MTP of prior block (not <) but < time put on current block | ||||
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 | bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 | ||||
bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2) | bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2) | ||||
success_txs.append(bip113signed2) | success_txs.append(bip113signed2) | ||||
success_txs.append(bip112tx_special_v2) | success_txs.append(bip112tx_special_v2) | ||||
success_txs.append(self.spend_tx(self.nodes[0], bip112tx_special_v2)) | success_txs.append(self.spend_tx(self.nodes[0], bip112tx_special_v2)) | ||||
Show All 23 Lines | def get_tests(self): | ||||
# Test #5 | # Test #5 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | yield TestInstance(test_blocks, sync_every_block=False) | ||||
assert_equal(get_csv_status(self.nodes[0]), False) | assert_equal(get_csv_status(self.nodes[0]), False) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
assert_equal(get_csv_status(self.nodes[0]), True) | assert_equal(get_csv_status(self.nodes[0]), True) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
################################# | self.log.info("Post-Soft Fork Tests.") | ||||
### After Soft Forks Activate ### | |||||
################################# | self.log.info("BIP 113 tests") | ||||
### BIP 113 ### | |||||
# BIP 113 tests should now fail regardless of version number | # BIP 113 tests should now fail regardless of version number | ||||
# if nLockTime isn't satisfied by new rules | # if nLockTime isn't satisfied by new rules | ||||
# = MTP of prior block (not <) but < time put on current block | # = MTP of prior block (not <) but < time put on current block | ||||
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 | bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 | ||||
bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1) | bip113signed1 = self.sign_transaction(self.nodes[0], bip113tx_v1) | ||||
# = MTP of prior block (not <) but < time put on current block | # = MTP of prior block (not <) but < time put on current block | ||||
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 | bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 | ||||
bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2) | bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2) | ||||
Show All 13 Lines | def get_tests(self): | ||||
yield TestInstance([[self.create_test_block([bip113tx]), True]]) | yield TestInstance([[self.create_test_block([bip113tx]), True]]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# Next block height = 580 after 4 blocks of random version | # Next block height = 580 after 4 blocks of random version | ||||
test_blocks = self.generate_blocks(4) | test_blocks = self.generate_blocks(4) | ||||
# Test #10 | # Test #10 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | yield TestInstance(test_blocks, sync_every_block=False) | ||||
### BIP 68 ### | self.log.info("BIP 68 tests") | ||||
### Version 1 txs ### | self.log.info("Test version 1 txs - all should still pass") | ||||
# All still pass | |||||
success_txs = [] | success_txs = [] | ||||
success_txs.extend(all_rlt_txs(bip68txs_v1)) | success_txs.extend(all_rlt_txs(bip68txs_v1)) | ||||
# Test #11 | # Test #11 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | yield TestInstance([[self.create_test_block(success_txs), True]]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
### Version 2 txs ### | self.log.info("Test version 2 txs") | ||||
bip68success_txs = [] | bip68success_txs = [] | ||||
# All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass | # All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass | ||||
for b25 in range(2): | for b25 in range(2): | ||||
for b22 in range(2): | for b22 in range(2): | ||||
for b18 in range(2): | for b18 in range(2): | ||||
bip68success_txs.append(bip68txs_v2[1][b25][b22][b18]) | bip68success_txs.append(bip68txs_v2[1][b25][b22][b18]) | ||||
# Test #12 | # Test #12 | ||||
yield TestInstance([[self.create_test_block(bip68success_txs), True]]) | yield TestInstance([[self.create_test_block(bip68success_txs), True]]) | ||||
Show All 35 Lines | def get_tests(self): | ||||
yield TestInstance(test_blocks, sync_every_block=False) | yield TestInstance(test_blocks, sync_every_block=False) | ||||
# All BIP 68 txs should pass | # All BIP 68 txs should pass | ||||
bip68success_txs.extend(bip68heighttxs) | bip68success_txs.extend(bip68heighttxs) | ||||
# Test #28 | # Test #28 | ||||
yield TestInstance([[self.create_test_block(bip68success_txs), True]]) | yield TestInstance([[self.create_test_block(bip68success_txs), True]]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
### BIP 112 ### | self.log.info("BIP 112 tests") | ||||
### Version 1 txs ### | self.log.info("Test version 1 txs") | ||||
# -1 OP_CSV tx should fail | # -1 OP_CSV tx should fail | ||||
# Test #29 | # Test #29 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [bip112tx_special_v1]), False]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [bip112tx_special_v1]), False]]) | ||||
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, | # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, | ||||
# version 1 txs should still pass | # version 1 txs should still pass | ||||
success_txs = [] | success_txs = [] | ||||
for b25 in range(2): | for b25 in range(2): | ||||
Show All 18 Lines | def get_tests(self): | ||||
fail_txs.append(bip112txs_vary_OP_CSV_v1[0][b25][b22][b18]) | fail_txs.append(bip112txs_vary_OP_CSV_v1[0][b25][b22][b18]) | ||||
fail_txs.append( | fail_txs.append( | ||||
bip112txs_vary_OP_CSV_9_v1[0][b25][b22][b18]) | bip112txs_vary_OP_CSV_9_v1[0][b25][b22][b18]) | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# Test #31 - Test #78 | # Test #31 - Test #78 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [tx]), False]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [tx]), False]]) | ||||
### Version 2 txs ### | self.log.info("Version 2 txs") | ||||
# -1 OP_CSV tx should fail | # -1 OP_CSV tx should fail | ||||
# Test #79 | # Test #79 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [bip112tx_special_v2]), False]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [bip112tx_special_v2]), False]]) | ||||
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, | # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, | ||||
# version 2 txs should pass | # version 2 txs should pass | ||||
success_txs = [] | success_txs = [] | ||||
for b25 in range(2): | for b25 in range(2): | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |