13 from io
import BytesIO
20 Make the signature in vin 0 of a tx non-DER-compliant, 21 by adding padding after the S-value. 23 scriptSig =
CScript(tx.vin[0].scriptSig)
26 if (len(newscript) == 0):
27 newscript.append(i[0:-1] + b
'\0' + i[-1:])
30 tx.vin[0].scriptSig =
CScript(newscript)
33 This test is meant to exercise BIP66 (DER SIG). 34 Connect to a single node. 35 Mine 2 (version 2) blocks (save the coinbases for later). 36 Generate 98 more version 2 blocks, verify the node accepts. 37 Mine 749 version 3 blocks, verify the node accepts. 38 Check that the new DERSIG rules are not enforced on the 750th version 3 block. 39 Check that the new DERSIG rules are enforced on the 751st version 3 block. 40 Mine 199 new version blocks. 41 Mine 1 old-version block. 42 Mine 1 new version block. 43 Mine 1 old version block, see that the node rejects. 54 extra_args=[[
'-debug',
'-whitelist=127.0.0.1',
'-blockversion=2']],
55 binary=[self.options.testbinary])
59 test.add_all_connections(self.
nodes)
64 from_txid = node.getblock(coinbase)[
'tx'][0]
65 inputs = [{
"txid" : from_txid,
"vout" : 0}]
66 outputs = { to_address : amount }
67 rawtx = node.createrawtransaction(inputs, outputs)
68 signresult = node.signrawtransaction(rawtx)
82 ''' 98 more version 2 blocks ''' 89 test_blocks.append([block,
True])
91 self.
tip = block.sha256
95 ''' Mine 749 version 3 blocks ''' 102 test_blocks.append([block,
True])
104 self.
tip = block.sha256
109 Check that the new DERSIG rules are not enforced in the 750th 119 block.vtx.append(spendtx)
120 block.hashMerkleRoot = block.calc_merkle_root()
125 self.
tip = block.sha256
130 Check that the new DERSIG rules are enforced in the 751st version 3 140 block.vtx.append(spendtx)
141 block.hashMerkleRoot = block.calc_merkle_root()
147 ''' Mine 199 new version blocks on last valid tip ''' 149 for i
in xrange(199):
154 test_blocks.append([block,
True])
156 self.
tip = block.sha256
160 ''' Mine 1 old version block ''' 166 self.
tip = block.sha256
170 ''' Mine 1 new version block ''' 176 self.
tip = block.sha256
180 ''' Mine 1 old version block, should be invalid ''' 188 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)
def create_transaction(self, node, coinbase, to_address, amount)
UniValue generate(const UniValue ¶ms, bool fHelp)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)