Browse Source

Minor fixes of functional test cases.

cn_mining
Jianping Wu 5 years ago
parent
commit
cb9d3dbec7
  1. 16
      test/functional/mining_basic.py
  2. 2
      test/functional/rpc_blockchain.py
  3. 5
      test/functional/test_framework/messages.py

16
test/functional/mining_basic.py

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
- submitblock"""
import copy
import struct
from binascii import b2a_hex
from decimal import Decimal
@ -17,6 +18,13 @@ from test_framework.mininode import CBlock @@ -17,6 +18,13 @@ from test_framework.mininode import CBlock
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error
def uint256_from_str(s):
r = 0
t = struct.unpack("<IIIIIIII", s[:32])
for i in range(8):
r += t[i] << (i * 32)
return r
def b2x(b):
return b2a_hex(b).decode('ascii')
@ -40,7 +48,7 @@ class MiningTest(BitcoinTestFramework): @@ -40,7 +48,7 @@ class MiningTest(BitcoinTestFramework):
assert_equal(mining_info['chain'], 'regtest')
assert_equal(mining_info['currentblocktx'], 0)
assert_equal(mining_info['currentblockweight'], 0)
assert_equal(mining_info['difficulty'], Decimal('0.0004882738576261828'))
assert_equal(mining_info['difficulty'], Decimal('1.999969720836845'))
assert_equal(mining_info['networkhashps'], Decimal('0.003333333333333334'))
assert_equal(mining_info['pooledtx'], 0)
@ -64,6 +72,10 @@ class MiningTest(BitcoinTestFramework): @@ -64,6 +72,10 @@ class MiningTest(BitcoinTestFramework):
block.nNonce = 0
block.vtx = [coinbase_tx]
block.major_version = 10
block.merkle_root = uint256_from_str(bytes.fromhex("3cf6c3b6da3f4058853ee70369ee43d473aca91ae8fc8f44a645beb21c392d80"))
block.calc_sha256()
self.log.info("getblocktemplate: Test valid block")
assert_template(node, block, None)
@ -103,7 +115,7 @@ class MiningTest(BitcoinTestFramework): @@ -103,7 +115,7 @@ class MiningTest(BitcoinTestFramework):
self.log.info("getblocktemplate: Test bad tx count")
# The tx count is immediately after the block header
TX_COUNT_OFFSET = 80
TX_COUNT_OFFSET = 80 + 78 # Kevacoin: 78 is the size of the cnHeader.
bad_block_sn = bytearray(block.serialize())
assert_equal(bad_block_sn[TX_COUNT_OFFSET], 1)
bad_block_sn[TX_COUNT_OFFSET] += 1

2
test/functional/rpc_blockchain.py

@ -202,7 +202,7 @@ class BlockchainTest(BitcoinTestFramework): @@ -202,7 +202,7 @@ class BlockchainTest(BitcoinTestFramework):
# 1 hash in 2 should be valid, so difficulty should be 1/2**31
# binary => decimal => binary math is why we do this check
# assert abs(difficulty * 2**31 - 1) < 0.0001
assert abs(difficulty) < 0.0005 # Kevacoin change
assert abs(difficulty) < 2.0 # Kevacoin change
def _test_getnetworkhashps(self):
hashes_per_second = self.nodes[0].getnetworkhashps()

5
test/functional/test_framework/messages.py

@ -633,8 +633,9 @@ class CBlockHeader(): @@ -633,8 +633,9 @@ class CBlockHeader():
c += ser_uint256(self.merkle_root)
c += struct.pack("<B", self.nTxes)
# self.sha256 stores the cn_fast hash.
self.sha256 = uint256_from_str(pycryptonight.cn_fast_hash(c))
self.hash = encode(pycryptonight.cn_fast_hash(c)[::-1], 'hex_codec').decode('ascii')
cn_hash = pycryptonight.cn_fast_hash(c)
self.sha256 = uint256_from_str(cn_hash)
self.hash = encode(cn_hash[::-1], 'hex_codec').decode('ascii')
# nNonce is used to store block height.
self.scrypt256 = uint256_from_str(pycryptonight.cn_slow_hash(c, self.major_version - 6, 0, self.nNonce))

Loading…
Cancel
Save