Search in sources :

Example 1 with SimpleNode

use of co.rsk.net.simples.SimpleNode in project rskj by rsksmart.

the class OneNodeTest method buildBlockchainInReverse.

@Test
public void buildBlockchainInReverse() {
    SimpleNode node = SimpleNode.createNode();
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    List<Block> reverse = new ArrayList<>();
    for (Block block : blocks) reverse.add(0, block);
    for (Block block : reverse) node.receiveMessageFrom(null, new BlockMessage(block));
    Assert.assertEquals(blocks.size(), node.getBestBlock().getNumber());
    Assert.assertEquals(blocks.get(blocks.size() - 1).getHash(), node.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleNode(co.rsk.net.simples.SimpleNode) Test(org.junit.Test)

Example 2 with SimpleNode

use of co.rsk.net.simples.SimpleNode in project rskj by rsksmart.

the class TwoNodeTest method buildBlockchainPartialAndSynchronize.

@Test
@Ignore
public void buildBlockchainPartialAndSynchronize() {
    SimpleNode node1 = createNode(0);
    SimpleNode node2 = createNode(0);
    List<Block> blocks = new BlockGenerator().getBlockChain(10);
    for (Block block : blocks) {
        BlockMessage message = new BlockMessage(block);
        node1.receiveMessageFrom(null, message);
        if (block.getNumber() <= 5)
            node2.receiveMessageFrom(null, message);
    }
    node1.sendStatusTo(node2);
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(10, node2.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleNode(co.rsk.net.simples.SimpleNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with SimpleNode

use of co.rsk.net.simples.SimpleNode in project rskj by rsksmart.

the class OneNodeTest method buildBlockchain.

@Test
public void buildBlockchain() {
    SimpleNode node = SimpleNode.createNode();
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    for (Block block : blocks) node.receiveMessageFrom(null, new BlockMessage(block));
    Assert.assertEquals(blocks.size(), node.getBestBlock().getNumber());
    Assert.assertEquals(blocks.get(blocks.size() - 1).getHash(), node.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleNode(co.rsk.net.simples.SimpleNode) Test(org.junit.Test)

Example 4 with SimpleNode

use of co.rsk.net.simples.SimpleNode in project rskj by rsksmart.

the class TwoNodeTest method createNode.

private static SimpleNode createNode(int size) {
    final World world = new World();
    final BlockStore store = new BlockStore();
    final Blockchain blockchain = world.getBlockChain();
    List<Block> blocks = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), size);
    for (Block b : blocks) blockchain.tryToConnect(b);
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    NodeMessageHandler handler = new NodeMessageHandler(new RskSystemProperties(), processor, null, null, null, null, null, new DummyBlockValidationRule());
    return new SimpleNode(handler);
}
Also used : DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleNode(co.rsk.net.simples.SimpleNode) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 5 with SimpleNode

use of co.rsk.net.simples.SimpleNode in project rskj by rsksmart.

the class TwoNodeTest method buildBlockchainAndSynchronize.

@Test
@Ignore
public void buildBlockchainAndSynchronize() {
    SimpleNode node1 = createNode(100);
    SimpleNode node2 = createNode(0);
    node1.sendStatusTo(node2);
    Assert.assertEquals(100, node1.getBestBlock().getNumber());
    Assert.assertEquals(100, node2.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
}
Also used : SimpleNode(co.rsk.net.simples.SimpleNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SimpleNode (co.rsk.net.simples.SimpleNode)5 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)4 Block (org.ethereum.core.Block)4 Test (org.junit.Test)4 BlockMessage (co.rsk.net.messages.BlockMessage)3 Ignore (org.junit.Ignore)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)1 World (co.rsk.test.World)1 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)1 ArrayList (java.util.ArrayList)1 Blockchain (org.ethereum.core.Blockchain)1