Changeset View
Changeset View
Standalone View
Standalone View
test/functional/chronik_block.py
Show All 29 Lines | def run_test(self): | ||||
expected_genesis_block = pb.Block( | expected_genesis_block = pb.Block( | ||||
block_info=pb.BlockInfo( | block_info=pb.BlockInfo( | ||||
hash=bytes.fromhex(GENESIS_BLOCK_HASH)[::-1], | hash=bytes.fromhex(GENESIS_BLOCK_HASH)[::-1], | ||||
prev_hash=bytes(32), | prev_hash=bytes(32), | ||||
height=0, | height=0, | ||||
n_bits=0x207fffff, | n_bits=0x207fffff, | ||||
timestamp=TIME_GENESIS_BLOCK, | timestamp=TIME_GENESIS_BLOCK, | ||||
block_size=285, | |||||
num_txs=1, | |||||
num_inputs=1, | |||||
num_outputs=1, | |||||
sum_input_sats=0, | |||||
sum_coinbase_output_sats=5000000000, | |||||
sum_normal_output_sats=0, | |||||
sum_burned_sats=0, | |||||
), | ), | ||||
) | ) | ||||
# Not a valid hash or height | # Not a valid hash or height | ||||
assert_equal(chronik.block('1234f').err(400).msg, | assert_equal(chronik.block('1234f').err(400).msg, | ||||
'400: Not a hash or height: 1234f') | '400: Not a hash or height: 1234f') | ||||
assert_equal(chronik.block('00' * 31).err(400).msg, | assert_equal(chronik.block('00' * 31).err(400).msg, | ||||
f'400: Not a hash or height: {"00"*31}') | f'400: Not a hash or height: {"00"*31}') | ||||
Show All 22 Lines | def run_test(self): | ||||
proto_block = chronik.block(i).ok() | proto_block = chronik.block(i).ok() | ||||
assert_equal(proto_block, pb.Block( | assert_equal(proto_block, pb.Block( | ||||
block_info=pb.BlockInfo( | block_info=pb.BlockInfo( | ||||
hash=bytes.fromhex(block_hashes[i])[::-1], | hash=bytes.fromhex(block_hashes[i])[::-1], | ||||
prev_hash=bytes.fromhex(block_hashes[i - 1])[::-1], | prev_hash=bytes.fromhex(block_hashes[i - 1])[::-1], | ||||
height=i, | height=i, | ||||
n_bits=0x207fffff, | n_bits=0x207fffff, | ||||
timestamp=proto_block.block_info.timestamp, | timestamp=proto_block.block_info.timestamp, | ||||
block_size=181, | |||||
num_txs=1, | |||||
num_inputs=1, | |||||
num_outputs=1, | |||||
sum_input_sats=0, | |||||
sum_coinbase_output_sats=5000000000, | |||||
sum_normal_output_sats=0, | |||||
sum_burned_sats=0, | |||||
), | ), | ||||
)) | )) | ||||
assert_equal(proto_block, chronik.block(block_hashes[i]).ok()) | assert_equal(proto_block, chronik.block(block_hashes[i]).ok()) | ||||
block_hashes.append(proto_block.block_info.hash) | block_hashes.append(proto_block.block_info.hash) | ||||
# Invalidate in the middle of the chain | # Invalidate in the middle of the chain | ||||
node.invalidateblock(block_hashes[50]) | node.invalidateblock(block_hashes[50]) | ||||
# Gives 404 for the invalidated blocks | # Gives 404 for the invalidated blocks | ||||
Show All 13 Lines | def run_test(self): | ||||
proto_block = chronik.block(50).ok() | proto_block = chronik.block(50).ok() | ||||
assert_equal(proto_block, pb.Block( | assert_equal(proto_block, pb.Block( | ||||
block_info=pb.BlockInfo( | block_info=pb.BlockInfo( | ||||
hash=bytes.fromhex(fork_hash)[::-1], | hash=bytes.fromhex(fork_hash)[::-1], | ||||
prev_hash=bytes.fromhex(block_hashes[49])[::-1], | prev_hash=bytes.fromhex(block_hashes[49])[::-1], | ||||
height=50, | height=50, | ||||
n_bits=0x207fffff, | n_bits=0x207fffff, | ||||
timestamp=proto_block.block_info.timestamp, | timestamp=proto_block.block_info.timestamp, | ||||
block_size=181, | |||||
num_txs=1, | |||||
num_inputs=1, | |||||
num_outputs=1, | |||||
sum_input_sats=0, | |||||
sum_coinbase_output_sats=5000000000, | |||||
sum_normal_output_sats=0, | |||||
sum_burned_sats=0, | |||||
), | ), | ||||
)) | )) | ||||
assert_equal(chronik.block(fork_hash).ok(), proto_block) | assert_equal(chronik.block(fork_hash).ok(), proto_block) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ChronikBlockTest().main() | ChronikBlockTest().main() |