Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_csv_activation.py
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | 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 | ||||
class BIP68_112_113Test(ComparisonTestFramework): | def create_transaction(node, txid, to_address, amount): | ||||
def set_test_params(self): | |||||
self.num_nodes = 1 | |||||
self.setup_clean_chain = True | |||||
self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']] | |||||
def run_test(self): | |||||
test = TestManager(self, self.options.tmpdir) | |||||
test.add_all_connections(self.nodes) | |||||
network_thread_start() | |||||
test.run() | |||||
def send_generic_input_tx(self, node, coinbases): | |||||
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)))) | |||||
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 = FromHex(CTransaction(), rawtx) | tx = FromHex(CTransaction(), rawtx) | ||||
return tx | return tx | ||||
def sign_transaction(self, 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(self, node, prev_tx): | |||||
spendtx = self.create_transaction( | def spend_tx(node, prev_tx, address): | ||||
node, prev_tx.hash, self.nodeaddress, (prev_tx.vout[0].nValue - 1000) / COIN) | spendtx = create_transaction( | ||||
node, prev_tx.hash, address, (prev_tx.vout[0].nValue - 1000) / COIN) | |||||
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 generate_blocks(self, number): | |||||
test_blocks = [] | |||||
for i in range(number): | |||||
block = self.create_test_block([]) | |||||
test_blocks.append([block, True]) | |||||
self.last_block_time += 600 | |||||
self.tip = block.sha256 | |||||
self.tipheight += 1 | |||||
return test_blocks | |||||
def create_test_block(self, txs, version=536870912): | def create_bip112special(node, input, txversion, address): | ||||
block = create_block(self.tip, create_coinbase( | tx = create_transaction( | ||||
self.tipheight + 1), self.last_block_time + 600) | node, input, address, Decimal("49.98")) | ||||
block.nVersion = version | tx.nVersion = txversion | ||||
block.vtx.extend(txs) | tx.vout[0].scriptPubKey = CScript( | ||||
make_conform_to_ctor(block) | [-1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | ||||
block.hashMerkleRoot = block.calc_merkle_root() | tx.rehash() | ||||
block.rehash() | signtx = sign_transaction(node, tx) | ||||
block.solve() | signtx.rehash() | ||||
return block | |||||
# Create a block with given txs, and spend these txs in the same block. | return signtx | ||||
# 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 send_generic_input_tx(node, coinbases, address): | ||||
def create_test_block_spend_utxos(self, node, txs, version=536870912): | amount = Decimal("49.99") | ||||
block = self.create_test_block(txs, version) | return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction(node, node.getblock(coinbases.pop())['tx'][0], address, amount)))) | ||||
block.vtx.extend([self.spend_tx(node, tx) for tx in txs]) | |||||
make_conform_to_ctor(block) | |||||
block.hashMerkleRoot = block.calc_merkle_root() | |||||
block.rehash() | |||||
block.solve() | |||||
return block | |||||
def create_bip68txs(self, bip68inputs, txversion, 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 = self.create_transaction( | tx = create_transaction( | ||||
self.nodes[0], bip68inputs[i], self.nodeaddress, 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 = self.sign_transaction(self.nodes[0], 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_bip112special(self, input, txversion): | |||||
tx = self.create_transaction( | |||||
self.nodes[0], input, self.nodeaddress, Decimal("49.98")) | |||||
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.rehash() | |||||
return signtx | |||||
def create_bip112txs(self, bip112inputs, varyOP_CSV, txversion, 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 = self.create_transaction( | tx = create_transaction( | ||||
self.nodes[0], bip112inputs[i], self.nodeaddress, 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 | ||||
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 = self.sign_transaction(self.nodes[0], tx) | signtx = sign_transaction(node, tx) | ||||
signtx.rehash() | signtx.rehash() | ||||
txs.append({'tx': signtx, 'sdf': sdf, 'stf': stf}) | txs.append({'tx': signtx, 'sdf': sdf, 'stf': stf}) | ||||
return txs | return txs | ||||
class BIP68_112_113Test(ComparisonTestFramework): | |||||
def set_test_params(self): | |||||
self.num_nodes = 1 | |||||
self.setup_clean_chain = True | |||||
self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']] | |||||
def run_test(self): | |||||
test = TestManager(self, self.options.tmpdir) | |||||
test.add_all_connections(self.nodes) | |||||
network_thread_start() | |||||
test.run() | |||||
def generate_blocks(self, number): | |||||
test_blocks = [] | |||||
for i in range(number): | |||||
block = self.create_test_block([]) | |||||
test_blocks.append([block, True]) | |||||
self.last_block_time += 600 | |||||
self.tip = block.sha256 | |||||
self.tipheight += 1 | |||||
return test_blocks | |||||
def create_test_block(self, txs, version=536870912): | |||||
block = create_block(self.tip, create_coinbase( | |||||
self.tipheight + 1), self.last_block_time + 600) | |||||
block.nVersion = version | |||||
block.vtx.extend(txs) | |||||
make_conform_to_ctor(block) | |||||
block.hashMerkleRoot = block.calc_merkle_root() | |||||
block.rehash() | |||||
block.solve() | |||||
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([spend_tx(node, tx, self.nodeaddress) for tx in txs]) | |||||
make_conform_to_ctor(block) | |||||
block.hashMerkleRoot = block.calc_merkle_root() | |||||
block.rehash() | |||||
block.solve() | |||||
return block | |||||
def get_tests(self): | def get_tests(self): | ||||
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 | ||||
Show All 19 Lines | def get_tests(self): | ||||
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 | ||||
bip68inputs = [] | bip68inputs = [] | ||||
for i in range(16): | for i in range(16): | ||||
bip68inputs.append(self.send_generic_input_tx( | bip68inputs.append(send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks)) | 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(self.send_generic_input_tx( | inputs.append(send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks)) | 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(self.send_generic_input_tx( | inputs.append(send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks)) | 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 = self.send_generic_input_tx( | bip112specialinput = send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks) | self.nodes[0], self.coinbase_blocks, self.nodeaddress) | ||||
# 1 normal input | # 1 normal input | ||||
bip113input = self.send_generic_input_tx( | bip113input = send_generic_input_tx( | ||||
self.nodes[0], self.coinbase_blocks) | 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.nodes[0].generate(1)[0] | inputblockhash = self.nodes[0].generate(1)[0] | ||||
self.nodes[0].setmocktime(0) | self.nodes[0].setmocktime(0) | ||||
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) | ||||
# Test #2 | # Test #2 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | yield TestInstance(test_blocks, sync_every_block=False) | ||||
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 = self.create_transaction( | bip113tx_v1 = create_transaction( | ||||
self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98")) | self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98")) | ||||
bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | ||||
bip113tx_v1.nVersion = 1 | bip113tx_v1.nVersion = 1 | ||||
bip113tx_v2 = self.create_transaction( | bip113tx_v2 = create_transaction( | ||||
self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98")) | self.nodes[0], bip113input, self.nodeaddress, Decimal("49.98")) | ||||
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 = self.create_bip68txs(bip68inputs, 1) | bip68txs_v1 = create_bip68txs( | ||||
bip68txs_v2 = self.create_bip68txs(bip68inputs, 2) | self.nodes[0], bip68inputs, 1, 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 = self.create_bip112txs( | bip112txs_vary_nSequence_v1 = create_bip112txs( | ||||
bip112basicinputs[0], False, 1) | self.nodes[0], bip112basicinputs[0], False, 1, self.nodeaddress) | ||||
bip112txs_vary_nSequence_v2 = self.create_bip112txs( | bip112txs_vary_nSequence_v2 = create_bip112txs( | ||||
bip112basicinputs[0], False, 2) | 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 = self.create_bip112txs( | bip112txs_vary_nSequence_9_v1 = create_bip112txs( | ||||
bip112basicinputs[1], False, 1, -1) | self.nodes[0], bip112basicinputs[1], False, 1, self.nodeaddress, -1) | ||||
bip112txs_vary_nSequence_9_v2 = self.create_bip112txs( | bip112txs_vary_nSequence_9_v2 = create_bip112txs( | ||||
bip112basicinputs[1], False, 2, -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 = self.create_bip112txs( | bip112txs_vary_OP_CSV_v1 = create_bip112txs( | ||||
bip112diverseinputs[0], True, 1) | self.nodes[0], bip112diverseinputs[0], True, 1, self.nodeaddress) | ||||
bip112txs_vary_OP_CSV_v2 = self.create_bip112txs( | bip112txs_vary_OP_CSV_v2 = create_bip112txs( | ||||
bip112diverseinputs[0], True, 2) | 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 = self.create_bip112txs( | bip112txs_vary_OP_CSV_9_v1 = create_bip112txs( | ||||
bip112diverseinputs[1], True, 1, -1) | self.nodes[0], bip112diverseinputs[1], True, 1, self.nodeaddress, -1) | ||||
bip112txs_vary_OP_CSV_9_v2 = self.create_bip112txs( | bip112txs_vary_OP_CSV_9_v2 = create_bip112txs( | ||||
bip112diverseinputs[1], True, 2, -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 = self.create_bip112special(bip112specialinput, 1) | bip112tx_special_v1 = create_bip112special( | ||||
bip112tx_special_v2 = self.create_bip112special(bip112specialinput, 2) | self.nodes[0], bip112specialinput, 1, self.nodeaddress) | ||||
bip112tx_special_v2 = create_bip112special( | |||||
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 = self.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(self.spend_tx(self.nodes[0], bip112tx_special_v1)) | success_txs.append( | ||||
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([self.spend_tx(self.nodes[0], tx) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_v1)]) | 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) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_v1)]) | 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) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v1)]) | for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v1)]) | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)) | ||||
success_txs.extend([self.spend_tx(self.nodes[0], tx) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)]) | for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)]) | ||||
# Test #3 | # Test #3 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | 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()) | ||||
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 = self.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(self.spend_tx(self.nodes[0], bip112tx_special_v2)) | success_txs.append( | ||||
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([self.spend_tx(self.nodes[0], tx) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_v2)]) | 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) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_v2)]) | 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) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v2)]) | for tx in all_rlt_txs(bip112txs_vary_nSequence_9_v2)]) | ||||
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)) | success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)) | ||||
success_txs.extend([self.spend_tx(self.nodes[0], tx) | success_txs.extend([spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)]) | for tx in all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)]) | ||||
# Test #4 | # Test #4 | ||||
yield TestInstance([[self.create_test_block(success_txs), True]]) | 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 | ||||
yield TestInstance(test_blocks, sync_every_block=False) | 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()) | ||||
self.log.info("Post-Soft Fork Tests.") | self.log.info("Post-Soft Fork Tests.") | ||||
self.log.info("BIP 113 tests") | self.log.info("BIP 113 tests") | ||||
# BIP 113 tests should now fail regardless of version number | # BIP 113 tests should now fail regardless of version number | ||||
# if nLockTime isn't satisfied by new rules | # if nLockTime isn't satisfied by new rules | ||||
# = MTP of prior block (not <) but < time put on current block | # = MTP of prior block (not <) but < time put on current block | ||||
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 | bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 | ||||
bip113signed1 = self.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 = self.sign_transaction(self.nodes[0], bip113tx_v2) | bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) | ||||
for bip113tx in [bip113signed1, bip113signed2]: | for bip113tx in [bip113signed1, bip113signed2]: | ||||
# Test #6, Test #7 | # Test #6, Test #7 | ||||
yield TestInstance([[self.create_test_block([bip113tx]), False]]) | 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 = 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 = sign_transaction(self.nodes[0], bip113tx_v2) | ||||
for bip113tx in [bip113signed1, bip113signed2]: | for bip113tx in [bip113signed1, bip113signed2]: | ||||
# Test #8, Test #9 | # Test #8, Test #9 | ||||
yield TestInstance([[self.create_test_block([bip113tx]), True]]) | 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) | ||||
# Test #10 | # Test #10 | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | def get_tests(self): | ||||
self.last_block_time += 600 | self.last_block_time += 600 | ||||
self.tip = int("0x" + block, 0) | self.tip = int("0x" + block, 0) | ||||
self.tipheight += 1 | self.tipheight += 1 | ||||
# Test #122 | # Test #122 | ||||
yield TestInstance(self.generate_blocks(9), sync_every_block=False) | yield TestInstance(self.generate_blocks(9), sync_every_block=False) | ||||
spend_txs = [] | spend_txs = [] | ||||
for tx in success_txs: | for tx in success_txs: | ||||
raw_tx = self.spend_tx(self.nodes[0], tx) | raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | ||||
raw_tx.rehash() | raw_tx.rehash() | ||||
spend_txs.append(raw_tx) | spend_txs.append(raw_tx) | ||||
# Test #123 | # Test #123 | ||||
yield TestInstance([[self.create_test_block(spend_txs), True]]) | 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 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 = self.sign_transaction(self.nodes[0], tx) | signtx = sign_transaction(self.nodes[0], tx) | ||||
time_txs.append(signtx) | time_txs.append(signtx) | ||||
# Test #124 | # Test #124 | ||||
yield TestInstance([[self.create_test_block(time_txs), True]]) | yield TestInstance([[self.create_test_block(time_txs), True]]) | ||||
# Spending the previous block utxos requires a block time difference of | # Spending the previous block utxos requires a block time difference of | ||||
# at least 10 * 512s (nSequence = 10). | # at least 10 * 512s (nSequence = 10). | ||||
# Generate 8 blocks then spend in the 9th (9 * 600 > 10 * 512) | # Generate 8 blocks then spend in the 9th (9 * 600 > 10 * 512) | ||||
block = self.nodes[0].getbestblockhash() | block = self.nodes[0].getbestblockhash() | ||||
self.last_block_time += 600 | self.last_block_time += 600 | ||||
self.tip = int("0x" + block, 0) | self.tip = int("0x" + block, 0) | ||||
self.tipheight += 1 | self.tipheight += 1 | ||||
# Test #125 | # Test #125 | ||||
yield TestInstance(self.generate_blocks(8), sync_every_block=False) | yield TestInstance(self.generate_blocks(8), sync_every_block=False) | ||||
spend_txs = [] | spend_txs = [] | ||||
for tx in time_txs: | for tx in time_txs: | ||||
raw_tx = self.spend_tx(self.nodes[0], tx) | raw_tx = spend_tx(self.nodes[0], tx, self.nodeaddress) | ||||
raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG | raw_tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG | ||||
raw_tx.rehash() | raw_tx.rehash() | ||||
spend_txs.append(raw_tx) | spend_txs.append(raw_tx) | ||||
# Test #126 | # Test #126 | ||||
yield TestInstance([[self.create_test_block(spend_txs), True]]) | 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() |