Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_csv_activation.py
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | def relative_locktime(sdf, srhb, stf, srlb): | ||||
if stf: | if stf: | ||||
locktime |= SEQ_TYPE_FLAG | locktime |= SEQ_TYPE_FLAG | ||||
if srlb: | if srlb: | ||||
locktime |= SEQ_RANDOM_LOW_BIT | locktime |= SEQ_RANDOM_LOW_BIT | ||||
return locktime | return locktime | ||||
def all_rlt_txs(txs): | def all_rlt_txs(txs): | ||||
return [tx['tx'] for tx in txs] | return [tx["tx"] for tx in txs] | ||||
def get_csv_status(node): | def get_csv_status(node): | ||||
height = node.getblockchaininfo()['blocks'] | height = node.getblockchaininfo()["blocks"] | ||||
return height >= 576 | return height >= 576 | ||||
def create_transaction(node, txid, to_address, *, amount): | def create_transaction(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 = FromHex(CTransaction(), rawtx) | tx = FromHex(CTransaction(), rawtx) | ||||
return tx | return tx | ||||
def sign_transaction(node, unsignedtx): | def sign_transaction(node, unsignedtx): | ||||
rawtx = ToHex(unsignedtx) | rawtx = ToHex(unsignedtx) | ||||
signresult = node.signrawtransactionwithwallet(rawtx) | signresult = node.signrawtransactionwithwallet(rawtx) | ||||
tx = FromHex(CTransaction(), signresult['hex']) | tx = FromHex(CTransaction(), signresult["hex"]) | ||||
return tx | return tx | ||||
def spend_tx(node, prev_tx, address): | def spend_tx(node, prev_tx, address): | ||||
spendtx = create_transaction( | spendtx = create_transaction( | ||||
node, prev_tx.hash, address, amount=(prev_tx.vout[0].nValue - 1000) / XEC) | node, prev_tx.hash, address, amount=(prev_tx.vout[0].nValue - 1000) / XEC | ||||
) | |||||
spendtx.nVersion = prev_tx.nVersion | spendtx.nVersion = prev_tx.nVersion | ||||
pad_tx(spendtx) | pad_tx(spendtx) | ||||
spendtx.rehash() | spendtx.rehash() | ||||
return spendtx | return spendtx | ||||
def create_bip112special(node, txid, txversion, address): | def create_bip112special(node, txid, txversion, address): | ||||
tx = create_transaction( | tx = create_transaction(node, txid, address, amount=Decimal("49980000")) | ||||
node, txid, address, amount=Decimal("49980000")) | |||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
tx.vout[0].scriptPubKey = CScript( | tx.vout[0].scriptPubKey = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | ||||
[-1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | |||||
tx.rehash() | tx.rehash() | ||||
signtx = sign_transaction(node, tx) | signtx = sign_transaction(node, tx) | ||||
signtx.rehash() | signtx.rehash() | ||||
return signtx | return signtx | ||||
def send_generic_input_tx(node, coinbases, address): | def send_generic_input_tx(node, coinbases, address): | ||||
return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction( | return node.sendrawtransaction( | ||||
node, node.getblock(coinbases.pop())['tx'][0], address, amount=Decimal("49990000"))))) | ToHex( | ||||
sign_transaction( | |||||
node, | |||||
create_transaction( | |||||
node, | |||||
node.getblock(coinbases.pop())["tx"][0], | |||||
address, | |||||
amount=Decimal("49990000"), | |||||
), | |||||
) | |||||
) | |||||
) | |||||
def create_bip68txs(node, bip68inputs, txversion, address, locktime_delta=0): | def create_bip68txs(node, bip68inputs, txversion, address, locktime_delta=0): | ||||
"""Returns a list of bip68 transactions with different bits set.""" | """Returns a list of bip68 transactions with different bits set.""" | ||||
txs = [] | txs = [] | ||||
assert len(bip68inputs) >= 16 | assert len(bip68inputs) >= 16 | ||||
for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | ||||
locktime = relative_locktime(sdf, srhb, stf, srlb) | locktime = relative_locktime(sdf, srhb, stf, srlb) | ||||
tx = create_transaction( | tx = create_transaction( | ||||
node, bip68inputs[i], address, amount=Decimal("49980000")) | node, bip68inputs[i], address, amount=Decimal("49980000") | ||||
) | |||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
tx.vin[0].nSequence = locktime + locktime_delta | tx.vin[0].nSequence = locktime + locktime_delta | ||||
tx = sign_transaction(node, tx) | tx = sign_transaction(node, tx) | ||||
tx.rehash() | tx.rehash() | ||||
txs.append({'tx': tx, 'sdf': sdf, 'stf': stf}) | txs.append({"tx": tx, "sdf": sdf, "stf": stf}) | ||||
return txs | return txs | ||||
def create_bip112txs(node, bip112inputs, varyOP_CSV, | def create_bip112txs( | ||||
txversion, address, locktime_delta=0): | node, bip112inputs, varyOP_CSV, txversion, address, locktime_delta=0 | ||||
): | |||||
"""Returns a list of bip112 transactions with different bits set.""" | """Returns a list of bip112 transactions with different bits set.""" | ||||
txs = [] | txs = [] | ||||
assert len(bip112inputs) >= 16 | assert len(bip112inputs) >= 16 | ||||
for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | ||||
locktime = relative_locktime(sdf, srhb, stf, srlb) | locktime = relative_locktime(sdf, srhb, stf, srlb) | ||||
tx = create_transaction( | tx = create_transaction( | ||||
node, bip112inputs[i], address, amount=Decimal("49980000")) | node, bip112inputs[i], address, amount=Decimal("49980000") | ||||
if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed | ) | ||||
if varyOP_CSV: # if varying OP_CSV, nSequence is fixed | |||||
tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta | tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta | ||||
else: # vary nSequence instead, OP_CSV is fixed | else: # vary nSequence instead, OP_CSV is fixed | ||||
tx.vin[0].nSequence = locktime + locktime_delta | tx.vin[0].nSequence = locktime + locktime_delta | ||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
if (varyOP_CSV): | if varyOP_CSV: | ||||
tx.vout[0].scriptPubKey = CScript( | tx.vout[0].scriptPubKey = CScript( | ||||
[locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | [locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE] | ||||
) | |||||
else: | else: | ||||
tx.vout[0].scriptPubKey = CScript( | tx.vout[0].scriptPubKey = CScript( | ||||
[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(BitcoinTestFramework): | 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=noban@127.0.0.1']] | self.extra_args = [["-whitelist=noban@127.0.0.1"]] | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def generate_blocks(self, number): | def generate_blocks(self, number): | ||||
test_blocks = [] | test_blocks = [] | ||||
for _ in range(number): | for _ in range(number): | ||||
block = self.create_test_block([]) | block = self.create_test_block([]) | ||||
test_blocks.append(block) | 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.tipheight + 1), self.last_block_time + 600) | self.tip, create_coinbase(self.tipheight + 1), self.last_block_time + 600 | ||||
) | |||||
block.nVersion = version | block.nVersion = version | ||||
block.vtx.extend(txs) | block.vtx.extend(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 | ||||
# Create a block with given txs, and spend these txs in the same 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. | # 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 | # Otherwise a number of intermediate blocks should be generated, and this | ||||
# method should not be used. | # method should not be used. | ||||
def create_test_block_spend_utxos(self, node, txs, version=536870912): | 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 send_blocks(self, blocks, success=True): | def send_blocks(self, blocks, success=True): | ||||
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. | """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.""" | Call with success = False if the tip shouldn't advance to the most recent block. | ||||
self.helper_peer.send_blocks_and_test( | """ | ||||
blocks, self.nodes[0], success=success) | self.helper_peer.send_blocks_and_test(blocks, self.nodes[0], success=success) | ||||
def run_test(self): | def run_test(self): | ||||
self.helper_peer = self.nodes[0].add_p2p_connection(P2PDataStore()) | self.helper_peer = self.nodes[0].add_p2p_connection(P2PDataStore()) | ||||
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 | # Enough so that the generated blocks will still all be before | ||||
# long_past_time | # 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.generate( | self.coinbase_blocks = self.generate(self.nodes[0], 1 + 16 + 2 * 32 + 1) | ||||
self.nodes[0], 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(self.nodes[0].getbestblockhash(), 16) | self.tip = int(self.nodes[0].getbestblockhash(), 16) | ||||
self.nodeaddress = self.nodes[0].getnewaddress() | self.nodeaddress = self.nodes[0].getnewaddress() | ||||
Show All 11 Lines | def run_test(self): | ||||
# 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 _ in range(16): | for _ in range(16): | ||||
bip68inputs.append(send_generic_input_tx( | bip68inputs.append( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress)) | send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress | |||||
) | |||||
) | |||||
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be | # 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be | ||||
# prepended to spending scriptSig) | # prepended to spending scriptSig) | ||||
bip112basicinputs = [] | bip112basicinputs = [] | ||||
for _ in range(2): | for _ in range(2): | ||||
inputs = [] | inputs = [] | ||||
for _ in range(16): | for _ in range(16): | ||||
inputs.append(send_generic_input_tx( | inputs.append( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress)) | send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress | |||||
) | |||||
) | |||||
bip112basicinputs.append(inputs) | bip112basicinputs.append(inputs) | ||||
# 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP | # 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP | ||||
# (actually will be prepended to spending scriptSig) | # (actually will be prepended to spending scriptSig) | ||||
bip112diverseinputs = [] | bip112diverseinputs = [] | ||||
for _ in range(2): | for _ in range(2): | ||||
inputs = [] | inputs = [] | ||||
for _ in range(16): | for _ in range(16): | ||||
inputs.append(send_generic_input_tx( | inputs.append( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress)) | send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress | |||||
) | |||||
) | |||||
bip112diverseinputs.append(inputs) | bip112diverseinputs.append(inputs) | ||||
# 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to | # 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to | ||||
# spending scriptSig) | # spending scriptSig) | ||||
bip112specialinput = send_generic_input_tx( | bip112specialinput = send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress) | self.nodes[0], self.coinbase_blocks, self.nodeaddress | ||||
) | |||||
# 1 normal input | # 1 normal input | ||||
bip113input = send_generic_input_tx( | bip113input = send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress) | self.nodes[0], self.coinbase_blocks, self.nodeaddress | ||||
) | |||||
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.generate(self.nodes[0], 1)[0] | inputblockhash = self.generate(self.nodes[0], 1)[0] | ||||
self.nodes[0].setmocktime(0) | self.nodes[0].setmocktime(0) | ||||
self.tip = int(inputblockhash, 16) | self.tip = int(inputblockhash, 16) | ||||
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 | ||||
self.send_blocks(test_blocks) | self.send_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 | ||||
bip113tx_v1 = create_transaction( | bip113tx_v1 = create_transaction( | ||||
self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49980000")) | self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49980000") | ||||
) | |||||
bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | ||||
bip113tx_v1.nVersion = 1 | bip113tx_v1.nVersion = 1 | ||||
bip113tx_v2 = create_transaction( | bip113tx_v2 = create_transaction( | ||||
self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49980000")) | self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49980000") | ||||
) | |||||
bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE | bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE | ||||
bip113tx_v2.nVersion = 2 | bip113tx_v2.nVersion = 2 | ||||
# For BIP68 test all 16 relative sequence locktimes | # For BIP68 test all 16 relative sequence locktimes | ||||
bip68txs_v1 = create_bip68txs( | bip68txs_v1 = create_bip68txs(self.nodes[0], bip68inputs, 1, self.nodeaddress) | ||||
self.nodes[0], bip68inputs, 1, self.nodeaddress) | bip68txs_v2 = create_bip68txs(self.nodes[0], bip68inputs, 2, self.nodeaddress) | ||||
bip68txs_v2 = create_bip68txs( | |||||
self.nodes[0], bip68inputs, 2, self.nodeaddress) | |||||
# For BIP112 test: | # For BIP112 test: | ||||
# 16 relative sequence locktimes of 10 against 10 OP_CSV OP_DROP inputs | # 16 relative sequence locktimes of 10 against 10 OP_CSV OP_DROP inputs | ||||
bip112txs_vary_nSequence_v1 = create_bip112txs( | bip112txs_vary_nSequence_v1 = create_bip112txs( | ||||
self.nodes[0], bip112basicinputs[0], False, 1, self.nodeaddress) | self.nodes[0], bip112basicinputs[0], False, 1, self.nodeaddress | ||||
) | |||||
bip112txs_vary_nSequence_v2 = create_bip112txs( | bip112txs_vary_nSequence_v2 = create_bip112txs( | ||||
self.nodes[0], bip112basicinputs[0], False, 2, self.nodeaddress) | self.nodes[0], bip112basicinputs[0], False, 2, self.nodeaddress | ||||
) | |||||
# 16 relative sequence locktimes of 9 against 10 OP_CSV OP_DROP inputs | # 16 relative sequence locktimes of 9 against 10 OP_CSV OP_DROP inputs | ||||
bip112txs_vary_nSequence_9_v1 = create_bip112txs( | bip112txs_vary_nSequence_9_v1 = create_bip112txs( | ||||
self.nodes[0], bip112basicinputs[1], False, 1, self.nodeaddress, -1) | self.nodes[0], bip112basicinputs[1], False, 1, self.nodeaddress, -1 | ||||
) | |||||
bip112txs_vary_nSequence_9_v2 = create_bip112txs( | bip112txs_vary_nSequence_9_v2 = create_bip112txs( | ||||
self.nodes[0], bip112basicinputs[1], False, 2, self.nodeaddress, -1) | self.nodes[0], bip112basicinputs[1], False, 2, self.nodeaddress, -1 | ||||
) | |||||
# sequence lock time of 10 against 16 (relative_lock_time) OP_CSV | # sequence lock time of 10 against 16 (relative_lock_time) OP_CSV | ||||
# OP_DROP inputs | # OP_DROP inputs | ||||
bip112txs_vary_OP_CSV_v1 = create_bip112txs( | bip112txs_vary_OP_CSV_v1 = create_bip112txs( | ||||
self.nodes[0], bip112diverseinputs[0], True, 1, self.nodeaddress) | self.nodes[0], bip112diverseinputs[0], True, 1, self.nodeaddress | ||||
) | |||||
bip112txs_vary_OP_CSV_v2 = create_bip112txs( | bip112txs_vary_OP_CSV_v2 = create_bip112txs( | ||||
self.nodes[0], bip112diverseinputs[0], True, 2, self.nodeaddress) | self.nodes[0], bip112diverseinputs[0], True, 2, self.nodeaddress | ||||
) | |||||
# sequence lock time of 9 against 16 (relative_lock_time) OP_CSV | # sequence lock time of 9 against 16 (relative_lock_time) OP_CSV | ||||
# OP_DROP inputs | # OP_DROP inputs | ||||
bip112txs_vary_OP_CSV_9_v1 = create_bip112txs( | bip112txs_vary_OP_CSV_9_v1 = create_bip112txs( | ||||
self.nodes[0], bip112diverseinputs[1], True, 1, self.nodeaddress, -1) | self.nodes[0], bip112diverseinputs[1], True, 1, self.nodeaddress, -1 | ||||
) | |||||
bip112txs_vary_OP_CSV_9_v2 = create_bip112txs( | bip112txs_vary_OP_CSV_9_v2 = create_bip112txs( | ||||
self.nodes[0], bip112diverseinputs[1], True, 2, self.nodeaddress, -1) | self.nodes[0], bip112diverseinputs[1], True, 2, self.nodeaddress, -1 | ||||
) | |||||
# -1 OP_CSV OP_DROP input | # -1 OP_CSV OP_DROP input | ||||
bip112tx_special_v1 = create_bip112special( | bip112tx_special_v1 = create_bip112special( | ||||
self.nodes[0], bip112specialinput, 1, self.nodeaddress) | self.nodes[0], bip112specialinput, 1, self.nodeaddress | ||||
) | |||||
bip112tx_special_v2 = create_bip112special( | bip112tx_special_v2 = create_bip112special( | ||||
self.nodes[0], bip112specialinput, 2, self.nodeaddress) | self.nodes[0], bip112specialinput, 2, self.nodeaddress | ||||
) | |||||
self.log.info("TESTING") | self.log.info("TESTING") | ||||
self.log.info("Pre-Soft Fork Tests. All txs should pass.") | self.log.info("Pre-Soft Fork Tests. All txs should pass.") | ||||
self.log.info("Test version 1 txs") | self.log.info("Test 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 = sign_transaction(self.nodes[0], bip113tx_v1) | bip113signed1 = 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( | success_txs.append( | ||||
spend_tx(self.nodes[0], bip112tx_special_v1, self.nodeaddress)) | spend_tx(self.nodes[0], bip112tx_special_v1, self.nodeaddress) | ||||
) | |||||
# 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([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend( | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_v1)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
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([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend( | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_v1)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
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([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend( | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v1)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
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( | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v1) | |||||
] | |||||
) | |||||
# Test #3 | # Test #3 | ||||
self.send_blocks([self.create_test_block(success_txs)]) | self.send_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 | ||||
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) | bip113signed2 = 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( | success_txs.append( | ||||
spend_tx(self.nodes[0], bip112tx_special_v2, self.nodeaddress)) | spend_tx(self.nodes[0], bip112tx_special_v2, self.nodeaddress) | ||||
) | |||||
# 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([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend( | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_v2)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
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([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend( | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_v2)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
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([spend_tx(self.nodes[0], tx, self.nodeaddress) | success_txs.extend( | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v2)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
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( | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)]) | [ | ||||
spend_tx(self.nodes[0], tx, self.nodeaddress) | |||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v2) | |||||
] | |||||
) | |||||
# Test #4 | # Test #4 | ||||
self.send_blocks([self.create_test_block(success_txs)]) | self.send_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 | ||||
Show All 12 Lines | def run_test(self): | ||||
# = 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 | ||||
self.send_blocks( | self.send_blocks([self.create_test_block([bip113tx])], success=False) | ||||
[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) | ||||
Show All 14 Lines | def run_test(self): | ||||
success_txs.extend(all_rlt_txs(bip68txs_v1)) | success_txs.extend(all_rlt_txs(bip68txs_v1)) | ||||
# Test #11 | # Test #11 | ||||
self.send_blocks([self.create_test_block(success_txs)]) | self.send_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"]] | ||||
self.send_blocks([self.create_test_block(bip68success_txs)]) | self.send_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 | ||||
self.send_blocks([self.create_test_block([tx])], success=False) | self.send_blocks([self.create_test_block([tx])], success=False) | ||||
bip68heighttxs = [tx['tx'] | bip68heighttxs = [ | ||||
for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']] | tx["tx"] 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 | ||||
self.send_blocks([self.create_test_block([tx])], success=False) | self.send_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 | ||||
self.send_blocks(test_blocks,) | self.send_blocks( | ||||
test_blocks, | |||||
) | |||||
# Height txs should fail and time txs should now pass 9 * 600 > 10 * | # Height txs should fail and time txs should now pass 9 * 600 > 10 * | ||||
# 512 | # 512 | ||||
bip68success_txs.extend(bip68timetxs) | bip68success_txs.extend(bip68timetxs) | ||||
# Test #22 | # Test #22 | ||||
self.send_blocks([self.create_test_block(bip68success_txs)]) | self.send_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: | ||||
Show All 11 Lines | def run_test(self): | ||||
self.send_blocks([self.create_test_block(bip68success_txs)]) | self.send_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 | ||||
self.send_blocks([self.create_test_block_spend_utxos( | self.send_blocks( | ||||
self.nodes[0], [bip112tx_special_v1])], success=False) | [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"] for tx in bip112txs_vary_OP_CSV_9_v1 if tx["sdf"]] | ||||
success_txs += [tx['tx'] | |||||
for tx in bip112txs_vary_OP_CSV_9_v1 if tx['sdf']] | |||||
# Test #30 | # Test #30 | ||||
self.send_blocks( | self.send_blocks( | ||||
[self.create_test_block_spend_utxos(self.nodes[0], success_txs)]) | [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"] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx["sdf"]] | ||||
fail_txs += [tx['tx'] | |||||
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 | ||||
self.send_blocks([self.create_test_block_spend_utxos( | self.send_blocks( | ||||
self.nodes[0], [tx])], success=False) | [self.create_test_block_spend_utxos(self.nodes[0], [tx])], success=False | ||||
) | |||||
self.log.info("Test 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 | ||||
self.send_blocks([self.create_test_block_spend_utxos( | self.send_blocks( | ||||
self.nodes[0], [bip112tx_special_v2])], success=False) | [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"] for tx in bip112txs_vary_OP_CSV_9_v2 if tx["sdf"]] | ||||
success_txs += [tx['tx'] | |||||
for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']] | |||||
# Test #80 | # Test #80 | ||||
self.send_blocks( | self.send_blocks( | ||||
[self.create_test_block_spend_utxos(self.nodes[0], success_txs)]) | [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 | # SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all | ||||
# remaining txs ## | # 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 | ||||
self.send_blocks([self.create_test_block_spend_utxos( | self.send_blocks( | ||||
self.nodes[0], [tx])], success=False) | [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 | ||||
self.send_blocks([self.create_test_block_spend_utxos( | self.send_blocks( | ||||
self.nodes[0], [tx])], success=False) | [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 = [ | ||||
for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']] | tx["tx"] | ||||
fail_txs += [tx['tx'] | for tx in bip112txs_vary_nSequence_v2 | ||||
for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']] | if not tx["sdf"] and tx["stf"] | ||||
] | |||||
fail_txs += [ | |||||
tx["tx"] 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 | ||||
self.send_blocks([self.create_test_block_spend_utxos( | self.send_blocks( | ||||
self.nodes[0], [tx])], success=False) | [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"] | ||||
success_txs += [tx['tx'] | for tx in bip112txs_vary_nSequence_v2 | ||||
for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and not tx['stf']] | if not tx["sdf"] and not tx["stf"] | ||||
] | |||||
success_txs += [ | |||||
tx["tx"] | |||||
for tx in bip112txs_vary_OP_CSV_v2 | |||||
if not tx["sdf"] and not tx["stf"] | |||||
] | |||||
# Test #121 | # Test #121 | ||||
self.send_blocks([self.create_test_block(success_txs)]) | self.send_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(f"0x{block}", 0) | self.tip = int(f"0x{block}", 0) | ||||
Show All 9 Lines | def run_test(self): | ||||
spend_txs.append(raw_tx) | spend_txs.append(raw_tx) | ||||
# Test #123 | # Test #123 | ||||
self.send_blocks([self.create_test_block(spend_txs)]) | self.send_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 | # Additional test, of checking that comparison of two time types works | ||||
# properly | # properly | ||||
time_txs = [] | time_txs = [] | ||||
for tx in [tx['tx'] | for tx in [ | ||||
for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]: | 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 | ||||
self.send_blocks([self.create_test_block(time_txs)]) | self.send_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). | ||||
Show All 13 Lines | def run_test(self): | ||||
spend_txs.append(raw_tx) | spend_txs.append(raw_tx) | ||||
# Test #126 | # Test #126 | ||||
self.send_blocks([self.create_test_block(spend_txs)]) | self.send_blocks([self.create_test_block(spend_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# TODO: Test empty stack fails | # TODO: Test empty stack fails | ||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
BIP68_112_113Test().main() | BIP68_112_113Test().main() |