mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
more fixes
This commit is contained in:
parent
89aeade373
commit
d35e6153df
3 changed files with 16 additions and 27 deletions
|
|
@ -1258,16 +1258,22 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
|
|||
obj.pushKV("blocks", (int)chainActive.Height());
|
||||
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
|
||||
obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex());
|
||||
obj.pushKV("difficulty", (double)GetDifficulty(chainActive.Tip()));
|
||||
if (!g_signed_blocks) {
|
||||
obj.pushKV("difficulty", (double)GetDifficulty(chainActive.Tip()));
|
||||
}
|
||||
obj.pushKV("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast());
|
||||
obj.pushKV("verificationprogress", GuessVerificationProgress(chainparams.TxData(), chainActive.Tip()));
|
||||
obj.pushKV("initialblockdownload", IsInitialBlockDownload());
|
||||
obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex());
|
||||
if (!g_signed_blocks) {
|
||||
obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex());
|
||||
}
|
||||
obj.pushKV("size_on_disk", CalculateCurrentUsage());
|
||||
obj.pushKV("pruned", fPruneMode);
|
||||
CScript sign_block_script = chainparams.GetConsensus().signblockscript;
|
||||
obj.pushKV("signblock_asm", ScriptToAsmStr(sign_block_script));
|
||||
obj.pushKV("signblock_hex", HexStr(sign_block_script));
|
||||
if (g_signed_blocks) {
|
||||
CScript sign_block_script = chainparams.GetConsensus().signblockscript;
|
||||
obj.pushKV("signblock_asm", ScriptToAsmStr(sign_block_script));
|
||||
obj.pushKV("signblock_hex", HexStr(sign_block_script));
|
||||
}
|
||||
|
||||
if (fPruneMode) {
|
||||
CBlockIndex* block = chainActive.Tip();
|
||||
|
|
|
|||
|
|
@ -7,17 +7,14 @@
|
|||
Test the following RPCs:
|
||||
- getblockchaininfo
|
||||
- gettxoutsetinfo
|
||||
- getdifficulty
|
||||
- getbestblockhash
|
||||
- getblockhash
|
||||
- getblockheader
|
||||
- getchaintxstats
|
||||
- getnetworkhashps
|
||||
- verifychain
|
||||
|
||||
Tests correspond to code in rpc/blockchain.cpp.
|
||||
"""
|
||||
|
||||
from decimal import Decimal
|
||||
import http.client
|
||||
import subprocess
|
||||
|
|
@ -54,8 +51,6 @@ class BlockchainTest(BitcoinTestFramework):
|
|||
self._test_getchaintxstats()
|
||||
self._test_gettxoutsetinfo()
|
||||
self._test_getblockheader()
|
||||
self._test_getdifficulty()
|
||||
self._test_getnetworkhashps()
|
||||
self._test_stopatheight()
|
||||
self._test_waitforblockheight()
|
||||
assert self.nodes[0].verifychain(4, 0)
|
||||
|
|
@ -68,17 +63,18 @@ class BlockchainTest(BitcoinTestFramework):
|
|||
'bip9_softforks',
|
||||
'blocks',
|
||||
'chain',
|
||||
'chainwork',
|
||||
'difficulty',
|
||||
'headers',
|
||||
'initialblockdownload',
|
||||
'mediantime',
|
||||
'pruned',
|
||||
'signblock_asm',
|
||||
'signblock_hex',
|
||||
'size_on_disk',
|
||||
'softforks',
|
||||
'verificationprogress',
|
||||
'warnings',
|
||||
]
|
||||
|
||||
res = self.nodes[0].getblockchaininfo()
|
||||
|
||||
# result should have these additional pruning keys if manual pruning is enabled
|
||||
|
|
@ -212,29 +208,14 @@ class BlockchainTest(BitcoinTestFramework):
|
|||
assert_equal(header['height'], 200)
|
||||
assert_equal(header['confirmations'], 1)
|
||||
assert_equal(header['previousblockhash'], secondbesthash)
|
||||
assert_is_hex_string(header['chainwork'])
|
||||
assert_equal(header['nTx'], 1)
|
||||
assert_is_hash_string(header['hash'])
|
||||
assert_is_hash_string(header['previousblockhash'])
|
||||
assert_is_hash_string(header['merkleroot'])
|
||||
assert_is_hash_string(header['bits'], length=None)
|
||||
assert isinstance(header['time'], int)
|
||||
assert isinstance(header['mediantime'], int)
|
||||
assert isinstance(header['nonce'], int)
|
||||
assert isinstance(header['version'], int)
|
||||
assert isinstance(int(header['versionHex'], 16), int)
|
||||
assert isinstance(header['difficulty'], Decimal)
|
||||
|
||||
def _test_getdifficulty(self):
|
||||
difficulty = self.nodes[0].getdifficulty()
|
||||
# 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
|
||||
|
||||
def _test_getnetworkhashps(self):
|
||||
hashes_per_second = self.nodes[0].getnetworkhashps()
|
||||
# This should be 2 hashes every 10 minutes or 1/300
|
||||
assert abs(hashes_per_second * 300 - 1) < 0.0001
|
||||
|
||||
def _test_stopatheight(self):
|
||||
assert_equal(self.nodes[0].getblockcount(), 200)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from .messages import (
|
|||
ser_uint256,
|
||||
sha256,
|
||||
uint256_from_str,
|
||||
CProof,
|
||||
)
|
||||
from .script import (
|
||||
CScript,
|
||||
|
|
@ -55,6 +56,7 @@ def create_block(hashprev, coinbase, ntime=None):
|
|||
block.hashPrevBlock = hashprev
|
||||
block.nBits = 0x207fffff # difficulty retargeting is disabled in REGTEST chainparams
|
||||
block.vtx.append(coinbase)
|
||||
block.proof = CProof(bytearray.fromhex('51'), bytearray.fromhex(''))
|
||||
block.hashMerkleRoot = block.calc_merkle_root()
|
||||
block.calc_sha256()
|
||||
return block
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue