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();
}
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)));
});
}
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));
}
Aggregations