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()));
}
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);
}
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;
}
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());
}
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());
}
Aggregations