mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 14:44:21 +01:00
Adds missing test on BlockProessor
This commit is contained in:
@@ -2,11 +2,19 @@ import pytest
|
|||||||
|
|
||||||
from pisa import c_logger
|
from pisa import c_logger
|
||||||
from pisa.block_processor import BlockProcessor
|
from pisa.block_processor import BlockProcessor
|
||||||
from pisa.utils.auth_proxy import JSONRPCException
|
from test.unit.conftest import get_random_value_hex, generate_block, generate_blocks
|
||||||
from test.unit.conftest import get_random_value_hex
|
|
||||||
|
|
||||||
c_logger.disabled = True
|
c_logger.disabled = True
|
||||||
|
|
||||||
|
hex_tx = (
|
||||||
|
"0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402"
|
||||||
|
"204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4"
|
||||||
|
"acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b"
|
||||||
|
"13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1ba"
|
||||||
|
"ded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482e"
|
||||||
|
"cad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def best_block_hash():
|
def best_block_hash():
|
||||||
@@ -41,29 +49,43 @@ def test_get_block_count():
|
|||||||
|
|
||||||
def test_decode_raw_transaction():
|
def test_decode_raw_transaction():
|
||||||
# We cannot exhaustively test this (we rely on bitcoind for this) but we can try to decode a correct transaction
|
# We cannot exhaustively test this (we rely on bitcoind for this) but we can try to decode a correct transaction
|
||||||
hex_tx = (
|
assert BlockProcessor.decode_raw_transaction(hex_tx) is not None
|
||||||
"0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402"
|
|
||||||
"204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4"
|
|
||||||
"acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b"
|
|
||||||
"13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1ba"
|
|
||||||
"ded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482e"
|
|
||||||
"cad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000"
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
BlockProcessor.decode_raw_transaction(hex_tx)
|
|
||||||
assert True
|
|
||||||
except JSONRPCException:
|
|
||||||
assert False
|
|
||||||
|
|
||||||
|
|
||||||
def test_decode_raw_transaction_invalid():
|
def test_decode_raw_transaction_invalid():
|
||||||
# Same but with an invalid one
|
# Same but with an invalid one
|
||||||
|
assert BlockProcessor.decode_raw_transaction(hex_tx[::-1]) is None
|
||||||
|
|
||||||
hex_tx = "A" * 16
|
|
||||||
|
|
||||||
try:
|
def test_get_missed_blocks():
|
||||||
BlockProcessor.decode_raw_transaction(hex_tx)
|
block_processor = BlockProcessor()
|
||||||
assert False
|
target_block = block_processor.get_best_block_hash()
|
||||||
except JSONRPCException:
|
|
||||||
assert True
|
# Generate some blocks and store the hash in a list
|
||||||
|
missed_blocks = []
|
||||||
|
for _ in range(5):
|
||||||
|
generate_block()
|
||||||
|
missed_blocks.append(BlockProcessor.get_best_block_hash())
|
||||||
|
|
||||||
|
# Check what we've missed
|
||||||
|
assert block_processor.get_missed_blocks(target_block) == missed_blocks
|
||||||
|
|
||||||
|
# We can see how it does not work if we replace the target by the first element in the list
|
||||||
|
block_tip = missed_blocks[0]
|
||||||
|
assert block_processor.get_missed_blocks(block_tip) != missed_blocks
|
||||||
|
|
||||||
|
# But it does again if we skip that block
|
||||||
|
assert block_processor.get_missed_blocks(block_tip) == missed_blocks[1:]
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_distance_to_tip():
|
||||||
|
target_distance = 5
|
||||||
|
|
||||||
|
block_processor = BlockProcessor()
|
||||||
|
target_block = block_processor.get_best_block_hash()
|
||||||
|
|
||||||
|
# Mine some blocks up to the target distance
|
||||||
|
generate_blocks(target_distance)
|
||||||
|
|
||||||
|
# Check if the distance is properly computed
|
||||||
|
assert block_processor.get_distance_to_tip(target_block) == target_distance
|
||||||
|
|||||||
Reference in New Issue
Block a user