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, FromHex, CTransaction, NetworkThread | from test_framework.mininode import ToHex, FromHex, CTransaction, NetworkThread, COIN | ||||
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 * | ||||
import time | import time | ||||
# far in the future | # far in the future | ||||
MAGNETIC_ANOMALY_START_TIME = 2000000000 | MAGNETIC_ANOMALY_START_TIME = 2000000000 | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | def create_transaction(self, node, txid, to_address, amount): | ||||
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 = FromHex(CTransaction(), signresult['hex']) | tx = FromHex(CTransaction(), signresult['hex']) | ||||
return tx | return tx | ||||
def spend_tx(self, node, prev_tx): | |||||
spendtx = self.create_transaction( | |||||
node, prev_tx.hash, self.nodeaddress, (prev_tx.vout[0].nValue - 1000) / COIN) | |||||
spendtx.nVersion = prev_tx.nVersion | |||||
spendtx.rehash() | |||||
return spendtx | |||||
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 | ||||
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) | ||||
block.nVersion = version | block.nVersion = version | ||||
block.vtx.extend(txs) | block.vtx.extend(txs) | ||||
block.hashMerkleRoot = block.calc_merkle_root() | block.hashMerkleRoot = block.calc_merkle_root() | ||||
block.rehash() | block.rehash() | ||||
block.solve() | block.solve() | ||||
return block | return block | ||||
# Create a block with given txs, and spend these txs in the same block. | |||||
# Spending utxos in the same block is OK as long as nSequence is not enforced. | |||||
# Otherwise a number of intermediate blocks should be generated, and this | |||||
# method should not be used. | |||||
def create_test_block_spend_utxos(self, node, txs, version=536870912): | |||||
block = self.create_test_block(txs, version) | |||||
block.vtx.extend([self.spend_tx(node, tx) for tx in txs]) | |||||
block.hashMerkleRoot = block.calc_merkle_root() | |||||
block.rehash() | |||||
block.solve() | |||||
return block | |||||
def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0): | def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0): | ||||
txs = [] | txs = [] | ||||
assert(len(bip68inputs) >= 16) | assert(len(bip68inputs) >= 16) | ||||
i = 0 | i = 0 | ||||
for b31 in range(2): | for b31 in range(2): | ||||
b25txs = [] | b25txs = [] | ||||
for b25 in range(2): | for b25 in range(2): | ||||
b22txs = [] | b22txs = [] | ||||
Show All 11 Lines | def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0): | ||||
b25txs.append(b22txs) | b25txs.append(b22txs) | ||||
txs.append(b25txs) | txs.append(b25txs) | ||||
return txs | return txs | ||||
def create_bip112special(self, input, txversion): | def create_bip112special(self, input, txversion): | ||||
tx = self.create_transaction( | tx = self.create_transaction( | ||||
self.nodes[0], input, self.nodeaddress, Decimal("49.98")) | self.nodes[0], input, self.nodeaddress, Decimal("49.98")) | ||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
tx.vout[0].scriptPubKey = CScript( | |||||
[-1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | |||||
tx.rehash() | |||||
signtx = self.sign_transaction(self.nodes[0], tx) | signtx = self.sign_transaction(self.nodes[0], tx) | ||||
signtx.vin[0].scriptSig = CScript( | signtx.rehash() | ||||
[-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig))) | |||||
return signtx | return signtx | ||||
def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0): | def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0): | ||||
txs = [] | txs = [] | ||||
assert(len(bip112inputs) >= 16) | assert(len(bip112inputs) >= 16) | ||||
i = 0 | i = 0 | ||||
for b31 in range(2): | for b31 in range(2): | ||||
b25txs = [] | b25txs = [] | ||||
Show All 9 Lines | def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, locktime_delta=0): | ||||
if (varyOP_CSV): | if (varyOP_CSV): | ||||
tx.vin[0].nSequence = base_relative_locktime + \ | tx.vin[0].nSequence = base_relative_locktime + \ | ||||
locktime_delta | locktime_delta | ||||
# vary nSequence instead, OP_CSV is fixed | # vary nSequence instead, OP_CSV is fixed | ||||
else: | 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) | |||||
if (varyOP_CSV): | if (varyOP_CSV): | ||||
signtx.vin[0].scriptSig = CScript( | tx.vout[0].scriptPubKey = 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, OP_TRUE]) | ||||
else: | else: | ||||
signtx.vin[0].scriptSig = CScript( | tx.vout[0].scriptPubKey = CScript( | ||||
[base_relative_locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(signtx.vin[0].scriptSig))) | [base_relative_locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | ||||
tx.rehash() | |||||
signtx = self.sign_transaction(self.nodes[0], tx) | |||||
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): | ||||
# Enough to build up to 1000 blocks 10 minutes apart without worrying | # Enough to build up to 1000 blocks 10 minutes apart without worrying | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
### Version 1 txs ### | ### 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)) | |||||
# 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([self.spend_tx(self.nodes[0], tx) | |||||
for tx in 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)) | ||||
success_txs.extend([self.spend_tx(self.nodes[0], tx) | |||||
for tx in 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([self.spend_tx(self.nodes[0], tx) | |||||
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) | |||||
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 ### | ### 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)) | |||||
# 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([self.spend_tx(self.nodes[0], tx) | |||||
for tx in 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)) | ||||
success_txs.extend([self.spend_tx(self.nodes[0], tx) | |||||
for tx in 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([self.spend_tx(self.nodes[0], tx) | |||||
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([self.spend_tx(self.nodes[0], tx) | |||||
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]]) | 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) | ||||
# Test #5 | # Test #5 | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
# 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 ### | ### BIP 112 ### | ||||
### Version 1 txs ### | ### 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([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): | ||||
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]) | ||||
# Test #30 | # Test #30 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], 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: | ||||
# Test #31 - Test #78 | # Test #31 - Test #78 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [tx]), False]]) | ||||
### Version 2 txs ### | ### 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([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 (all sequence locks are met) | # version 2 txs should 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): | ||||
# 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]) | ||||
# Test #80 | # Test #80 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], 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: | ||||
# Test #81 - Test #104 | # Test #81 - Test #104 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [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: | ||||
# Test #105 - Test #112 | # Test #105 - Test #112 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [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: | ||||
# Test #113 - Test #120 | # Test #113 - Test #120 | ||||
yield TestInstance([[self.create_test_block([tx]), False]]) | yield TestInstance([[self.create_test_block_spend_utxos(self.nodes[0], [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]) | ||||
# Test #121 | # Test #121 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | yield TestInstance([[self.create_test_block(success_txs), True]]) | ||||
# Spending the previous block utxos requires a difference of 10 blocks (nSequence = 10). | |||||
# Generate 9 blocks then spend in the 10th | |||||
block = self.nodes[0].getbestblockhash() | |||||
self.last_block_time += 600 | |||||
self.tip = int("0x" + block, 0) | |||||
self.tipheight += 1 | |||||
# Test #122 | |||||
yield TestInstance(self.generate_blocks(9), sync_every_block=False) | |||||
spend_txs = [] | |||||
for tx in success_txs: | |||||
raw_tx = self.spend_tx(self.nodes[0], tx) | |||||
raw_tx.vin[0].nSequence = base_relative_locktime | |||||
raw_tx.rehash() | |||||
spend_txs.append(raw_tx) | |||||
# Test #123 | |||||
yield TestInstance([[self.create_test_block(spend_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 | |||||
signtx = self.sign_transaction(self.nodes[0], tx) | signtx = self.sign_transaction(self.nodes[0], tx) | ||||
time_txs.append(signtx) | time_txs.append(signtx) | ||||
# Test #122 | # Test #124 | ||||
yield TestInstance([[self.create_test_block(time_txs), True]]) | yield TestInstance([[self.create_test_block(time_txs), True]]) | ||||
# Spending the previous block utxos requires a block time difference of | |||||
# at least 10 * 512s (nSequence = 10). | |||||
# Generate 8 blocks then spend in the 9th (9 * 600 > 10 * 512) | |||||
block = self.nodes[0].getbestblockhash() | |||||
self.last_block_time += 600 | |||||
self.tip = int("0x" + block, 0) | |||||
self.tipheight += 1 | |||||
# Test #125 | |||||
yield TestInstance(self.generate_blocks(8), sync_every_block=False) | |||||
spend_txs = [] | |||||
for tx in time_txs: | |||||
raw_tx = self.spend_tx(self.nodes[0], tx) | |||||
raw_tx.vin[0].nSequence = base_relative_locktime | seq_type_flag | |||||
raw_tx.rehash() | |||||
spend_txs.append(raw_tx) | |||||
# Test #126 | |||||
yield TestInstance([[self.create_test_block(spend_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() |