Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_csv_activation.py
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | def create_bip112special(node, input, txversion, address): | ||||
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): | ||||
amount = Decimal("49.99") | amount = Decimal("49.99") | ||||
return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction(node, node.getblock(coinbases.pop())['tx'][0], address, amount)))) | return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction( | ||||
node, node.getblock(coinbases.pop())['tx'][0], address, amount)))) | |||||
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, Decimal("49.98")) | node, bip68inputs[i], address, Decimal("49.98")) | ||||
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, txversion, address, locktime_delta=0): | def create_bip112txs(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, Decimal("49.98")) | node, bip112inputs[i], address, Decimal("49.98")) | ||||
if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed | if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | class BIP68_112_113Test(BitcoinTestFramework): | ||||
def run_test(self): | def run_test(self): | ||||
self.nodes[0].add_p2p_connection(P2PDataStore()) | 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 long_past_time | # Enough so that the generated blocks will still all be before | ||||
# long_past_time | |||||
self.nodes[0].setmocktime(long_past_time - 100) | self.nodes[0].setmocktime(long_past_time - 100) | ||||
# 82 blocks generated for inputs | # 82 blocks generated for inputs | ||||
self.coinbase_blocks = self.nodes[0].generate(1 + 16 + 2 * 32 + 1) | self.coinbase_blocks = self.nodes[0].generate(1 + 16 + 2 * 32 + 1) | ||||
# Set time back to present so yielded blocks aren't in the future as | # Set time back to present so yielded blocks aren't in the future as | ||||
# we advance last_block_time | # we advance last_block_time | ||||
self.nodes[0].setmocktime(0) | self.nodes[0].setmocktime(0) | ||||
# height of the next block to build | # height of the next block to build | ||||
self.tipheight = 82 | self.tipheight = 82 | ||||
Show All 17 Lines | def run_test(self): | ||||
# Put inputs for all tests in the chain at height 572 (tip now = 571) (time increases by 600s per block) | # Put inputs for all tests in the chain at height 572 (tip now = 571) (time increases by 600s per block) | ||||
# Note we reuse inputs for v1 and v2 txs so must test these separately | # Note we reuse inputs for v1 and v2 txs so must test these separately | ||||
# 16 normal inputs | # 16 normal inputs | ||||
bip68inputs = [] | bip68inputs = [] | ||||
for i in range(16): | for i in range(16): | ||||
bip68inputs.append(send_generic_input_tx( | bip68inputs.append(send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress)) | self.nodes[0], self.coinbase_blocks, self.nodeaddress)) | ||||
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig) | # 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be | ||||
# prepended to spending scriptSig) | |||||
bip112basicinputs = [] | bip112basicinputs = [] | ||||
for j in range(2): | for j in range(2): | ||||
inputs = [] | inputs = [] | ||||
for i in range(16): | for i in range(16): | ||||
inputs.append(send_generic_input_tx( | inputs.append(send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress)) | 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 (actually will be prepended to spending scriptSig) | # 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP | ||||
# (actually will be prepended to spending scriptSig) | |||||
bip112diverseinputs = [] | bip112diverseinputs = [] | ||||
for j in range(2): | for j in range(2): | ||||
inputs = [] | inputs = [] | ||||
for i in range(16): | for i in range(16): | ||||
inputs.append(send_generic_input_tx( | inputs.append(send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks, self.nodeaddress)) | 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 spending scriptSig) | # 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to | ||||
# 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) | ||||
Show All 39 Lines | def run_test(self): | ||||
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 OP_DROP inputs | # sequence lock time of 10 against 16 (relative_lock_time) OP_CSV | ||||
# 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 OP_DROP inputs | # sequence lock time of 9 against 16 (relative_lock_time) OP_CSV | ||||
# 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( | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Test #17 - Test #20 | # Test #17 - Test #20 | ||||
self.sync_blocks([self.create_test_block([tx])], success=False) | self.sync_blocks([self.create_test_block([tx])], success=False) | ||||
# Advance one block to 581 | # Advance one block to 581 | ||||
test_blocks = self.generate_blocks(1) | test_blocks = self.generate_blocks(1) | ||||
# Test #21 | # Test #21 | ||||
self.sync_blocks(test_blocks,) | self.sync_blocks(test_blocks,) | ||||
# Height txs should fail and time txs should now pass 9 * 600 > 10 * 512 | # Height txs should fail and time txs should now pass 9 * 600 > 10 * | ||||
# 512 | |||||
bip68success_txs.extend(bip68timetxs) | bip68success_txs.extend(bip68timetxs) | ||||
# Test #22 | # Test #22 | ||||
self.sync_blocks([self.create_test_block(bip68success_txs)]) | self.sync_blocks([self.create_test_block(bip68success_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
for tx in bip68heighttxs: | for tx in bip68heighttxs: | ||||
# Test #23 - Test #26 | # Test #23 - Test #26 | ||||
self.sync_blocks([self.create_test_block([tx])], success=False) | self.sync_blocks([self.create_test_block([tx])], success=False) | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
success_txs += [tx['tx'] | success_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']] | for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']] | ||||
# Test #80 | # Test #80 | ||||
self.sync_blocks( | self.sync_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 remaining txs ## | # SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all | ||||
# remaining txs ## | |||||
# All txs with nSequence 9 should fail either due to earlier mismatch | # All txs with nSequence 9 should fail either due to earlier mismatch | ||||
# or failing the CSV check | # or failing the CSV check | ||||
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2) | fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2) | ||||
fail_txs += [tx['tx'] | fail_txs += [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']] | for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']] | ||||
for tx in fail_txs: | for tx in fail_txs: | ||||
# Test #81 - Test #104 | # Test #81 - Test #104 | ||||
Show All 40 Lines | def run_test(self): | ||||
raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | ||||
raw_tx.rehash() | raw_tx.rehash() | ||||
spend_txs.append(raw_tx) | spend_txs.append(raw_tx) | ||||
# Test #123 | # Test #123 | ||||
self.sync_blocks([self.create_test_block(spend_txs)]) | self.sync_blocks([self.create_test_block(spend_txs)]) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
# Additional test, of checking that comparison of two time types works properly | # Additional test, of checking that comparison of two time types works | ||||
# properly | |||||
time_txs = [] | time_txs = [] | ||||
for tx in [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]: | for tx in [tx['tx'] | ||||
for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]: | |||||
signtx = sign_transaction(self.nodes[0], tx) | signtx = sign_transaction(self.nodes[0], tx) | ||||
time_txs.append(signtx) | time_txs.append(signtx) | ||||
# Test #124 | # Test #124 | ||||
self.sync_blocks([self.create_test_block(time_txs)]) | self.sync_blocks([self.create_test_block(time_txs)]) | ||||
# Spending the previous block utxos requires a block time difference of | # Spending the previous block utxos requires a block time difference of | ||||
# at least 10 * 512s (nSequence = 10). | # at least 10 * 512s (nSequence = 10). | ||||
Show All 23 Lines |