mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
test: introduce get_weight()
helper for CBlock
This commit is contained in:
parent
a084ebe133
commit
4af97c74ed
@ -450,8 +450,7 @@ class SegWitTest(BitcoinTestFramework):
|
||||
rpc_details = self.nodes[0].getblock(block.hash, True)
|
||||
assert_equal(rpc_details["size"], len(block.serialize()))
|
||||
assert_equal(rpc_details["strippedsize"], len(block.serialize(False)))
|
||||
weight = 3 * len(block.serialize(False)) + len(block.serialize())
|
||||
assert_equal(rpc_details["weight"], weight)
|
||||
assert_equal(rpc_details["weight"], block.get_weight())
|
||||
|
||||
# Upgraded node should not ask for blocks from unupgraded
|
||||
block4 = self.build_next_block(version=4)
|
||||
|
@ -746,6 +746,13 @@ class CBlock(CBlockHeader):
|
||||
self.nNonce += 1
|
||||
self.rehash()
|
||||
|
||||
# Calculate the block weight using witness and non-witness
|
||||
# serialization size (does NOT use sigops).
|
||||
def get_weight(self):
|
||||
with_witness_size = len(self.serialize(with_witness=True))
|
||||
without_witness_size = len(self.serialize(with_witness=False))
|
||||
return (WITNESS_SCALE_FACTOR - 1) * without_witness_size + with_witness_size
|
||||
|
||||
def __repr__(self):
|
||||
return "CBlock(nVersion=%i hashPrevBlock=%064x hashMerkleRoot=%064x nTime=%s nBits=%08x nNonce=%08x vtx=%s)" \
|
||||
% (self.nVersion, self.hashPrevBlock, self.hashMerkleRoot,
|
||||
|
Loading…
Reference in New Issue
Block a user