Skip to content

Commit

Permalink
Merge bitcoin#25976: QA: rpc_blockchain: Test output of getblock verb…
Browse files Browse the repository at this point in the history
…osity 0, False, and True

f663b43 QA: rpc_blockchain: Test output of getblock verbosity 0, False, and True (Luke Dashjr)

Pull request description:

  Currently getblock's "verbosity" is documented as a NUM, though it has a fallback to Boolean for the (deprecated?) "verbose" alias.

  Since we've been doing more generic type-checking on RPC stuff, I think it would be a good idea to actually test the Boolean values work.

  I didn't see an existing test for verbosity=0, so this adds that too.

ACKs for top commit:
  aureleoules:
    ACK f663b43.

Tree-SHA512: 321a7795a2f32e469d28879dd323c85cb6b221828030e2a33ad9afd35a648191151a79b04e359b2f58314e43360f81c25f05be07deb42f61efdf556850a7266c
  • Loading branch information
MacroFake committed Sep 5, 2022
2 parents 0ebd4db + f663b43 commit e864f2e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/functional/rpc_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
msg_block,
)
from test_framework.p2p import P2PInterface
from test_framework.script import hash256
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
Expand Down Expand Up @@ -485,6 +486,10 @@ def _test_getblock(self):
self.wallet.send_self_transfer(fee_rate=fee_per_kb, from_node=node)
blockhash = self.generate(node, 1)[0]

def assert_hexblock_hashes(verbosity):
block = node.getblock(blockhash, verbosity)
assert_equal(blockhash, hash256(bytes.fromhex(block[:160]))[::-1].hex())

def assert_fee_not_in_block(verbosity):
block = node.getblock(blockhash, verbosity)
assert 'fee' not in block['tx'][1]
Expand Down Expand Up @@ -519,8 +524,13 @@ def assert_vin_does_not_contain_prevout(verbosity):
for vin in tx["vin"]:
assert "prevout" not in vin

self.log.info("Test that getblock with verbosity 0 hashes to expected value")
assert_hexblock_hashes(0)
assert_hexblock_hashes(False)

self.log.info("Test that getblock with verbosity 1 doesn't include fee")
assert_fee_not_in_block(1)
assert_fee_not_in_block(True)

self.log.info('Test that getblock with verbosity 2 and 3 includes expected fee')
assert_fee_in_block(2)
Expand Down

0 comments on commit e864f2e

Please sign in to comment.