use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class BlockchainTest method blockchainTest.
@Test
public void blockchainTest() {
Blockchain blockchain = createBlockchain();
Assert.assertNotNull(blockchain);
Block block = blockchain.getBestBlock();
Assert.assertNotNull(block);
Assert.assertEquals(0, block.getNumber());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class BlockchainTest method tryToConnect.
@Test
public void tryToConnect() {
Blockchain blockchain = createBlockchain();
BlockGenerator blockGenerator = new BlockGenerator();
Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
Block block2 = blockGenerator.createChildBlock(block1);
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(blockchain.getBestBlock(), block2);
Assert.assertEquals(2, block2.getNumber());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class BridgePerformanceTestCase method execute.
private ExecutionTracker execute(ABIEncoder abiEncoder, BridgeStorageProviderInitializer storageInitializer, TxBuilder txBuilder, HeightProvider heightProvider, int executionIndex) {
ExecutionTracker executionInfo = new ExecutionTracker(thread);
RepositoryImpl repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
BridgeStorageProvider storageProvider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants);
storageInitializer.initialize(storageProvider, track, executionIndex);
try {
storageProvider.save();
} catch (Exception e) {
throw new RuntimeException("Error trying to save the storage after initialization", e);
}
track.commit();
Transaction tx = txBuilder.build(executionIndex);
List<LogInfo> logs = new ArrayList<>();
RepositoryTrackWithBenchmarking benchmarkerTrack = new RepositoryTrackWithBenchmarking(config, repository);
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
Blockchain blockchain = BlockChainBuilder.ofSizeWithNoTransactionPoolCleaner(heightProvider.getHeight(executionIndex));
bridge.init(tx, blockchain.getBestBlock(), benchmarkerTrack, blockchain.getBlockStore(), null, logs);
// Execute a random method so that bridge support initialization
// does its initial writes to the repo for e.g. genesis block,
// federation, etc, etc. and we don't get
// those recorded in the actual execution.
bridge.execute(Bridge.GET_FEDERATION_SIZE.encode());
benchmarkerTrack.getStatistics().clear();
executionInfo.startTimer();
bridge.execute(abiEncoder.encode(executionIndex));
executionInfo.endTimer();
benchmarkerTrack.commit();
executionInfo.setRepositoryStatistics(benchmarkerTrack.getStatistics());
return executionInfo;
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class Web3RskImplTest method web3_ext_dumpState.
@Test
public void web3_ext_dumpState() throws Exception {
Rsk rsk = Mockito.mock(Rsk.class);
Blockchain blockchain = Mockito.mock(Blockchain.class);
NetworkStateExporter networkStateExporter = Mockito.mock(NetworkStateExporter.class);
Mockito.when(networkStateExporter.exportStatus(Mockito.anyString())).thenReturn(true);
Block block = Mockito.mock(Block.class);
Mockito.when(block.getHash()).thenReturn(PegTestUtils.createHash3());
Mockito.when(block.getNumber()).thenReturn(1L);
BlockStore blockStore = Mockito.mock(BlockStore.class);
Mockito.when(blockStore.getBestBlock()).thenReturn(block);
Mockito.when(networkStateExporter.exportStatus(Mockito.anyString())).thenReturn(true);
Mockito.when(blockchain.getBestBlock()).thenReturn(block);
Wallet wallet = WalletFactory.createWallet();
RskSystemProperties config = new RskSystemProperties();
PersonalModule pm = new PersonalModuleWalletEnabled(config, rsk, wallet, null);
EthModule em = new EthModule(config, blockchain, null, new ExecutionBlockRetriever(blockchain, null, null), new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, rsk, wallet, null));
TxPoolModule tpm = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
Web3RskImpl web3 = new Web3RskImpl(rsk, blockchain, Web3Mocks.getMockTransactionPool(), config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, tpm, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, networkStateExporter, blockStore, null, null, null, null, null);
web3.ext_dumpState();
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class Web3ImplSnapshotTest method revertToSnapshot.
@Test
public void revertToSnapshot() {
World world = new World();
Web3Impl web3 = createWeb3(world);
Blockchain blockchain = world.getBlockChain();
addBlocks(blockchain, 10);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
BlockChainStatus status = blockchain.getStatus();
String snapshotId = web3.evm_snapshot();
addBlocks(blockchain, 10);
Assert.assertEquals(20, blockchain.getBestBlock().getNumber());
Assert.assertTrue(web3.evm_revert(snapshotId));
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
BlockChainStatus newStatus = blockchain.getStatus();
Assert.assertEquals(status.getBestBlock().getHash(), newStatus.getBestBlock().getHash());
Assert.assertEquals(status.getTotalDifficulty(), newStatus.getTotalDifficulty());
}
Aggregations