Search in sources :

Example 1 with ReferenceTestWorldState

use of org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState in project besu by hyperledger.

the class BackwardSyncContextTest method setup.

@Before
public void setup() {
    when(mockProtocolSpec.getBlockValidator()).thenReturn(blockValidator);
    when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(mockProtocolSpec);
    genesisBlock = blockDataGenerator.genesisBlock();
    remoteBlockchain = createInMemoryBlockchain(genesisBlock);
    localBlockchain = createInMemoryBlockchain(genesisBlock);
    for (int i = 1; i <= REMOTE_HEIGHT; i++) {
        final BlockDataGenerator.BlockOptions options = new BlockDataGenerator.BlockOptions().setBlockNumber(i).setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).orElseThrow());
        final Block block = blockDataGenerator.block(options);
        final List<TransactionReceipt> receipts = blockDataGenerator.receipts(block);
        remoteBlockchain.appendBlock(block, receipts);
        if (i <= LOCAL_HEIGHT) {
            localBlockchain.appendBlock(block, receipts);
        }
    }
    when(protocolContext.getBlockchain()).thenReturn(localBlockchain);
    EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
    peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
    EthContext ethContext = ethProtocolManager.ethContext();
    when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenAnswer(invocation -> {
        final Object[] arguments = invocation.getArguments();
        Block block = (Block) arguments[1];
        return new Result(new BlockValidator.BlockProcessingOutputs(new ReferenceTestWorldState(), blockDataGenerator.receipts(block)));
    });
    backwardChain = newBackwardChain();
    context = spy(new BackwardSyncContext(protocolContext, protocolSchedule, metricsSystem, ethContext, syncState, backwardChain));
    doReturn(true).when(context).isReady();
    doReturn(2).when(context).getBatchSize();
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) ReferenceTestWorldState(org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) Block(org.hyperledger.besu.ethereum.core.Block) Before(org.junit.Before)

Example 2 with ReferenceTestWorldState

use of org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState in project besu by hyperledger.

the class ForwardSyncStepTest method setup.

@Before
public void setup() {
    headersStorage = new GenericKeyValueStorageFacade<>(Hash::toArrayUnsafe, new BlocksHeadersConvertor(new MainnetBlockHeaderFunctions()), new InMemoryKeyValueStorage());
    blocksStorage = new GenericKeyValueStorageFacade<>(Hash::toArrayUnsafe, new BlocksConvertor(new MainnetBlockHeaderFunctions()), new InMemoryKeyValueStorage());
    chainStorage = new GenericKeyValueStorageFacade<>(Hash::toArrayUnsafe, new HashConvertor(), new InMemoryKeyValueStorage());
    Block genesisBlock = blockDataGenerator.genesisBlock();
    remoteBlockchain = createInMemoryBlockchain(genesisBlock);
    localBlockchain = createInMemoryBlockchain(genesisBlock);
    for (int i = 1; i <= REMOTE_HEIGHT; i++) {
        final BlockDataGenerator.BlockOptions options = new BlockDataGenerator.BlockOptions().setBlockNumber(i).setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).orElseThrow());
        final Block block = blockDataGenerator.block(options);
        final List<TransactionReceipt> receipts = blockDataGenerator.receipts(block);
        remoteBlockchain.appendBlock(block, receipts);
        if (i <= LOCAL_HEIGHT) {
            localBlockchain.appendBlock(block, receipts);
        }
    }
    when(context.getProtocolContext().getBlockchain()).thenReturn(localBlockchain);
    when(context.getProtocolSchedule()).thenReturn(protocolSchedule);
    when(context.getBatchSize()).thenReturn(2);
    when(context.executeNextStep(null)).thenReturn(CompletableFuture.completedFuture(null));
    EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
    peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
    EthContext ethContext = ethProtocolManager.ethContext();
    when(context.getEthContext()).thenReturn(ethContext);
    when(context.getBlockValidatorForBlock(any()).validateAndProcessBlock(any(), any(), any(), any())).thenAnswer(invocation -> {
        final Object[] arguments = invocation.getArguments();
        Block block = (Block) arguments[1];
        return new Result(new BlockValidator.BlockProcessingOutputs(new ReferenceTestWorldState(), blockDataGenerator.receipts(block)));
    });
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) ReferenceTestWorldState(org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) Block(org.hyperledger.besu.ethereum.core.Block) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) Before(org.junit.Before)

Example 3 with ReferenceTestWorldState

use of org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState in project besu by hyperledger.

the class BackwardsSyncContextTest method setup.

@Before
public void setup() {
    when(mockProtocolSpec.getBlockValidator()).thenReturn(blockValidator);
    when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(mockProtocolSpec);
    Block genesisBlock = blockDataGenerator.genesisBlock();
    remoteBlockchain = createInMemoryBlockchain(genesisBlock);
    localBlockchain = createInMemoryBlockchain(genesisBlock);
    for (int i = 1; i <= REMOTE_HEIGHT; i++) {
        final BlockDataGenerator.BlockOptions options = new BlockDataGenerator.BlockOptions().setBlockNumber(i).setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).orElseThrow());
        final Block block = blockDataGenerator.block(options);
        final List<TransactionReceipt> receipts = blockDataGenerator.receipts(block);
        remoteBlockchain.appendBlock(block, receipts);
        if (i <= LOCAL_HEIGHT) {
            localBlockchain.appendBlock(block, receipts);
        }
    }
    when(protocolContext.getBlockchain()).thenReturn(localBlockchain);
    EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create();
    peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager);
    EthContext ethContext = ethProtocolManager.ethContext();
    when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenAnswer(invocation -> {
        final Object[] arguments = invocation.getArguments();
        Block block = (Block) arguments[1];
        return new Result(new BlockValidator.BlockProcessingOutputs(new ReferenceTestWorldState(), blockDataGenerator.receipts(block)));
    });
    context = spy(new BackwardsSyncContext(protocolContext, protocolSchedule, metricsSystem, ethContext));
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) ReferenceTestWorldState(org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) Block(org.hyperledger.besu.ethereum.core.Block) Before(org.junit.Before)

Aggregations

BlockValidator (org.hyperledger.besu.ethereum.BlockValidator)3 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)3 Block (org.hyperledger.besu.ethereum.core.Block)3 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)3 TransactionReceipt (org.hyperledger.besu.ethereum.core.TransactionReceipt)3 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)3 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)3 ReferenceTestWorldState (org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState)3 Before (org.junit.Before)3 MainnetBlockHeaderFunctions (org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions)1 InMemoryKeyValueStorage (org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage)1