mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-13 16:48:08 +00:00
Minor fixes of functional test cases.
This commit is contained in:
parent
0b30d4911c
commit
cb9d3dbec7
@ -9,6 +9,7 @@
|
|||||||
- submitblock"""
|
- submitblock"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import struct
|
||||||
from binascii import b2a_hex
|
from binascii import b2a_hex
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
@ -17,6 +18,13 @@ from test_framework.mininode import CBlock
|
|||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal, assert_raises_rpc_error
|
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):
|
def b2x(b):
|
||||||
return b2a_hex(b).decode('ascii')
|
return b2a_hex(b).decode('ascii')
|
||||||
|
|
||||||
@ -40,7 +48,7 @@ class MiningTest(BitcoinTestFramework):
|
|||||||
assert_equal(mining_info['chain'], 'regtest')
|
assert_equal(mining_info['chain'], 'regtest')
|
||||||
assert_equal(mining_info['currentblocktx'], 0)
|
assert_equal(mining_info['currentblocktx'], 0)
|
||||||
assert_equal(mining_info['currentblockweight'], 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['networkhashps'], Decimal('0.003333333333333334'))
|
||||||
assert_equal(mining_info['pooledtx'], 0)
|
assert_equal(mining_info['pooledtx'], 0)
|
||||||
|
|
||||||
@ -64,6 +72,10 @@ class MiningTest(BitcoinTestFramework):
|
|||||||
block.nNonce = 0
|
block.nNonce = 0
|
||||||
block.vtx = [coinbase_tx]
|
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")
|
self.log.info("getblocktemplate: Test valid block")
|
||||||
assert_template(node, block, None)
|
assert_template(node, block, None)
|
||||||
|
|
||||||
@ -103,7 +115,7 @@ class MiningTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
self.log.info("getblocktemplate: Test bad tx count")
|
self.log.info("getblocktemplate: Test bad tx count")
|
||||||
# The tx count is immediately after the block header
|
# 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())
|
bad_block_sn = bytearray(block.serialize())
|
||||||
assert_equal(bad_block_sn[TX_COUNT_OFFSET], 1)
|
assert_equal(bad_block_sn[TX_COUNT_OFFSET], 1)
|
||||||
bad_block_sn[TX_COUNT_OFFSET] += 1
|
bad_block_sn[TX_COUNT_OFFSET] += 1
|
||||||
|
@ -202,7 +202,7 @@ class BlockchainTest(BitcoinTestFramework):
|
|||||||
# 1 hash in 2 should be valid, so difficulty should be 1/2**31
|
# 1 hash in 2 should be valid, so difficulty should be 1/2**31
|
||||||
# binary => decimal => binary math is why we do this check
|
# binary => decimal => binary math is why we do this check
|
||||||
# assert abs(difficulty * 2**31 - 1) < 0.0001
|
# 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):
|
def _test_getnetworkhashps(self):
|
||||||
hashes_per_second = self.nodes[0].getnetworkhashps()
|
hashes_per_second = self.nodes[0].getnetworkhashps()
|
||||||
|
@ -633,8 +633,9 @@ class CBlockHeader():
|
|||||||
c += ser_uint256(self.merkle_root)
|
c += ser_uint256(self.merkle_root)
|
||||||
c += struct.pack("<B", self.nTxes)
|
c += struct.pack("<B", self.nTxes)
|
||||||
# self.sha256 stores the cn_fast hash.
|
# self.sha256 stores the cn_fast hash.
|
||||||
self.sha256 = uint256_from_str(pycryptonight.cn_fast_hash(c))
|
cn_hash = pycryptonight.cn_fast_hash(c)
|
||||||
self.hash = encode(pycryptonight.cn_fast_hash(c)[::-1], 'hex_codec').decode('ascii')
|
self.sha256 = uint256_from_str(cn_hash)
|
||||||
|
self.hash = encode(cn_hash[::-1], 'hex_codec').decode('ascii')
|
||||||
# nNonce is used to store block height.
|
# nNonce is used to store block height.
|
||||||
self.scrypt256 = uint256_from_str(pycryptonight.cn_slow_hash(c, self.major_version - 6, 0, self.nNonce))
|
self.scrypt256 = uint256_from_str(pycryptonight.cn_slow_hash(c, self.major_version - 6, 0, self.nNonce))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user