13 from io
import BytesIO
17 '''Modify the signature in vin 0 of the tx to fail CLTV 19 Prepends -1 CLTV DROP in the scriptSig itself. 21 tx.vin[0].scriptSig =
CScript([OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP] +
22 list(
CScript(tx.vin[0].scriptSig)))
25 This test is meant to exercise BIP65 (CHECKLOCKTIMEVERIFY) 26 Connect to a single node. 27 Mine 2 (version 3) blocks (save the coinbases for later). 28 Generate 98 more version 3 blocks, verify the node accepts. 29 Mine 749 version 4 blocks, verify the node accepts. 30 Check that the new CLTV rules are not enforced on the 750th version 4 block. 31 Check that the new CLTV rules are enforced on the 751st version 4 block. 32 Mine 199 new version blocks. 33 Mine 1 old-version block. 34 Mine 1 new version block. 35 Mine 1 old version block, see that the node rejects. 46 extra_args=[[
'-debug',
'-whitelist=127.0.0.1',
'-blockversion=3']],
47 binary=[self.options.testbinary])
51 test.add_all_connections(self.
nodes)
56 from_txid = node.getblock(coinbase)[
'tx'][0]
57 inputs = [{
"txid" : from_txid,
"vout" : 0}]
58 outputs = { to_address : amount }
59 rawtx = node.createrawtransaction(inputs, outputs)
60 signresult = node.signrawtransaction(rawtx)
74 ''' 98 more version 3 blocks ''' 81 test_blocks.append([block,
True])
83 self.
tip = block.sha256
87 ''' Mine 749 version 4 blocks ''' 94 test_blocks.append([block,
True])
96 self.
tip = block.sha256
101 Check that the new CLTV rules are not enforced in the 750th 111 block.vtx.append(spendtx)
112 block.hashMerkleRoot = block.calc_merkle_root()
117 self.
tip = block.sha256
122 Check that the new CLTV rules are enforced in the 751st version 4 132 block.vtx.append(spendtx)
133 block.hashMerkleRoot = block.calc_merkle_root()
139 ''' Mine 199 new version blocks on last valid tip ''' 141 for i
in xrange(199):
146 test_blocks.append([block,
True])
148 self.
tip = block.sha256
152 ''' Mine 1 old version block ''' 158 self.
tip = block.sha256
162 ''' Mine 1 new version block ''' 168 self.
tip = block.sha256
172 ''' Mine 1 old version block, should be invalid ''' 180 if __name__ ==
'__main__':
def hex_str_to_bytes(hex_str)
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None)
UniValue getnewaddress(const UniValue ¶ms, bool fHelp)
UniValue generate(const UniValue ¶ms, bool fHelp)
def create_transaction(self, node, coinbase, to_address, amount)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)