use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processTenBlocksGenesisAtLastAddingToBlockchain.
@Test(timeout = WAIT_TIME)
public void processTenBlocksGenesisAtLastAddingToBlockchain() throws InterruptedException {
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
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 (Block b : blocks) {
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.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInBlockchain.
@Test
public void processGetBlockHeaderMessageUsingBlockInBlockchain() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final Block block = blockchain.getBlockByNumber(5);
final NetBlockStore store = new NetBlockStore();
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 AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
processor.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), 1);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());
final BlockHeadersResponseMessage bMessage = (BlockHeadersResponseMessage) message;
Assert.assertEquals(block.getHeader().getHash(), bMessage.getBlockHeaders().get(0).getHash());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBodyRequestMessageUsingBlockInBlockchain.
@Test
public void processBodyRequestMessageUsingBlockInBlockchain() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final Block block = blockchain.getBlockByNumber(3);
final NetBlockStore store = new NetBlockStore();
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 AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
processor.processBodyRequest(sender, 100, block.getHash().getBytes());
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BODY_RESPONSE_MESSAGE, message.getMessageType());
final BodyResponseMessage bMessage = (BodyResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Assert.assertEquals(block.getTransactionsList(), bMessage.getTransactions());
Assert.assertEquals(block.getUncleList(), bMessage.getUncles());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockHashRequestMessageUsingBlockInBlockchain.
@Test
public void processBlockHashRequestMessageUsingBlockInBlockchain() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final Block block = blockchain.getBlockByNumber(5);
final Keccak256 blockHash = block.getHash();
final NetBlockStore store = new NetBlockStore();
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 AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processBlockRequest(sender, 100, block.getHash().getBytes());
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_RESPONSE_MESSAGE, message.getMessageType());
final BlockResponseMessage bMessage = (BlockResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockRetrievingParentUsingSender.
@Test
public void processBlockRetrievingParentUsingSender() {
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
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 AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
final SimplePeer sender = new SimplePeer();
final BlockGenerator blockGenerator = new BlockGenerator();
final Block genesis = blockGenerator.getGenesisBlock();
final Block parent = blockGenerator.createChildBlock(genesis);
final Block block = blockGenerator.createChildBlock(parent);
processor.processBlock(sender, block);
Assert.assertEquals(1, processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size());
Assert.assertTrue(store.hasBlock(block));
Assert.assertEquals(1, sender.getMessages().size());
Assert.assertEquals(1, store.size());
final Message message = sender.getMessages().get(0);
Assert.assertNotNull(message);
Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, message.getMessageType());
final GetBlockMessage gbMessage = (GetBlockMessage) message;
Assert.assertArrayEquals(block.getParentHash().getBytes(), gbMessage.getBlockHash());
}
Aggregations