Search in sources :

Example 71 with BlockChainBuilder

use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.

the class NodeBlockProcessorTest method processTwoBlockListsAddingToBlockchainWithFork.

@Test
public void processTwoBlockListsAddingToBlockchainWithFork() {
    NetBlockStore store = new NetBlockStore();
    Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    Block genesis = blockchain.getBestBlock();
    BlockGenerator blockGenerator = new BlockGenerator();
    List<Block> blocks = blockGenerator.getBlockChain(genesis, 10);
    List<Block> blocks2 = blockGenerator.getBlockChain(blocks.get(4), 20);
    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);
    for (Block b : blocks2) processor.processBlock(null, b);
    Assert.assertEquals(25, 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 72 with BlockChainBuilder

use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.

the class NodeBlockProcessorTest method noSyncingWithEmptyBlockchainAndLowBestBlock.

@Test
@Ignore("Ignored when Process status deleted on block processor")
public void noSyncingWithEmptyBlockchainAndLowBestBlock() {
    NetBlockStore store = new NetBlockStore();
    Block block = new BlockGenerator().createBlock(10, 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().getBytes());
    // processor.processStatus(new SimpleNodeChannel(null, null), status);
    Assert.assertFalse(processor.hasBetterBlockToSync());
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 73 with BlockChainBuilder

use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.

the class NodeBlockProcessorTest method processBlockHashRequestMessageUsingOutOfBoundsHeight.

@Test
public void processBlockHashRequestMessageUsingOutOfBoundsHeight() throws UnknownHostException {
    final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    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.processBlockHashRequest(sender, 100, 99999);
    Assert.assertTrue(sender.getMessages().isEmpty());
}
Also used : Blockchain(org.ethereum.core.Blockchain) 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 74 with BlockChainBuilder

use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.

the class NodeBlockProcessorTest method processTenBlocksGenesisAtLastAddingToBlockchain.

@Test
public void processTenBlocksGenesisAtLastAddingToBlockchain() {
    NetBlockStore store = new NetBlockStore();
    Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    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);
    for (Block b : blocks) processor.processBlock(null, b);
    processor.processBlock(null, genesis);
    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 75 with BlockChainBuilder

use of co.rsk.test.builders.BlockChainBuilder in project rskj by rsksmart.

the class NodeBlockProcessorTest method noSyncingWithEmptyBlockchain.

@Test
public void noSyncingWithEmptyBlockchain() {
    NetBlockStore store = new NetBlockStore();
    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());
}
Also used : Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Aggregations

BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)155 Test (org.junit.Test)139 TestSystemProperties (co.rsk.config.TestSystemProperties)109 Blockchain (org.ethereum.core.Blockchain)88 SimplePeer (co.rsk.net.simples.SimplePeer)82 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)76 Block (org.ethereum.core.Block)69 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)62 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)25 BlockStore (org.ethereum.db.BlockStore)25 EthereumListener (org.ethereum.listener.EthereumListener)25 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)19 Ignore (org.junit.Ignore)17 RskSystemProperties (co.rsk.config.RskSystemProperties)15 Keccak256 (co.rsk.crypto.Keccak256)14 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)11 AsyncNodeBlockProcessorListener (co.rsk.net.utils.AsyncNodeBlockProcessorListener)9 org.ethereum.core (org.ethereum.core)9 ECKey (org.ethereum.crypto.ECKey)9 ChannelManager (org.ethereum.net.server.ChannelManager)9