Search in sources :

Example 41 with TestSystemProperties

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

the class AsyncNodeBlockProcessorTest method processBlockHashRequestMessageUsingEmptyStore.

@Test
public void processBlockHashRequestMessageUsingEmptyStore() {
    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.processBlockRequest(sender, 100, block.getHash().getBytes());
    Assert.assertFalse(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
    Assert.assertTrue(sender.getMessages().isEmpty());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) 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 42 with TestSystemProperties

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

the class AsyncNodeBlockProcessorTest method processBlockAddingToBlockchainUsingItsParent.

@Test(timeout = WAIT_TIME)
public void processBlockAddingToBlockchainUsingItsParent() throws InterruptedException {
    final NetBlockStore store = new NetBlockStore();
    final BlockGenerator blockGenerator = new BlockGenerator();
    final Block genesis = blockGenerator.getGenesisBlock();
    store.saveBlock(genesis);
    final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    final Block parent = blockGenerator.createChildBlock(blockchain.getBlockByNumber(10));
    final Block block = blockGenerator.createChildBlock(parent);
    Assert.assertEquals(11, parent.getNumber());
    Assert.assertEquals(12, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), parent.getParentHash().getBytes());
    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, block);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(block.getHash());
    }
    Assert.assertTrue(store.hasBlock(block));
    Assert.assertNull(blockchain.getBlockByHash(block.getHash().getBytes()));
    blockProcessResult = processor.processBlock(null, parent);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(parent.getHash());
    }
    Assert.assertFalse(store.hasBlock(block));
    Assert.assertFalse(store.hasBlock(parent));
    Assert.assertEquals(12, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
    Assert.assertEquals(1, store.size());
    processor.stopAndWait(WAIT_TIME);
}
Also used : Blockchain(org.ethereum.core.Blockchain) AsyncNodeBlockProcessorListener(co.rsk.net.utils.AsyncNodeBlockProcessorListener) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 43 with TestSystemProperties

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

the class AsyncNodeBlockProcessorTest method processBlockAddingToBlockchain.

@Test(timeout = WAIT_TIME)
public void processBlockAddingToBlockchain() throws InterruptedException {
    final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    final NetBlockStore store = new NetBlockStore();
    final Block genesis = blockchain.getBlockByNumber(0);
    store.saveBlock(genesis);
    final Block block = new BlockGenerator().createChildBlock(blockchain.getBlockByNumber(10));
    Assert.assertEquals(11, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
    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, block);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(block.getHash());
    }
    Assert.assertFalse(store.hasBlock(block));
    Assert.assertEquals(11, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
    Assert.assertEquals(1, store.size());
    processor.stopAndWait(WAIT_TIME);
}
Also used : Blockchain(org.ethereum.core.Blockchain) AsyncNodeBlockProcessorListener(co.rsk.net.utils.AsyncNodeBlockProcessorListener) Block(org.ethereum.core.Block) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 44 with TestSystemProperties

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

the class AsyncNodeBlockProcessorTest method invalidBlock.

@Test
public void invalidBlock() {
    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 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.INVALID_RESULT_INSTANCE, DummyBlockValidator.INVALID_RESULT_INSTANCE);
    BlockProcessResult blockProcessResult = processor.processBlock(sender, block);
    Assert.assertFalse(blockProcessResult.isScheduledForProcessing());
    Assert.assertFalse(blockProcessResult.wasBlockAdded(block));
    Assert.assertTrue(blockProcessResult.isInvalidBlock());
}
Also used : SimplePeer(co.rsk.net.simples.SimplePeer) 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)

Example 45 with TestSystemProperties

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

the class AsyncNodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInStore.

@Test
public void processGetBlockHeaderMessageUsingBlockInStore() {
    final Block block = new BlockGenerator().getBlock(3);
    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();
    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) 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)

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