use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.
the class AsyncNodeBlockProcessorUnclesTest method setUp.
@Before
public void setUp() {
blockChainBuilder = new BlockChainBuilder();
blockChain = blockChainBuilder.build();
listener = new AsyncNodeBlockProcessorListener();
processor = createAsyncNodeBlockProcessor(blockChain, listener);
processor.start();
}
use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processTwoBlockListsAddingToBlockchain.
@Test(timeout = WAIT_TIME)
public void processTwoBlockListsAddingToBlockchain() throws InterruptedException {
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final NetBlockStore store = new NetBlockStore();
final Block genesis = blockchain.getBestBlock();
final BlockGenerator blockGenerator = new BlockGenerator();
final List<Block> blocks = blockGenerator.getBlockChain(genesis, 10);
final List<Block> blocks2 = blockGenerator.getBlockChain(genesis, 20);
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
processor.start();
BlockProcessResult blockProcessResult = processor.processBlock(null, genesis);
if (blockProcessResult.isScheduledForProcessing()) {
listener.waitForBlock(genesis.getHash());
}
Assert.assertEquals(0, store.size());
Block blockToWait = null;
for (Block b : blocks) {
blockProcessResult = processor.processBlock(null, b);
if (blockProcessResult.isScheduledForProcessing()) {
blockToWait = b;
}
}
for (Block b : blocks2) {
blockProcessResult = processor.processBlock(null, b);
if (blockProcessResult.isScheduledForProcessing()) {
blockToWait = b;
}
}
if (blockToWait != null) {
listener.waitForBlock(blockToWait.getHash());
}
Assert.assertEquals(20, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
processor.stopAndWait(WAIT_TIME);
}
use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processTenBlocksInverseOrderAddingToBlockchain.
@Test(timeout = WAIT_TIME)
public void processTenBlocksInverseOrderAddingToBlockchain() throws InterruptedException {
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final NetBlockStore store = new NetBlockStore();
final Block genesis = blockchain.getBestBlock();
final List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
processor.start();
BlockProcessResult blockProcessResult;
Block blockToWait = null;
for (int k = 0; k < 10; k++) {
Block b = blocks.get(9 - k);
blockProcessResult = processor.processBlock(null, b);
if (blockProcessResult.isScheduledForProcessing()) {
blockToWait = b;
}
}
blockProcessResult = processor.processBlock(null, genesis);
if (blockProcessResult.isScheduledForProcessing()) {
blockToWait = genesis;
}
if (blockToWait != null) {
listener.waitForBlock(blockToWait.getHash());
}
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
processor.stopAndWait(WAIT_TIME);
}
use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processTenBlocksWithHoleAddingToBlockchain.
@Test(timeout = WAIT_TIME)
public void processTenBlocksWithHoleAddingToBlockchain() throws InterruptedException {
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final NetBlockStore store = new NetBlockStore();
final Block genesis = blockchain.getBestBlock();
final List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final TestSystemProperties config = new TestSystemProperties();
final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
processor.start();
BlockProcessResult blockProcessResult;
Block blockToWait = null;
for (int k = 0; k < 10; k++) {
if (k != 5) {
Block b = blocks.get(9 - k);
blockProcessResult = processor.processBlock(null, b);
if (blockProcessResult.isScheduledForProcessing()) {
blockToWait = b;
}
}
}
blockProcessResult = processor.processBlock(null, genesis);
if (blockProcessResult.isScheduledForProcessing()) {
blockToWait = genesis;
}
blockProcessResult = processor.processBlock(null, blocks.get(4));
if (blockProcessResult.isScheduledForProcessing()) {
blockToWait = blocks.get(4);
}
if (blockToWait != null) {
listener.waitForBlock(blockToWait.getHash());
}
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
processor.stopAndWait(WAIT_TIME);
}
Aggregations