use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method duplicatedBlock.
@Test
public void duplicatedBlock() {
final NetBlockStore store = new NetBlockStore();
final Peer sender = new SimplePeer();
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final BlockGenerator blockGenerator = new BlockGenerator();
final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
final Block sameBlock = new Block(block.getHeader(), block.getTransactionsList(), block.getUncleList(), true, true);
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);
processor.processBlock(sender, block);
BlockProcessResult blockProcessResult = processor.processBlock(sender, sameBlock);
Assert.assertFalse(blockProcessResult.isScheduledForProcessing());
Assert.assertFalse(blockProcessResult.wasBlockAdded(block));
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processGetBlockMessageUsingBlockInStore.
@Test
public void processGetBlockMessageUsingBlockInStore() {
final Block block = new BlockGenerator().getBlock(3);
final Keccak256 blockHash = block.getHash();
final NetBlockStore store = new NetBlockStore();
store.saveBlock(block);
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();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processGetBlock(sender, 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_MESSAGE, message.getMessageType());
final BlockMessage bMessage = (BlockMessage) message;
Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processBlockHeadersRequestMessageUsingBlockInBlockchain.
@Test
public void processBlockHeadersRequestMessageUsingBlockInBlockchain() {
final Blockchain blockchain = new BlockChainBuilder().ofSize(100);
final Block block = blockchain.getBlockByNumber(60);
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, 100, block.getHash().getBytes(), 20);
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 response = (BlockHeadersResponseMessage) message;
Assert.assertEquals(100, response.getId());
Assert.assertNotNull(response.getBlockHeaders());
Assert.assertEquals(20, response.getBlockHeaders().size());
for (int k = 0; k < 20; k++) {
Assert.assertEquals(blockchain.getBlockByNumber(60 - k).getHash(), response.getBlockHeaders().get(k).getHash());
}
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class AsyncNodeBlockProcessorTest method processTenBlocksAddingToBlockchain.
@Test(timeout = WAIT_TIME)
public void processTenBlocksAddingToBlockchain() 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 = processor.processBlock(null, genesis);
if (blockProcessResult.isScheduledForProcessing()) {
listener.waitForBlock(genesis.getHash());
}
Assert.assertEquals(0, store.size());
Block blockToWait = null;
for (Block b : blocks) {
BlockProcessResult result = processor.processBlock(null, b);
if (result.isScheduledForProcessing()) {
blockToWait = b;
}
}
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 processGetBlockMessageUsingEmptyStore.
@Test
public void processGetBlockMessageUsingEmptyStore() {
final Block block = new BlockGenerator().getBlock(3);
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();
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
processor.processGetBlock(sender, block.getHash().getBytes());
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
Assert.assertTrue(sender.getMessages().isEmpty());
}
Aggregations