Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_csv_activation.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
from itertools import product | from itertools import product | ||||
import time | import time | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
make_conform_to_ctor, | make_conform_to_ctor, | ||||
) | ) | ||||
from test_framework.comptool import TestInstance, TestManager | |||||
from test_framework.messages import COIN, CTransaction, FromHex, ToHex | from test_framework.messages import COIN, CTransaction, FromHex, ToHex | ||||
from test_framework.mininode import network_thread_start | from test_framework.mininode import network_thread_start, P2PDataStore | ||||
from test_framework.script import ( | from test_framework.script import ( | ||||
CScript, | CScript, | ||||
OP_CHECKSEQUENCEVERIFY, | OP_CHECKSEQUENCEVERIFY, | ||||
OP_DROP, | OP_DROP, | ||||
OP_TRUE, | OP_TRUE, | ||||
) | ) | ||||
from test_framework.test_framework import ComparisonTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.txtools import pad_tx | from test_framework.txtools import pad_tx | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
BASE_RELATIVE_LOCKTIME = 10 | BASE_RELATIVE_LOCKTIME = 10 | ||||
SEQ_DISABLE_FLAG = 1 << 31 | SEQ_DISABLE_FLAG = 1 << 31 | ||||
SEQ_RANDOM_HIGH_BIT = 1 << 25 | SEQ_RANDOM_HIGH_BIT = 1 << 25 | ||||
SEQ_TYPE_FLAG = 1 << 22 | SEQ_TYPE_FLAG = 1 << 22 | ||||
SEQ_RANDOM_LOW_BIT = 1 << 18 | SEQ_RANDOM_LOW_BIT = 1 << 18 | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | ||||
[BASE_RELATIVE_LOCKTIME, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | [BASE_RELATIVE_LOCKTIME, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | ||||
tx.rehash() | tx.rehash() | ||||
signtx = sign_transaction(node, tx) | signtx = sign_transaction(node, tx) | ||||
signtx.rehash() | signtx.rehash() | ||||
txs.append({'tx': signtx, 'sdf': sdf, 'stf': stf}) | txs.append({'tx': signtx, 'sdf': sdf, 'stf': stf}) | ||||
return txs | return txs | ||||
class BIP68_112_113Test(ComparisonTestFramework): | class BIP68_112_113Test(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']] | self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']] | ||||
def run_test(self): | |||||
test = TestManager(self, self.options.tmpdir) | |||||
test.add_all_connections(self.nodes) | |||||
network_thread_start() | |||||
test.run() | |||||
def generate_blocks(self, number): | def generate_blocks(self, number): | ||||
test_blocks = [] | test_blocks = [] | ||||
for i in range(number): | for i in range(number): | ||||
block = self.create_test_block([]) | block = self.create_test_block([]) | ||||
test_blocks.append([block, True]) | test_blocks.append(block) | ||||
self.last_block_time += 600 | self.last_block_time += 600 | ||||
self.tip = block.sha256 | self.tip = block.sha256 | ||||
self.tipheight += 1 | self.tipheight += 1 | ||||
return test_blocks | return test_blocks | ||||
def create_test_block(self, txs, version=536870912): | def create_test_block(self, txs, version=536870912): | ||||
block = create_block(self.tip, create_coinbase( | block = create_block(self.tip, create_coinbase( | ||||
self.tipheight + 1), self.last_block_time + 600) | self.tipheight + 1), self.last_block_time + 600) | ||||
Show All 13 Lines | def create_test_block_spend_utxos(self, node, txs, version=536870912): | ||||
block = self.create_test_block(txs, version) | block = self.create_test_block(txs, version) | ||||
block.vtx.extend([spend_tx(node, tx, self.nodeaddress) for tx in txs]) | block.vtx.extend([spend_tx(node, tx, self.nodeaddress) for tx in txs]) | ||||
make_conform_to_ctor(block) | make_conform_to_ctor(block) | ||||
block.hashMerkleRoot = block.calc_merkle_root() | block.hashMerkleRoot = block.calc_merkle_root() | ||||
block.rehash() | block.rehash() | ||||
block.solve() | block.solve() | ||||
return block | return block | ||||
def get_tests(self): | def sync_blocks(self, blocks, success=True, reject_code=None, reject_reason=None, request_block=True): | ||||
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. | |||||
Call with success = False if the tip shouldn't advance to the most recent block.""" | |||||
self.nodes[0].p2p.send_blocks_and_test( | |||||
blocks, self.nodes[0], success=success, reject_code=reject_code, reject_reason=reject_reason, request_block=request_block) | |||||
def run_test(self): | |||||
self.nodes[0].add_p2p_connection(P2PDataStore()) | |||||
network_thread_start() | |||||
self.nodes[0].p2p.wait_for_verack() | |||||
self.log.info("Generate blocks in the past for coinbase outputs.") | 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) | ||||
# Generate 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) | self.sync_blocks(test_blocks) | ||||
# 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 | ||||
Show All 36 Lines | def run_test(self): | ||||
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) | self.sync_blocks(test_blocks) | ||||
self.log.info( | self.log.info( | ||||
"Not yet activated, height = 574 (will activate for block 576, not 575)") | "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 | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# try BIP 112 with seq=9 txs | # try BIP 112 with seq=9 txs | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1)) | success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1)) | ||||
success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
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([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
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]]) | self.sync_blocks([self.create_test_block(success_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
self.log.info("Test 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 | ||||
Show All 14 Lines | def run_test(self): | ||||
# try BIP 112 with seq=9 txs | # try BIP 112 with seq=9 txs | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2)) | success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2)) | ||||
success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v2)]) | for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v2)]) | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)) | ||||
success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)]) | for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)]) | ||||
# Test #4 | # Test #4 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | self.sync_blocks([self.create_test_block(success_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# 1 more version 4 block to get us to height 575 so the fork should | # 1 more version 4 block to get us to height 575 so the fork should | ||||
# now be active for the next block | # now be active for the next block | ||||
test_blocks = self.generate_blocks(1) | test_blocks = self.generate_blocks(1) | ||||
# Test #5 | # Test #5 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | self.sync_blocks(test_blocks) | ||||
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.") | self.log.info("Post-Soft Fork Tests.") | ||||
self.log.info("BIP 113 tests") | self.log.info("BIP 113 tests") | ||||
# 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 = sign_transaction(self.nodes[0], bip113tx_v1) | bip113signed1 = 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 = sign_transaction(self.nodes[0], bip113tx_v2) | bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) | ||||
for bip113tx in [bip113signed1, bip113signed2]: | for bip113tx in [bip113signed1, bip113signed2]: | ||||
# Test #6, Test #7 | # Test #6, Test #7 | ||||
yield TestInstance([[self.create_test_block([bip113tx]), False]]) | self.sync_blocks( | ||||
[self.create_test_block([bip113tx])], success=False) | |||||
# BIP 113 tests should now pass if the locktime is < MTP | # BIP 113 tests should now pass if the locktime is < MTP | ||||
# < MTP of prior block | # < MTP of prior block | ||||
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 | bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 | ||||
bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1) | bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1) | ||||
# < MTP of prior block | # < MTP of prior block | ||||
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 | bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 | ||||
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) | bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) | ||||
for bip113tx in [bip113signed1, bip113signed2]: | for bip113tx in [bip113signed1, bip113signed2]: | ||||
# Test #8, Test #9 | # Test #8, Test #9 | ||||
yield TestInstance([[self.create_test_block([bip113tx]), True]]) | self.sync_blocks([self.create_test_block([bip113tx])]) | ||||
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) | self.sync_blocks(test_blocks) | ||||
self.log.info("BIP 68 tests") | self.log.info("BIP 68 tests") | ||||
self.log.info("Test version 1 txs - all should still pass") | self.log.info("Test version 1 txs - all should 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]]) | self.sync_blocks([self.create_test_block(success_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
self.log.info("Test version 2 txs") | self.log.info("Test version 2 txs") | ||||
# All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass | # All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass | ||||
bip68success_txs = [tx['tx'] for tx in bip68txs_v2 if tx['sdf']] | bip68success_txs = [tx['tx'] for tx in bip68txs_v2 if tx['sdf']] | ||||
yield TestInstance([[self.create_test_block(bip68success_txs), True]]) | self.sync_blocks([self.create_test_block(bip68success_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# All txs without flag fail as we are at delta height = 8 < 10 and | # All txs without flag fail as we are at delta height = 8 < 10 and | ||||
# delta time = 8 * 600 < 10 * 512 | # delta time = 8 * 600 < 10 * 512 | ||||
bip68timetxs = [tx['tx'] | bip68timetxs = [tx['tx'] | ||||
for tx in bip68txs_v2 if not tx['sdf'] and tx['stf']] | for tx in bip68txs_v2 if not tx['sdf'] and tx['stf']] | ||||
for tx in bip68timetxs: | for tx in bip68timetxs: | ||||
# Test #13 - Test #16 | # Test #13 - Test #16 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | self.sync_blocks([self.create_test_block([tx])], success=False) | ||||
bip68heighttxs = [tx['tx'] | bip68heighttxs = [tx['tx'] | ||||
for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']] | for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']] | ||||
for tx in bip68heighttxs: | for tx in bip68heighttxs: | ||||
# Test #17 - Test #20 | # Test #17 - Test #20 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | self.sync_blocks([self.create_test_block([tx])], success=False) | ||||
# Advance one block to 581 | # Advance one block to 581 | ||||
test_blocks = self.generate_blocks(1) | test_blocks = self.generate_blocks(1) | ||||
# Test #21 | # Test #21 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | self.sync_blocks(test_blocks,) | ||||
# Height txs should fail and time txs should now pass 9 * 600 > 10 * 512 | # Height txs should fail and time txs should now pass 9 * 600 > 10 * 512 | ||||
bip68success_txs.extend(bip68timetxs) | bip68success_txs.extend(bip68timetxs) | ||||
# Test #22 | # Test #22 | ||||
yield TestInstance([[self.create_test_block(bip68success_txs), True]]) | self.sync_blocks([self.create_test_block(bip68success_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
for tx in bip68heighttxs: | for tx in bip68heighttxs: | ||||
# Test #23 - Test #26 | # Test #23 - Test #26 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | self.sync_blocks([self.create_test_block([tx])], success=False) | ||||
# Advance one block to 582 | # Advance one block to 582 | ||||
test_blocks = self.generate_blocks(1) | test_blocks = self.generate_blocks(1) | ||||
# Test #27 | # Test #27 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | self.sync_blocks(test_blocks) | ||||
# 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]]) | self.sync_blocks([self.create_test_block(bip68success_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
self.log.info("BIP 112 tests") | self.log.info("BIP 112 tests") | ||||
self.log.info("Test 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]]) | self.sync_blocks([self.create_test_block_spend_utxos( | ||||
self.nodes[0], [bip112tx_special_v1])], success=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 = [tx['tx'] | success_txs = [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_v1 if tx['sdf']] | for tx in bip112txs_vary_OP_CSV_v1 if tx['sdf']] | ||||
success_txs += [tx['tx'] | success_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_9_v1 if tx['sdf']] | for tx in bip112txs_vary_OP_CSV_9_v1 if tx['sdf']] | ||||
# Test #30 | # Test #30 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], success_txs), True]]) | self.sync_blocks( | ||||
[self.create_test_block_spend_utxos(self.nodes[0], success_txs)]) | |||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, | # If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, | ||||
# version 1 txs should now fail | # version 1 txs should now fail | ||||
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_v1) | fail_txs = all_rlt_txs(bip112txs_vary_nSequence_v1) | ||||
fail_txs += all_rlt_txs(bip112txs_vary_nSequence_9_v1) | fail_txs += all_rlt_txs(bip112txs_vary_nSequence_9_v1) | ||||
fail_txs += [tx['tx'] | fail_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']] | for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']] | ||||
fail_txs += [tx['tx'] | fail_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']] | for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']] | ||||
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]]) | self.sync_blocks([self.create_test_block_spend_utxos( | ||||
self.nodes[0], [tx])], success=False) | |||||
self.log.info("Version 2 txs") | self.log.info("Test 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]]) | self.sync_blocks([self.create_test_block_spend_utxos( | ||||
self.nodes[0], [bip112tx_special_v2])], success=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 = [tx['tx'] | success_txs = [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_v2 if tx['sdf']] | for tx in bip112txs_vary_OP_CSV_v2 if tx['sdf']] | ||||
success_txs += [tx['tx'] | success_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']] | for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']] | ||||
# Test #80 | # Test #80 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], success_txs), True]]) | self.sync_blocks( | ||||
[self.create_test_block_spend_utxos(self.nodes[0], success_txs)]) | |||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
## SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all remaining txs ## | ## 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 | # All txs with nSequence 9 should fail either due to earlier mismatch | ||||
# or failing the CSV check | # or failing the CSV check | ||||
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2) | fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2) | ||||
fail_txs += [tx['tx'] | fail_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']] | for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']] | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# Test #81 - Test #104 | # Test #81 - Test #104 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [tx]), False]]) | self.sync_blocks([self.create_test_block_spend_utxos( | ||||
self.nodes[0], [tx])], success=False) | |||||
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail | # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail | ||||
fail_txs = [tx['tx'] | fail_txs = [tx['tx'] | ||||
for tx in bip112txs_vary_nSequence_v2 if tx['sdf']] | for tx in bip112txs_vary_nSequence_v2 if tx['sdf']] | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# Test #105 - Test #112 | # Test #105 - Test #112 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [tx]), False]]) | self.sync_blocks([self.create_test_block_spend_utxos( | ||||
self.nodes[0], [tx])], success=False) | |||||
# If sequencelock types mismatch, tx should fail | # If sequencelock types mismatch, tx should fail | ||||
fail_txs = [tx['tx'] | fail_txs = [tx['tx'] | ||||
for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']] | for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']] | ||||
fail_txs += [tx['tx'] | fail_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']] | for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']] | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# Test #113 - Test #120 | # Test #113 - Test #120 | ||||
yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [tx]), False]]) | self.sync_blocks([self.create_test_block_spend_utxos( | ||||
self.nodes[0], [tx])], success=False) | |||||
# Remaining txs should pass, just test masking works properly | # Remaining txs should pass, just test masking works properly | ||||
success_txs = [ | success_txs = [ | ||||
tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and not tx['stf']] | tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and not tx['stf']] | ||||
success_txs += [tx['tx'] | success_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and not tx['stf']] | for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and not tx['stf']] | ||||
# Test #121 | # Test #121 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | self.sync_blocks([self.create_test_block(success_txs)]) | ||||
# Spending the previous block utxos requires a difference of 10 blocks (nSequence = 10). | # Spending the previous block utxos requires a difference of 10 blocks (nSequence = 10). | ||||
# Generate 9 blocks then spend in the 10th | # Generate 9 blocks then spend in the 10th | ||||
block = self.nodes[0].getbestblockhash() | block = self.nodes[0].getbestblockhash() | ||||
self.last_block_time += 600 | self.last_block_time += 600 | ||||
self.tip = int("0x" + block, 0) | self.tip = int("0x" + block, 0) | ||||
self.tipheight += 1 | self.tipheight += 1 | ||||
# Test #122 | # Test #122 | ||||
yield TestInstance(self.generate_blocks(9), sync_every_block=False) | self.sync_blocks(self.generate_blocks(9)) | ||||
spend_txs = [] | spend_txs = [] | ||||
for tx in success_txs: | for tx in success_txs: | ||||
raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | ||||
raw_tx.rehash() | raw_tx.rehash() | ||||
spend_txs.append(raw_tx) | spend_txs.append(raw_tx) | ||||
# Test #123 | # Test #123 | ||||
yield TestInstance([[self.create_test_block(spend_txs), True]]) | self.sync_blocks([self.create_test_block(spend_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# Additional test, of checking that comparison of two time types works properly | # Additional test, of checking that comparison of two time types works properly | ||||
time_txs = [] | time_txs = [] | ||||
for tx in [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]: | for tx in [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]: | ||||
signtx = sign_transaction(self.nodes[0], tx) | signtx = sign_transaction(self.nodes[0], tx) | ||||
time_txs.append(signtx) | time_txs.append(signtx) | ||||
# Test #124 | # Test #124 | ||||
yield TestInstance([[self.create_test_block(time_txs), True]]) | self.sync_blocks([self.create_test_block(time_txs)]) | ||||
# Spending the previous block utxos requires a block time difference of | # Spending the previous block utxos requires a block time difference of | ||||
# at least 10 * 512s (nSequence = 10). | # at least 10 * 512s (nSequence = 10). | ||||
# Generate 8 blocks then spend in the 9th (9 * 600 > 10 * 512) | # Generate 8 blocks then spend in the 9th (9 * 600 > 10 * 512) | ||||
block = self.nodes[0].getbestblockhash() | block = self.nodes[0].getbestblockhash() | ||||
self.last_block_time += 600 | self.last_block_time += 600 | ||||
self.tip = int("0x" + block, 0) | self.tip = int("0x" + block, 0) | ||||
self.tipheight += 1 | self.tipheight += 1 | ||||
# Test #125 | # Test #125 | ||||
yield TestInstance(self.generate_blocks(8), sync_every_block=False) | self.sync_blocks(self.generate_blocks(8)) | ||||
spend_txs = [] | spend_txs = [] | ||||
for tx in time_txs: | for tx in time_txs: | ||||
raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG | raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG | ||||
raw_tx.rehash() | raw_tx.rehash() | ||||
spend_txs.append(raw_tx) | spend_txs.append(raw_tx) | ||||
# Test #126 | # Test #126 | ||||
yield TestInstance([[self.create_test_block(spend_txs), True]]) | self.sync_blocks([self.create_test_block(spend_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# Missing aspects of test | # Missing aspects of test | ||||
# Testing empty stack fails | # Testing empty stack fails | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
BIP68_112_113Test().main() | BIP68_112_113Test().main() |