# Nimbus # Copyright (c) 2022-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. {.used.} {.push raises: [].} import unittest2, stint, eth/common/eth_types_rlp, ../eth_data/history_data_json_store, ../network/history/[history_content, accumulator], ./test_helpers suite "Header Accumulator": test "Header Accumulator Canonical Verification": const # Amount of headers to be created and added to the accumulator amount = mergeBlockNumber # Headers to test verification for. # Note: This test assumes at least 5 epochs headersToTest = [ 0, epochSize - 1, epochSize, epochSize*2 - 1, epochSize*2, epochSize*3 - 1, epochSize*3, epochSize*3 + 1, int(amount) - 1] var headers: seq[BlockHeader] for i in 0.. than latest header in accumulator) var proof: AccumulatorProof let header = BlockHeader(blockNumber: mergeBlockNumber.stuint(256)) check verifyAccumulatorProof(accumulator, header, proof).isErr() # Test altered block headers by altering the difficulty for i in headersToTest: let proof = buildProof(headers[i], epochAccumulators) check: proof.isOk() # Alter the block header so the proof no longer matches let header = BlockHeader( blockNumber: i.stuint(256), difficulty: 2.stuint(256)) check verifyAccumulatorProof(accumulator, header, proof.get()).isErr() block: # Test invalid proofs var proof: AccumulatorProof for i in headersToTest: check verifyAccumulatorProof(accumulator, headers[i], proof).isErr() test "Header Accumulator - Not Finished": # Less headers than needed to finish the accumulator const amount = mergeBlockNumber - 1 var headers: seq[BlockHeader] for i in 0..