Search in sources :

Example 6 with BlockMessage

use of co.rsk.net.messages.BlockMessage 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 7 with BlockMessage

use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.

the class TwoAsyncNodeTest method buildBlockchainPartialAndSynchronize.

@Test
@Ignore("This should be reviewed with sync processor or deleted")
public void buildBlockchainPartialAndSynchronize() throws InterruptedException {
    SimpleAsyncNode node1 = createNode(0);
    SimpleAsyncNode node2 = createNode(0);
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    for (Block block : blocks) {
        BlockMessage message = new BlockMessage(block);
        node1.receiveMessageFrom(null, message);
        node1.waitExactlyNTasksWithTimeout(1);
        if (block.getNumber() <= 5) {
            node2.receiveMessageFrom(null, message);
            node2.waitExactlyNTasksWithTimeout(1);
        }
    }
    node1.sendStatusTo(node2);
    node2.waitUntilNTasksWithTimeout(1);
    node1.waitExactlyNTasksWithTimeout(5);
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    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) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with BlockMessage

use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.

the class TwoAsyncNodeUsingSyncProcessorTest method buildBlockchainPartialAndSynchronize.

@Test
public void buildBlockchainPartialAndSynchronize() throws InterruptedException {
    SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10, 0, false, true, null);
    for (Block block : blocks) {
        BlockMessage message = new BlockMessage(block);
        node1.receiveMessageFrom(null, message);
        node1.waitExactlyNTasksWithTimeout(1);
        if (block.getNumber() <= 5) {
            node2.receiveMessageFrom(null, message);
            node2.waitExactlyNTasksWithTimeout(1);
        }
    }
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(5, node2.getBestBlock().getNumber());
    node1.sendFullStatusTo(node2);
    // find connection point
    node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(10, 5, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // get blocks
    node2.waitExactlyNTasksWithTimeout(5);
    // drain node 1 for next test
    node1.clearQueue();
    node2.sendFullStatusTo(node1);
    // receive status, do nothing
    node1.waitExactlyNTasksWithTimeout(1);
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(10, node2.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

BlockMessage (co.rsk.net.messages.BlockMessage)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)7 Block (org.ethereum.core.Block)7 Test (org.junit.Test)7 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)4 SimpleNode (co.rsk.net.simples.SimpleNode)3 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 co.rsk.net (co.rsk.net)1 GetBlockMessage (co.rsk.net.messages.GetBlockMessage)1 Message (co.rsk.net.messages.Message)1 StatusMessage (co.rsk.net.messages.StatusMessage)1 EthMessage (org.ethereum.net.eth.message.EthMessage)1 TransactionsMessage (org.ethereum.net.eth.message.TransactionsMessage)1