use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorTest method processStatusHavingBestBlockInBlockchainStore.
@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusHavingBestBlockInBlockchainStore() throws UnknownHostException {
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = new BlockChainBuilder().ofSize(2);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimplePeer sender = new SimplePeer();
final Block block = blockchain.getBlockByNumber(1);
final Keccak256 blockHash = block.getHash();
store.saveBlock(block);
// final Status status = new Status(block.getNumber(), block.getHash());
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
// processor.processStatus(sender, status);
Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
Assert.assertEquals(0, sender.getGetBlockMessages().size());
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBodyRequestMessageUsingBlockInBlockchain.
@Test
public void processBodyRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
final Block block = blockchain.getBlockByNumber(3);
final NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
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.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInStore.
@Test
public void processGetBlockHeaderMessageUsingBlockInStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final NetBlockStore store = new NetBlockStore();
store.saveBlock(block);
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
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.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorUnclesTest method rejectBlockWithTwoUnknownUnclesAndUnknownParent.
@Test
public void rejectBlockWithTwoUnknownUnclesAndUnknownParent() {
BlockChainImpl blockChain = new BlockChainBuilder().build();
NodeBlockProcessor processor = createNodeBlockProcessor(blockChain);
Block genesis = blockChain.getBestBlock();
Block block1 = new BlockBuilder(null, null, null).parent(genesis).build();
Block uncle1 = new BlockBuilder(null, null, null).parent(genesis).build();
Block uncle2 = new BlockBuilder(null, null, null).parent(genesis).build();
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle1.getHeader());
uncles.add(uncle2.getHeader());
Block block2 = new BlockBuilder(null, null, null).parent(block1).uncles(uncles).build();
SimplePeer sender = new SimplePeer();
processor.processBlock(sender, block2);
Assert.assertEquals(0, blockChain.getBestBlock().getNumber());
Assert.assertArrayEquals(genesis.getHash().getBytes(), blockChain.getBestBlockHash());
Assert.assertEquals(1, sender.getGetBlockMessages().size());
Assert.assertTrue(sender.getGetBlockMessagesHashes().contains(block1.getHash()));
}
use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.
the class NodeBlockProcessorUnclesTest method addBlockWithTwoKnownUncles.
@Test
public void addBlockWithTwoKnownUncles() {
BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
BlockChainImpl blockChain = blockChainBuilder.build();
org.ethereum.db.BlockStore blockStore = blockChainBuilder.getBlockStore();
NodeBlockProcessor processor = createNodeBlockProcessor(blockChain);
Block genesis = blockChain.getBestBlock();
BlockBuilder blockBuilder = new BlockBuilder(blockChain, null, blockStore).trieStore(blockChainBuilder.getTrieStore());
blockBuilder.parent(blockChain.getBestBlock());
Block block1 = blockBuilder.parent(genesis).build();
Block uncle1 = blockBuilder.parent(genesis).build();
Block uncle2 = blockBuilder.parent(genesis).build();
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle1.getHeader());
uncles.add(uncle2.getHeader());
Block block2 = blockBuilder.parent(block1).uncles(uncles).build();
processor.processBlock(null, block1);
processor.processBlock(null, uncle1);
processor.processBlock(null, uncle2);
SimplePeer sender = new SimplePeer();
processor.processBlock(sender, block2);
Assert.assertEquals(2, blockChain.getBestBlock().getNumber());
Assert.assertArrayEquals(block2.getHash().getBytes(), blockChain.getBestBlockHash());
Assert.assertTrue(sender.getGetBlockMessages().isEmpty());
}
Aggregations