Search in sources :

Example 36 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class TwoAsyncNodeUsingSyncProcessorTest method stopSyncingAfter5SkeletonChunks.

@Test
public void stopSyncingAfter5SkeletonChunks() {
    Blockchain b1 = BlockChainBuilder.ofSize(30, false);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 2000, false);
    SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(2030, node2.getBestBlock().getNumber());
    node2.sendFullStatusTo(node1);
    // sync setup
    node1.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(2030, 30, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // request bodies
    node1.waitExactlyNTasksWithTimeout(1122);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(1152, node1.getBestBlock().getNumber());
    Assert.assertEquals(2030, node2.getBestBlock().getNumber());
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) Test(org.junit.Test)

Example 37 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class SimpleAsyncNode method createNodeWithBlockChainBuilder.

// TODO(mc) find out why the following two work differently
public static SimpleAsyncNode createNodeWithBlockChainBuilder(int size) {
    final Blockchain blockchain = BlockChainBuilder.ofSize(0);
    BlockChainBuilder.extend(blockchain, size, false, true);
    return createNode(blockchain, SyncConfiguration.IMMEDIATE_FOR_TESTING);
}
Also used : Blockchain(org.ethereum.core.Blockchain)

Example 38 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class Web3Mocks method getMockBlockchain.

public static Blockchain getMockBlockchain() {
    Blockchain mockBlockchain = mock(Blockchain.class, RETURNS_DEEP_STUBS);
    when(mockBlockchain.getBestBlock().getNumber()).thenReturn(0L);
    return mockBlockchain;
}
Also used : Blockchain(org.ethereum.core.Blockchain)

Example 39 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class BlockchainTest method tryToConnectWithCompetingChain.

@Test
public void tryToConnectWithCompetingChain() {
    // Two competing blockchains of the same size (2)
    Blockchain blockchain = createBlockchain();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
    Block block2 = blockGenerator.createChildBlock(block1, 0, 5);
    Block block1b = blockGenerator.createChildBlock(blockchain.getBestBlock());
    Block block2b = blockGenerator.createChildBlock(block1b, 0, 4);
    // genesis <- block1 <- block2
    // genesis <- block1b <- block2b
    Assert.assertEquals(ImportResult.NO_PARENT, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block1b));
    Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1b));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block2b));
    Assert.assertEquals(blockchain.getBestBlock(), block2);
    Assert.assertEquals(2, block2.getNumber());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 40 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class BlockchainTest method checkItDoesntAddAnInvalidBlock.

@Test
public void checkItDoesntAddAnInvalidBlock() {
    Blockchain blockchain = createBlockchain();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
    ImportResult importResult1 = blockchain.tryToConnect(block1);
    assertTrue(importResult1.isSuccessful());
    Block block2 = blockGenerator.createChildBlock(blockchain.getBestBlock());
    Block block2b = blockGenerator.createBlock(10, 5);
    Block block3 = Block.fromValidData(block2.getHeader(), block2b.getTransactionsList(), block2b.getUncleList());
    ImportResult importResult2 = blockchain.tryToConnect(block3);
    Assert.assertFalse(importResult2.isSuccessful());
}
Also used : ImportResult(org.ethereum.core.ImportResult) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

Blockchain (org.ethereum.core.Blockchain)86 Test (org.junit.Test)75 Block (org.ethereum.core.Block)51 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)47 RskSystemProperties (co.rsk.config.RskSystemProperties)45 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)38 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)25 World (co.rsk.test.World)19 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)14 Keccak256 (co.rsk.crypto.Keccak256)7 Ignore (org.junit.Ignore)7 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)5 BlockIdentifier (org.ethereum.core.BlockIdentifier)3 BlockChainStatus (co.rsk.core.bc.BlockChainStatus)2 NewBlockHashMessage (co.rsk.net.messages.NewBlockHashMessage)2 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)2 Repository (org.ethereum.core.Repository)2 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)2 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1