Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_cltv.py
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.coinbase_txids = [self.nodes[0].getblock( | self.coinbase_txids = [self.nodes[0].getblock( | ||||
b)['tx'][0] for b in self.nodes[0].generate(CLTV_HEIGHT - 2)] | b)['tx'][0] for b in self.nodes[0].generate(CLTV_HEIGHT - 2)] | ||||
self.nodeaddress = self.nodes[0].getnewaddress() | self.nodeaddress = self.nodes[0].getnewaddress() | ||||
self.log.info( | self.log.info( | ||||
"Test that an invalid-according-to-CLTV transaction can still appear in a block") | "Test that an invalid-according-to-CLTV transaction can still appear in a block") | ||||
fundtx = create_transaction(self.nodes[0], self.coinbase_txids[0], | fundtx = create_transaction(self.nodes[0], self.coinbase_txids[0], | ||||
self.nodeaddress, amount=49.99) | self.nodeaddress, amount=49990000) | ||||
fundtx, spendtx = cltv_lock_to_height( | fundtx, spendtx = cltv_lock_to_height( | ||||
self.nodes[0], fundtx, self.nodeaddress, 49.98) | self.nodes[0], fundtx, self.nodeaddress, 49980000) | ||||
tip = self.nodes[0].getbestblockhash() | tip = self.nodes[0].getbestblockhash() | ||||
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1 | block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1 | ||||
block = create_block(int(tip, 16), create_coinbase( | block = create_block(int(tip, 16), create_coinbase( | ||||
CLTV_HEIGHT - 1), block_time) | CLTV_HEIGHT - 1), block_time) | ||||
block.nVersion = 3 | block.nVersion = 3 | ||||
block.vtx.append(fundtx) | block.vtx.append(fundtx) | ||||
# include the -1 CLTV in block | # include the -1 CLTV in block | ||||
Show All 18 Lines | def run_test(self): | ||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip) | assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip) | ||||
self.nodes[0].p2p.sync_with_ping() | self.nodes[0].p2p.sync_with_ping() | ||||
self.log.info( | self.log.info( | ||||
"Test that invalid-according-to-cltv transactions cannot appear in a block") | "Test that invalid-according-to-cltv transactions cannot appear in a block") | ||||
block.nVersion = 4 | block.nVersion = 4 | ||||
fundtx = create_transaction(self.nodes[0], self.coinbase_txids[1], | fundtx = create_transaction(self.nodes[0], self.coinbase_txids[1], | ||||
self.nodeaddress, amount=49.99) | self.nodeaddress, amount=49990000) | ||||
fundtx, spendtx = cltv_lock_to_height( | fundtx, spendtx = cltv_lock_to_height( | ||||
self.nodes[0], fundtx, self.nodeaddress, 49.98) | self.nodes[0], fundtx, self.nodeaddress, 49980000) | ||||
# The funding tx only has unexecuted bad CLTV, in scriptpubkey; this is | # The funding tx only has unexecuted bad CLTV, in scriptpubkey; this is | ||||
# valid. | # valid. | ||||
self.nodes[0].p2p.send_and_ping(msg_tx(fundtx)) | self.nodes[0].p2p.send_and_ping(msg_tx(fundtx)) | ||||
assert fundtx.hash in self.nodes[0].getrawmempool() | assert fundtx.hash in self.nodes[0].getrawmempool() | ||||
# Mine a block containing the funding transaction | # Mine a block containing the funding transaction | ||||
block.vtx.append(fundtx) | block.vtx.append(fundtx) | ||||
Show All 31 Lines | def run_test(self): | ||||
with self.nodes[0].assert_debug_log(expected_msgs=['ConnectBlock {} failed, blk-bad-inputs'.format(block.hash)]): | with self.nodes[0].assert_debug_log(expected_msgs=['ConnectBlock {} failed, blk-bad-inputs'.format(block.hash)]): | ||||
self.nodes[0].p2p.send_and_ping(msg_block(block)) | self.nodes[0].p2p.send_and_ping(msg_block(block)) | ||||
assert_equal(self.nodes[0].getbestblockhash(), tip) | assert_equal(self.nodes[0].getbestblockhash(), tip) | ||||
self.nodes[0].p2p.sync_with_ping() | self.nodes[0].p2p.sync_with_ping() | ||||
self.log.info( | self.log.info( | ||||
"Test that a version 4 block with a valid-according-to-CLTV transaction is accepted") | "Test that a version 4 block with a valid-according-to-CLTV transaction is accepted") | ||||
fundtx = create_transaction(self.nodes[0], self.coinbase_txids[2], | fundtx = create_transaction(self.nodes[0], self.coinbase_txids[2], | ||||
self.nodeaddress, amount=49.99) | self.nodeaddress, amount=49990000) | ||||
fundtx, spendtx = cltv_lock_to_height( | fundtx, spendtx = cltv_lock_to_height( | ||||
self.nodes[0], fundtx, self.nodeaddress, 49.98, CLTV_HEIGHT) | self.nodes[0], fundtx, self.nodeaddress, 49980000, CLTV_HEIGHT) | ||||
# make sure sequence is nonfinal and locktime is good | # make sure sequence is nonfinal and locktime is good | ||||
spendtx.vin[0].nSequence = 0xfffffffe | spendtx.vin[0].nSequence = 0xfffffffe | ||||
spendtx.nLockTime = CLTV_HEIGHT | spendtx.nLockTime = CLTV_HEIGHT | ||||
# both transactions are fully valid | # both transactions are fully valid | ||||
self.nodes[0].sendrawtransaction(ToHex(fundtx)) | self.nodes[0].sendrawtransaction(ToHex(fundtx)) | ||||
self.nodes[0].sendrawtransaction(ToHex(spendtx)) | self.nodes[0].sendrawtransaction(ToHex(spendtx)) | ||||
Show All 16 Lines |