Search in sources :

Example 51 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class NodeBlockProcessorTest method canBeIgnoredForUncles.

@Test
public void canBeIgnoredForUncles() throws UnknownHostException {
    final NetBlockStore store = new NetBlockStore();
    final Peer sender = new SimplePeer();
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final Blockchain blockchain = new BlockChainBuilder().ofSize(15);
    final TestSystemProperties config = new TestSystemProperties();
    int uncleGenerationLimit = config.getNetworkConstants().getUncleGenerationLimit();
    final long blockNumberThatCanBeIgnored = blockchain.getBestBlock().getNumber() - 1 - uncleGenerationLimit;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    Assert.assertTrue(processor.canBeIgnoredForUnclesRewards(blockNumberThatCanBeIgnored));
    Assert.assertFalse(processor.canBeIgnoredForUnclesRewards(blockNumberThatCanBeIgnored + 1));
}
Also used : SimplePeer(co.rsk.net.simples.SimplePeer) Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SimplePeer(co.rsk.net.simples.SimplePeer) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 52 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class NodeBlockProcessorTest method processBlockRequestMessageUsingBlockInStore.

@Test
public void processBlockRequestMessageUsingBlockInStore() throws UnknownHostException {
    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);
    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();
    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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Keccak256(co.rsk.crypto.Keccak256) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 53 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInBlockchain.

@Test
public void processGetBlockHeaderMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    final Block block = blockchain.getBlockByNumber(5);
    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.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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 54 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class NodeBlockProcessorTest method processGetBlockMessageUsingBlockInStore.

@Test
public void processGetBlockMessageUsingBlockInStore() throws UnknownHostException {
    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);
    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();
    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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Keccak256(co.rsk.crypto.Keccak256) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 55 with TestSystemProperties

use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.

the class NodeBlockProcessorTest method processBlockRetrievingParentUsingSender.

@Test
public void processBlockRetrievingParentUsingSender() throws UnknownHostException {
    final NetBlockStore store = new NetBlockStore();
    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();
    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.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
    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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Aggregations

TestSystemProperties (co.rsk.config.TestSystemProperties)158 Test (org.junit.Test)130 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)109 Blockchain (org.ethereum.core.Blockchain)78 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)75 SimplePeer (co.rsk.net.simples.SimplePeer)69 Block (org.ethereum.core.Block)69 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)56 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)23 EthereumListener (org.ethereum.listener.EthereumListener)23 BlockStore (org.ethereum.db.BlockStore)21 RskSystemProperties (co.rsk.config.RskSystemProperties)17 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)16 Keccak256 (co.rsk.crypto.Keccak256)13 RepositoryLocator (co.rsk.db.RepositoryLocator)10 World (co.rsk.test.World)10 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)9 Ignore (org.junit.Ignore)9 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)8 AsyncNodeBlockProcessorListener (co.rsk.net.utils.AsyncNodeBlockProcessorListener)8