aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/bipdersig-p2p.py
diff options
context:
space:
mode:
Diffstat (limited to 'qa/rpc-tests/bipdersig-p2p.py')
-rwxr-xr-xqa/rpc-tests/bipdersig-p2p.py67
1 files changed, 33 insertions, 34 deletions
diff --git a/qa/rpc-tests/bipdersig-p2p.py b/qa/rpc-tests/bipdersig-p2p.py
index ec1678cc2c..3bad5af5e6 100755
--- a/qa/rpc-tests/bipdersig-p2p.py
+++ b/qa/rpc-tests/bipdersig-p2p.py
@@ -1,8 +1,7 @@
-#!/usr/bin/env python2
-#
-# Distributed under the MIT/X11 software license, see the accompanying
+#!/usr/bin/env python3
+# Copyright (c) 2015-2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#
from test_framework.test_framework import ComparisonTestFramework
from test_framework.util import *
@@ -10,8 +9,7 @@ from test_framework.mininode import CTransaction, NetworkThread
from test_framework.blocktools import create_coinbase, create_block
from test_framework.comptool import TestInstance, TestManager
from test_framework.script import CScript
-from binascii import hexlify, unhexlify
-import cStringIO
+from io import BytesIO
import time
# A canonical signature consists of:
@@ -25,7 +23,7 @@ def unDERify(tx):
newscript = []
for i in scriptSig:
if (len(newscript) == 0):
- newscript.append(i[0:-1] + '\0' + i[-1])
+ newscript.append(i[0:-1] + b'\0' + i[-1:])
else:
newscript.append(i)
tx.vin[0].scriptSig = CScript(newscript)
@@ -47,11 +45,12 @@ Mine 1 old version block, see that the node rejects.
class BIP66Test(ComparisonTestFramework):
def __init__(self):
+ super().__init__()
self.num_nodes = 1
def setup_network(self):
# Must set the blockversion for this test
- self.nodes = start_nodes(1, self.options.tmpdir,
+ self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[['-debug', '-whitelist=127.0.0.1', '-blockversion=2']],
binary=[self.options.testbinary])
@@ -68,7 +67,7 @@ class BIP66Test(ComparisonTestFramework):
rawtx = node.createrawtransaction(inputs, outputs)
signresult = node.signrawtransaction(rawtx)
tx = CTransaction()
- f = cStringIO.StringIO(unhexlify(signresult['hex']))
+ f = BytesIO(hex_str_to_bytes(signresult['hex']))
tx.deserialize(f)
return tx
@@ -76,13 +75,13 @@ class BIP66Test(ComparisonTestFramework):
self.coinbase_blocks = self.nodes[0].generate(2)
height = 3 # height of the next block to build
- self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
+ self.tip = int("0x" + self.nodes[0].getbestblockhash(), 0)
self.nodeaddress = self.nodes[0].getnewaddress()
- self.last_block_time = time.time()
+ self.last_block_time = int(time.time())
- ''' 98 more version 2 blocks '''
+ ''' 298 more version 2 blocks '''
test_blocks = []
- for i in xrange(98):
+ for i in range(298):
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 2
block.rehash()
@@ -95,7 +94,7 @@ class BIP66Test(ComparisonTestFramework):
''' Mine 749 version 3 blocks '''
test_blocks = []
- for i in xrange(749):
+ for i in range(749):
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 3
block.rehash()
@@ -125,29 +124,11 @@ class BIP66Test(ComparisonTestFramework):
self.last_block_time += 1
self.tip = block.sha256
height += 1
- yield TestInstance([[block, True]])
-
- '''
- Check that the new DERSIG rules are enforced in the 751st version 3
- block.
- '''
- spendtx = self.create_transaction(self.nodes[0],
- self.coinbase_blocks[1], self.nodeaddress, 1.0)
- unDERify(spendtx)
- spendtx.rehash()
-
- block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
- block.nVersion = 3
- block.vtx.append(spendtx)
- block.hashMerkleRoot = block.calc_merkle_root()
- block.rehash()
- block.solve()
- self.last_block_time += 1
- yield TestInstance([[block, False]])
+ yield TestInstance([[block, True]])
''' Mine 199 new version blocks on last valid tip '''
test_blocks = []
- for i in xrange(199):
+ for i in range(199):
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 3
block.rehash()
@@ -178,6 +159,24 @@ class BIP66Test(ComparisonTestFramework):
height += 1
yield TestInstance([[block, True]])
+ '''
+ Check that the new DERSIG rules are enforced in the 951st version 3
+ block.
+ '''
+ spendtx = self.create_transaction(self.nodes[0],
+ self.coinbase_blocks[1], self.nodeaddress, 1.0)
+ unDERify(spendtx)
+ spendtx.rehash()
+
+ block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
+ block.nVersion = 3
+ block.vtx.append(spendtx)
+ block.hashMerkleRoot = block.calc_merkle_root()
+ block.rehash()
+ block.solve()
+ self.last_block_time += 1
+ yield TestInstance([[block, False]])
+
''' Mine 1 old version block, should be invalid '''
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 2