mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
test: don't rely on usdt block_conn event order
Relying on block_connected event order in the USDT interface tests turned out to be brittle. Fixes https://github.com/bitcoin/bitcoin/issues/25793 Fixes https://github.com/bitcoin/bitcoin/issues/25764
This commit is contained in:
parent
b1a2021f78
commit
0532aa7444
1 changed files with 6 additions and 5 deletions
|
@ -91,7 +91,7 @@ class ValidationTracepointTest(BitcoinTestFramework):
|
||||||
# that the handle_* functions succeeded.
|
# that the handle_* functions succeeded.
|
||||||
BLOCKS_EXPECTED = 2
|
BLOCKS_EXPECTED = 2
|
||||||
blocks_checked = 0
|
blocks_checked = 0
|
||||||
expected_blocks = list()
|
expected_blocks = dict()
|
||||||
|
|
||||||
self.log.info("hook into the validation:block_connected tracepoint")
|
self.log.info("hook into the validation:block_connected tracepoint")
|
||||||
ctx = USDT(pid=self.nodes[0].process.pid)
|
ctx = USDT(pid=self.nodes[0].process.pid)
|
||||||
|
@ -104,15 +104,16 @@ class ValidationTracepointTest(BitcoinTestFramework):
|
||||||
nonlocal expected_blocks, blocks_checked
|
nonlocal expected_blocks, blocks_checked
|
||||||
event = ctypes.cast(data, ctypes.POINTER(Block)).contents
|
event = ctypes.cast(data, ctypes.POINTER(Block)).contents
|
||||||
self.log.info(f"handle_blockconnected(): {event}")
|
self.log.info(f"handle_blockconnected(): {event}")
|
||||||
block = expected_blocks.pop(0)
|
block_hash = bytes(event.hash[::-1]).hex()
|
||||||
assert_equal(block["hash"], bytes(event.hash[::-1]).hex())
|
block = expected_blocks[block_hash]
|
||||||
|
assert_equal(block["hash"], block_hash)
|
||||||
assert_equal(block["height"], event.height)
|
assert_equal(block["height"], event.height)
|
||||||
assert_equal(len(block["tx"]), event.transactions)
|
assert_equal(len(block["tx"]), event.transactions)
|
||||||
assert_equal(len([tx["vin"] for tx in block["tx"]]), event.inputs)
|
assert_equal(len([tx["vin"] for tx in block["tx"]]), event.inputs)
|
||||||
assert_equal(0, event.sigops) # no sigops in coinbase tx
|
assert_equal(0, event.sigops) # no sigops in coinbase tx
|
||||||
# only plausibility checks
|
# only plausibility checks
|
||||||
assert(event.duration > 0)
|
assert(event.duration > 0)
|
||||||
|
del expected_blocks[block_hash]
|
||||||
blocks_checked += 1
|
blocks_checked += 1
|
||||||
|
|
||||||
bpf["block_connected"].open_perf_buffer(
|
bpf["block_connected"].open_perf_buffer(
|
||||||
|
@ -122,7 +123,7 @@ class ValidationTracepointTest(BitcoinTestFramework):
|
||||||
block_hashes = self.generatetoaddress(
|
block_hashes = self.generatetoaddress(
|
||||||
self.nodes[0], BLOCKS_EXPECTED, ADDRESS_BCRT1_UNSPENDABLE)
|
self.nodes[0], BLOCKS_EXPECTED, ADDRESS_BCRT1_UNSPENDABLE)
|
||||||
for block_hash in block_hashes:
|
for block_hash in block_hashes:
|
||||||
expected_blocks.append(self.nodes[0].getblock(block_hash, 2))
|
expected_blocks[block_hash] = self.nodes[0].getblock(block_hash, 2)
|
||||||
|
|
||||||
bpf.perf_buffer_poll(timeout=200)
|
bpf.perf_buffer_poll(timeout=200)
|
||||||
bpf.cleanup()
|
bpf.cleanup()
|
||||||
|
|
Loading…
Add table
Reference in a new issue