use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class RemascFederationProviderTest method getRemascFederationProvider.
private static RemascFederationProvider getRemascFederationProvider() throws IOException, BlockStoreException {
Genesis genesisBlock = new BlockGenerator().getGenesisBlock();
BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock);
Blockchain blockchain = builder.build();
BridgeSupport bridgeSupport = new BridgeSupport(new RskSystemProperties(), blockchain.getRepository(), null, PrecompiledContracts.BRIDGE_ADDR, null);
RemascFederationProvider provider = null;
try {
provider = new RemascFederationProvider(bridgeSupport);
} catch (BlockStoreException | IOException e) {
e.printStackTrace();
}
return provider;
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class Web3ImplRpcTest method getRpcModules.
@Test
public void getRpcModules() {
Ethereum eth = Web3Mocks.getMockEthereum();
Blockchain blockchain = Web3Mocks.getMockBlockchain();
TransactionPool transactionPool = Web3Mocks.getMockTransactionPool();
PersonalModule pm = new PersonalModuleWalletDisabled();
Repository repository = Web3Mocks.getMockRepository();
Web3Impl web3 = new Web3RskImpl(eth, blockchain, transactionPool, new RskSystemProperties(), null, null, pm, null, null, null, repository, null, null, null, null, null, null, null, null);
Map<String, String> result = web3.rpc_modules();
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertTrue(result.containsKey("eth"));
Assert.assertEquals("1.0", result.get("eth"));
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithThreePeers400Different.
@Test
public void synchronizeNewNodeWithThreePeers400Different() {
Blockchain b1 = BlockChainBuilder.ofSize(0, true);
Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 200);
Blockchain b3 = BlockChainBuilder.copyAndExtend(b2, 200);
SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b2);
SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b2);
SimpleAsyncNode node3 = SimpleAsyncNode.createDefaultNode(b3);
SyncConfiguration syncConfiguration = new SyncConfiguration(3, 1, 10, 100, 20, 192);
SimpleAsyncNode node4 = SimpleAsyncNode.createNode(b1, syncConfiguration);
Assert.assertEquals(200, node1.getBestBlock().getNumber());
Assert.assertEquals(200, node2.getBestBlock().getNumber());
Assert.assertEquals(400, node3.getBestBlock().getNumber());
Assert.assertEquals(0, node4.getBestBlock().getNumber());
node1.sendFullStatusTo(node4);
node2.sendFullStatusTo(node4);
node3.sendFullStatusTo(node4);
// sync setup
int setupRequests = SyncUtils.syncSetupRequests(400, 0, syncConfiguration);
node4.waitUntilNTasksWithTimeout(setupRequests);
// synchronize 50 new blocks from node 1
node4.waitExactlyNTasksWithTimeout(400 + setupRequests - 10);
Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node4.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertEquals(400, node4.getBestBlock().getNumber());
Assert.assertEquals(node4.getBestBlock().getHash(), node3.getBestBlock().getHash());
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node4.getSyncProcessor().getExpectedResponses().isEmpty());
node1.joinWithTimeout();
node2.joinWithTimeout();
node3.joinWithTimeout();
node4.joinWithTimeout();
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
Assert.assertFalse(node3.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class TwoAsyncNodeTest method createNode.
private static SimpleAsyncNode 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;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
NodeMessageHandler handler = new NodeMessageHandler(config, processor, null, null, null, null, null, new DummyBlockValidationRule());
return new SimpleAsyncNode(handler);
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class TwoAsyncNodeUsingSyncProcessorTest method syncInMultipleStepsWithLongBlockchain.
@Test
public void syncInMultipleStepsWithLongBlockchain() {
Blockchain b1 = BlockChainBuilder.ofSize(300, false);
Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 4000, false);
SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Assert.assertEquals(300, node1.getBestBlock().getNumber());
Assert.assertEquals(4300, node2.getBestBlock().getNumber());
for (int i = 0; i < 5; i++) {
int skippedChunks = 300 / 192;
int expectedBestBlockNumber = Math.min(4300, 192 * skippedChunks + 192 * 6 * (i + 1));
long currentBestBlock = node1.getBestBlock().getNumber();
// at the beginning and the end we might have different number of blocks to download
int blocksToDownload = Math.toIntExact(expectedBestBlockNumber - currentBestBlock);
node2.sendFullStatusTo(node1);
node1.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(4300, currentBestBlock, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// request bodies
node1.waitExactlyNTasksWithTimeout(blocksToDownload);
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertEquals(expectedBestBlockNumber, node1.getBestBlock().getNumber());
Assert.assertEquals(4300, node2.getBestBlock().getNumber());
// this prevents node2's queue to get full
node2.clearQueue();
}
node1.joinWithTimeout();
node2.joinWithTimeout();
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
Aggregations