Search in sources :

Example 56 with TestSystemProperties

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

the class NodeBlockProcessorTest method syncingThenNoSyncing.

@Test
@Ignore("Ignored when Process status deleted on block processor")
public void syncingThenNoSyncing() {
    NetBlockStore store = new NetBlockStore();
    Block block = new BlockGenerator().createBlock(30, 0);
    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);
    Assert.assertFalse(processor.hasBetterBlockToSync());
    // Status status = new Status(block.getNumber(), block.getHash());
    // processor.processStatus(new SimpleNodeChannel(null, null), status);
    Assert.assertTrue(processor.hasBetterBlockToSync());
    Assert.assertTrue(processor.hasBetterBlockToSync());
    blockchain.setStatus(block, new BlockDifficulty(BigInteger.valueOf(30)));
    Assert.assertFalse(processor.hasBetterBlockToSync());
    Assert.assertFalse(processor.hasBetterBlockToSync());
    Block block2 = new BlockGenerator().createBlock(60, 0);
    // Status status2 = new Status(block2.getNumber(), block2.getHash());
    // processor.processStatus(new SimpleNodeChannel(null, null), status2);
    Assert.assertTrue(processor.hasBetterBlockToSync());
    Assert.assertFalse(processor.hasBetterBlockToSync());
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 57 with TestSystemProperties

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

the class NodeBlockProcessorTest method processStatusHavingBestBlockInStore.

@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusHavingBestBlockInStore() 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 block = blockGenerator.createChildBlock(genesis);
    store.saveBlock(block);
    // final Status status = new Status(block.getNumber(), block.getHash());
    // processor.processStatus(sender, status);
    Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
    Assert.assertEquals(1, store.size());
}
Also used : Blockchain(org.ethereum.core.Blockchain) 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) SimplePeer(co.rsk.net.simples.SimplePeer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 58 with TestSystemProperties

use of co.rsk.config.TestSystemProperties 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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) SimplePeer(co.rsk.net.simples.SimplePeer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 59 with TestSystemProperties

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

the class NodeBlockProcessorTest method processTenBlocksAddingToBlockchain.

@Test
public void processTenBlocksAddingToBlockchain() {
    Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    NetBlockStore store = new NetBlockStore();
    Block genesis = blockchain.getBestBlock();
    List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
    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);
    processor.processBlock(null, genesis);
    Assert.assertEquals(0, store.size());
    for (Block b : blocks) processor.processBlock(null, b);
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    Assert.assertEquals(0, store.size());
}
Also used : Blockchain(org.ethereum.core.Blockchain) 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 60 with TestSystemProperties

use of co.rsk.config.TestSystemProperties 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());
}
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)

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