Skip to content

Commit

Permalink
initial fixing of compact blocks tests
Browse files Browse the repository at this point in the history
  • Loading branch information
backpacker69 committed Jun 4, 2019
1 parent 5592bf2 commit 7af4d6f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion test/functional/p2p_compactblocks.py
Expand Up @@ -11,6 +11,7 @@
from test_framework.mininode import *
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.key import CECKey
from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment
from test_framework.script import CScript, OP_TRUE, OP_DROP

Expand Down Expand Up @@ -98,16 +99,20 @@ def set_test_params(self):
# TODO: Rewrite this test to support SegWit being always active.
self.extra_args = [["-vbparams=segwit:0:0"], ["-vbparams=segwit:0:999999999999", "-txindex", "-deprecatedrpc=addwitnessaddress"]]
self.utxos = []
self.coinbase_key = CECKey()
self.coinbase_key.set_secretbytes(b"horsebattery")
self.coinbase_pubkey = self.coinbase_key.get_pubkey()

def build_block_on_tip(self, node, segwit=False):
height = node.getblockcount()
tip = node.getbestblockhash()
mtp = node.getblockheader(tip)['mediantime']
block = create_block(int(tip, 16), create_coinbase(height + 1), mtp + 1)
block = create_block(int(tip, 16), create_coinbase(height + 1, self.coinbase_pubkey, mtp), mtp + 1)
block.nVersion = 4
if segwit:
add_witness_commitment(block)
block.solve()
block.vchBlockSig = self.coinbase_key.sign(bytes.fromhex(block.hash)[::-1])
return block

# Create 10 more anyone-can-spend utxo's for testing.
Expand Down
4 changes: 3 additions & 1 deletion test/functional/test_framework/blocktools.py
Expand Up @@ -84,7 +84,7 @@ def serialize_script_num(value):
# Create a coinbase transaction, assuming no miner fees.
# If pubkey is passed in, the coinbase output will be a P2PK output;
# otherwise an anyone-can-spend output.
def create_coinbase(height, pubkey = None):
def create_coinbase(height, pubkey = None, timestamp = None):
coinbase = CTransaction()
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
ser_string(serialize_script_num(height)), 0xffffffff))
Expand All @@ -96,6 +96,8 @@ def create_coinbase(height, pubkey = None):
coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG])
else:
coinbaseoutput.scriptPubKey = CScript([OP_TRUE])
if (timestamp != None):
coinbase.nTime = timestamp
coinbase.vout = [ coinbaseoutput ]
coinbase.calc_sha256()
return coinbase
Expand Down
4 changes: 3 additions & 1 deletion test/functional/test_framework/messages.py
Expand Up @@ -34,7 +34,7 @@
MAX_INV_SZ = 50000
MAX_BLOCK_BASE_SIZE = 1000000

COIN = 100000000 # 1 btc in satoshis
COIN = 1000000 # 1 btc in satoshis

NODE_NETWORK = (1 << 0)
# NODE_GETUTXO = (1 << 1)
Expand Down Expand Up @@ -504,6 +504,7 @@ def __init__(self, header=None):
self.nNonce = header.nNonce
self.sha256 = header.sha256
self.hash = header.hash
self.nFlags = header.nFlags
self.calc_sha256()

def set_null(self):
Expand All @@ -513,6 +514,7 @@ def set_null(self):
self.nTime = 0
self.nBits = 0
self.nNonce = 0
self.nFlags = 0
self.sha256 = None
self.hash = None

Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/test_framework.py
Expand Up @@ -163,7 +163,7 @@ def main(self):
exit_code = TEST_EXIT_SKIPPED
else:
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir)
self.log.error("Hint: Call {} '{}' to consolidate all logs".format(os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../combine_logs.py"), self.options.tmpdir))
self.log.error("Hint: Call {} '{}' | less to consolidate and view all logs".format(os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../combine_logs.py"), self.options.tmpdir))
exit_code = TEST_EXIT_FAILED
logging.shutdown()
sys.exit(exit_code)
Expand Down

0 comments on commit 7af4d6f

Please sign in to comment.