Changeset View
Changeset View
Standalone View
Standalone View
test/functional/bip68-112-113-p2p.py
Show All 36 Lines | |||||
bip112txs_vary_nSequence_9 - 16 txs with nSequence relative_locktimes of 9 evaluated against 10 OP_CSV OP_DROP | bip112txs_vary_nSequence_9 - 16 txs with nSequence relative_locktimes of 9 evaluated against 10 OP_CSV OP_DROP | ||||
bip112txs_vary_OP_CSV - 16 txs with nSequence = 10 evaluated against varying {relative_locktimes of 10} OP_CSV OP_DROP | bip112txs_vary_OP_CSV - 16 txs with nSequence = 10 evaluated against varying {relative_locktimes of 10} OP_CSV OP_DROP | ||||
bip112txs_vary_OP_CSV_9 - 16 txs with nSequence = 9 evaluated against varying {relative_locktimes of 10} OP_CSV OP_DROP | bip112txs_vary_OP_CSV_9 - 16 txs with nSequence = 9 evaluated against varying {relative_locktimes of 10} OP_CSV OP_DROP | ||||
bip112tx_special - test negative argument to OP_CSV | bip112tx_special - test negative argument to OP_CSV | ||||
""" | """ | ||||
from test_framework.test_framework import ComparisonTestFramework | from test_framework.test_framework import ComparisonTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.mininode import ToHex, CTransaction, NetworkThread | from test_framework.mininode import ToHex, FromHex, CTransaction, NetworkThread | ||||
from test_framework.blocktools import create_coinbase, create_block | from test_framework.blocktools import create_coinbase, create_block | ||||
from test_framework.comptool import TestInstance, TestManager | from test_framework.comptool import TestInstance, TestManager | ||||
from test_framework.script import * | from test_framework.script import * | ||||
from io import BytesIO | |||||
import time | import time | ||||
# far in the future | # far in the future | ||||
MAGNETIC_ANOMALY_START_TIME = 2000000000 | MAGNETIC_ANOMALY_START_TIME = 2000000000 | ||||
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 | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | 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', | ||||
'-magneticanomalyactivationtime=%d' % MAGNETIC_ANOMALY_START_TIME]] | '-magneticanomalyactivationtime=%d' % MAGNETIC_ANOMALY_START_TIME]] | ||||
def run_test(self): | def run_test(self): | ||||
test = TestManager(self, self.options.tmpdir) | test = TestManager(self, self.options.tmpdir) | ||||
test.add_all_connections(self.nodes) | test.add_all_connections(self.nodes) | ||||
NetworkThread().start() # Start up network handling in another thread | # Start up network handling in another thread | ||||
NetworkThread().start() | |||||
test.run() | test.run() | ||||
def send_generic_input_tx(self, node, coinbases): | def send_generic_input_tx(self, node, coinbases): | ||||
amount = Decimal("49.99") | amount = Decimal("49.99") | ||||
return node.sendrawtransaction(ToHex(self.sign_transaction(node, self.create_transaction(node, node.getblock(coinbases.pop())['tx'][0], self.nodeaddress, amount)))) | return node.sendrawtransaction(ToHex(self.sign_transaction(node, self.create_transaction(node, node.getblock(coinbases.pop())['tx'][0], self.nodeaddress, amount)))) | ||||
def create_transaction(self, node, txid, to_address, amount): | def create_transaction(self, node, txid, to_address, amount): | ||||
inputs = [{"txid": txid, "vout": 0}] | inputs = [{"txid": txid, "vout": 0}] | ||||
outputs = {to_address: amount} | outputs = {to_address: amount} | ||||
rawtx = node.createrawtransaction(inputs, outputs) | rawtx = node.createrawtransaction(inputs, outputs) | ||||
tx = CTransaction() | tx = FromHex(CTransaction(), rawtx) | ||||
f = BytesIO(hex_str_to_bytes(rawtx)) | |||||
tx.deserialize(f) | |||||
return tx | return tx | ||||
def sign_transaction(self, node, unsignedtx): | def sign_transaction(self, node, unsignedtx): | ||||
rawtx = ToHex(unsignedtx) | rawtx = ToHex(unsignedtx) | ||||
signresult = node.signrawtransaction(rawtx) | signresult = node.signrawtransaction(rawtx) | ||||
tx = CTransaction() | tx = FromHex(CTransaction(), signresult['hex']) | ||||
f = BytesIO(hex_str_to_bytes(signresult['hex'])) | |||||
tx.deserialize(f) | |||||
return tx | return tx | ||||
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, True]) | ||||
self.last_block_time += 600 | self.last_block_time += 600 | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0): | ||||
for b25 in range(2): | for b25 in range(2): | ||||
b22txs = [] | b22txs = [] | ||||
for b22 in range(2): | for b22 in range(2): | ||||
b18txs = [] | b18txs = [] | ||||
for b18 in range(2): | for b18 in range(2): | ||||
tx = self.create_transaction( | tx = self.create_transaction( | ||||
self.nodes[0], bip112inputs[i], self.nodeaddress, Decimal("49.98")) | self.nodes[0], bip112inputs[i], self.nodeaddress, Decimal("49.98")) | ||||
i += 1 | i += 1 | ||||
if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed | # if varying OP_CSV, nSequence is fixed | ||||
if (varyOP_CSV): | |||||
tx.vin[0].nSequence = base_relative_locktime + \ | tx.vin[0].nSequence = base_relative_locktime + \ | ||||
locktime_delta | locktime_delta | ||||
else: # vary nSequence instead, OP_CSV is fixed | # vary nSequence instead, OP_CSV is fixed | ||||
else: | |||||
tx.vin[0].nSequence = relative_locktimes[b31][b25][b22][b18] + \ | tx.vin[0].nSequence = relative_locktimes[b31][b25][b22][b18] + \ | ||||
locktime_delta | locktime_delta | ||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
signtx = self.sign_transaction(self.nodes[0], tx) | signtx = self.sign_transaction(self.nodes[0], tx) | ||||
if (varyOP_CSV): | if (varyOP_CSV): | ||||
signtx.vin[0].scriptSig = CScript( | signtx.vin[0].scriptSig = CScript( | ||||
[relative_locktimes[b31][b25][b22][b18], OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig))) | [relative_locktimes[b31][b25][b22][b18], OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig))) | ||||
else: | else: | ||||
Show All 11 Lines | def get_tests(self): | ||||
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) | ||||
self.tipheight = 82 # height of the next block to build | # height of the next block to build | ||||
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 | # 489 more version 4 blocks | ||||
test_blocks = self.generate_blocks(489) | test_blocks = self.generate_blocks(489) | ||||
yield TestInstance(test_blocks, sync_every_block=False) # 1 | # 1 | ||||
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 | ||||
Show All 31 Lines | def get_tests(self): | ||||
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) | ||||
yield TestInstance(test_blocks, sync_every_block=False) # 5 | # 2 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | |||||
# 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 | ||||
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")) | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
# add BIP 68 txs | # add BIP 68 txs | ||||
success_txs.extend(all_rlt_txs(bip68txs_v1)) | success_txs.extend(all_rlt_txs(bip68txs_v1)) | ||||
# add BIP 112 with seq=10 txs | # add BIP 112 with seq=10 txs | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v1)) | success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v1)) | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_v1)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_v1)) | ||||
# 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(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)) | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) # 6 | # 3 | ||||
schancel: I guess some tests were lost? Can I ask that you possibly add "Test #3" I was a bit confused… | |||||
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 ### | ### 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) | ||||
# add BIP 68 txs | # add BIP 68 txs | ||||
success_txs.extend(all_rlt_txs(bip68txs_v2)) | success_txs.extend(all_rlt_txs(bip68txs_v2)) | ||||
# add BIP 112 with seq=10 txs | # add BIP 112 with seq=10 txs | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v2)) | success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v2)) | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_v2)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_v2)) | ||||
# 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(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)) | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) # 7 | # 4 | ||||
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()) | ||||
# 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) | ||||
yield TestInstance(test_blocks, sync_every_block=False) # 8 | # 5 | ||||
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()) | ||||
################################# | ################################# | ||||
### After Soft Forks Activate ### | ### After Soft Forks Activate ### | ||||
################################# | ################################# | ||||
### BIP 113 ### | ### 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) | ||||
for bip113tx in [bip113signed1, bip113signed2]: | for bip113tx in [bip113signed1, bip113signed2]: | ||||
# 9,10 | # 6, 7 | ||||
yield TestInstance([[self.create_test_block([bip113tx]), False]]) | yield TestInstance([[self.create_test_block([bip113tx]), 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 = self.sign_transaction(self.nodes[0], bip113tx_v1) | bip113signed1 = self.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 = self.sign_transaction(self.nodes[0], bip113tx_v2) | bip113signed2 = self.sign_transaction(self.nodes[0], bip113tx_v2) | ||||
for bip113tx in [bip113signed1, bip113signed2]: | for bip113tx in [bip113signed1, bip113signed2]: | ||||
# 11,12 | # 8 ,9 | ||||
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) | ||||
yield TestInstance(test_blocks, sync_every_block=False) # 13 | # 10 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | |||||
### BIP 68 ### | ### BIP 68 ### | ||||
### Version 1 txs ### | ### Version 1 txs ### | ||||
# All 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)) | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) # 14 | # 11 | ||||
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 ### | ### 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]) | ||||
# 15 | # 12 | ||||
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()) | ||||
# 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 = [] | bip68timetxs = [] | ||||
for b25 in range(2): | for b25 in range(2): | ||||
for b18 in range(2): | for b18 in range(2): | ||||
bip68timetxs.append(bip68txs_v2[0][b25][1][b18]) | bip68timetxs.append(bip68txs_v2[0][b25][1][b18]) | ||||
for tx in bip68timetxs: | for tx in bip68timetxs: | ||||
# 16 - 19 | # 13 - 16 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block([tx]), False]]) | ||||
bip68heighttxs = [] | bip68heighttxs = [] | ||||
for b25 in range(2): | for b25 in range(2): | ||||
for b18 in range(2): | for b18 in range(2): | ||||
bip68heighttxs.append(bip68txs_v2[0][b25][0][b18]) | bip68heighttxs.append(bip68txs_v2[0][b25][0][b18]) | ||||
for tx in bip68heighttxs: | for tx in bip68heighttxs: | ||||
# 20 - 23 | # 17 - 20 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block([tx]), False]]) | ||||
# Advance one block to 581 | # Advance one block to 581 | ||||
test_blocks = self.generate_blocks(1) | test_blocks = self.generate_blocks(1) | ||||
yield TestInstance(test_blocks, sync_every_block=False) # 24 | # 21 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | |||||
# 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) | ||||
# 25 | # 22 | ||||
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()) | ||||
for tx in bip68heighttxs: | for tx in bip68heighttxs: | ||||
# 26 - 29 | # 23 - 26 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block([tx]), False]]) | ||||
# Advance one block to 582 | # Advance one block to 582 | ||||
test_blocks = self.generate_blocks(1) | test_blocks = self.generate_blocks(1) | ||||
yield TestInstance(test_blocks, sync_every_block=False) # 30 | # 27 | ||||
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) | ||||
# 31 | # 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 ### | ### BIP 112 ### | ||||
### Version 1 txs ### | ### Version 1 txs ### | ||||
# -1 OP_CSV tx should fail | # -1 OP_CSV tx should fail | ||||
# 32 | # 29 | ||||
yield TestInstance([[self.create_test_block([bip112tx_special_v1]), False]]) | yield TestInstance([[self.create_test_block([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): | ||||
for b22 in range(2): | for b22 in range(2): | ||||
for b18 in range(2): | for b18 in range(2): | ||||
success_txs.append( | success_txs.append( | ||||
bip112txs_vary_OP_CSV_v1[1][b25][b22][b18]) | bip112txs_vary_OP_CSV_v1[1][b25][b22][b18]) | ||||
success_txs.append( | success_txs.append( | ||||
bip112txs_vary_OP_CSV_9_v1[1][b25][b22][b18]) | bip112txs_vary_OP_CSV_9_v1[1][b25][b22][b18]) | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) # 33 | # 30 | ||||
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()) | ||||
# 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 = [] | fail_txs = [] | ||||
fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v1)) | fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_v1)) | ||||
fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1)) | fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1)) | ||||
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): | ||||
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: | ||||
# 34 - 81 | # 31 - 78 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block([tx]), False]]) | ||||
### Version 2 txs ### | ### Version 2 txs ### | ||||
# -1 OP_CSV tx should fail | # -1 OP_CSV tx should fail | ||||
# 82 | # 79 | ||||
yield TestInstance([[self.create_test_block([bip112tx_special_v2]), False]]) | yield TestInstance([[self.create_test_block([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 (all sequence locks are met) | # version 2 txs should pass (all sequence locks are met) | ||||
success_txs = [] | success_txs = [] | ||||
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): | ||||
# 8/16 of vary_OP_CSV | # 8/16 of vary_OP_CSV | ||||
success_txs.append( | success_txs.append( | ||||
bip112txs_vary_OP_CSV_v2[1][b25][b22][b18]) | bip112txs_vary_OP_CSV_v2[1][b25][b22][b18]) | ||||
# 8/16 of vary_OP_CSV_9 | # 8/16 of vary_OP_CSV_9 | ||||
success_txs.append( | success_txs.append( | ||||
bip112txs_vary_OP_CSV_9_v2[1][b25][b22][b18]) | bip112txs_vary_OP_CSV_9_v2[1][b25][b22][b18]) | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) # 83 | # 80 | ||||
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()) | ||||
## 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 = [] | fail_txs = [] | ||||
# 16/16 of vary_nSequence_9 | # 16/16 of vary_nSequence_9 | ||||
fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2)) | fail_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2)) | ||||
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): | ||||
# 16/16 of vary_OP_CSV_9 | # 16/16 of vary_OP_CSV_9 | ||||
fail_txs.append( | fail_txs.append( | ||||
bip112txs_vary_OP_CSV_9_v2[0][b25][b22][b18]) | bip112txs_vary_OP_CSV_9_v2[0][b25][b22][b18]) | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# 84 - 107 | # 81 - 104 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block([tx]), 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 = [] | fail_txs = [] | ||||
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): | ||||
# 8/16 of vary_nSequence | # 8/16 of vary_nSequence | ||||
fail_txs.append( | fail_txs.append( | ||||
bip112txs_vary_nSequence_v2[1][b25][b22][b18]) | bip112txs_vary_nSequence_v2[1][b25][b22][b18]) | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# 108-115 | # 105-112 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block([tx]), False]]) | ||||
# If sequencelock types mismatch, tx should fail | # If sequencelock types mismatch, tx should fail | ||||
fail_txs = [] | fail_txs = [] | ||||
for b25 in range(2): | for b25 in range(2): | ||||
for b18 in range(2): | for b18 in range(2): | ||||
# 12/16 of vary_nSequence | # 12/16 of vary_nSequence | ||||
fail_txs.append(bip112txs_vary_nSequence_v2[0][b25][1][b18]) | fail_txs.append(bip112txs_vary_nSequence_v2[0][b25][1][b18]) | ||||
# 12/16 of vary_OP_CSV | # 12/16 of vary_OP_CSV | ||||
fail_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][1][b18]) | fail_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][1][b18]) | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# 116-123 | # 113-120 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block([tx]), False]]) | ||||
# Remaining txs should pass, just test masking works properly | # Remaining txs should pass, just test masking works properly | ||||
success_txs = [] | success_txs = [] | ||||
for b25 in range(2): | for b25 in range(2): | ||||
for b18 in range(2): | for b18 in range(2): | ||||
# 16/16 of vary_nSequence | # 16/16 of vary_nSequence | ||||
success_txs.append(bip112txs_vary_nSequence_v2[0][b25][0][b18]) | success_txs.append(bip112txs_vary_nSequence_v2[0][b25][0][b18]) | ||||
# 16/16 of vary_OP_CSV | # 16/16 of vary_OP_CSV | ||||
success_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][0][b18]) | success_txs.append(bip112txs_vary_OP_CSV_v2[0][b25][0][b18]) | ||||
# 124 | # 121 | ||||
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()) | ||||
# 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 b25 in range(2): | for b25 in range(2): | ||||
for b18 in range(2): | for b18 in range(2): | ||||
tx = bip112txs_vary_OP_CSV_v2[0][b25][1][b18] | tx = bip112txs_vary_OP_CSV_v2[0][b25][1][b18] | ||||
tx.vin[0].nSequence = base_relative_locktime | seq_type_flag | tx.vin[0].nSequence = base_relative_locktime | seq_type_flag | ||||
signtx = self.sign_transaction(self.nodes[0], tx) | signtx = self.sign_transaction(self.nodes[0], tx) | ||||
time_txs.append(signtx) | time_txs.append(signtx) | ||||
yield TestInstance([[self.create_test_block(time_txs), True]]) # 125 | # 122 | ||||
yield TestInstance([[self.create_test_block(time_txs), True]]) | |||||
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() |
I guess some tests were lost? Can I ask that you possibly add "Test #3" I was a bit confused as to what the comment was for.